Knowledge search ranks by how near a chunk's meaning is, not by its place in two lists
Fused by rank, a full-text match on a question's everyday words outvoted a far nearer meaning: on the PoC, "how much leave do fathers get" found the annual-leave page before the paternity one (cosine distance 0.44 against 0.25). Now a chunk scores its similarity to the question plus up to 0.3 for a full-text match, each search brings four times k candidates, the text search drops Turkish and English stop words, and an operator's search says when the embedding model did not answer rather than quietly searching text. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1ec9b83076
commit
bc5ee9f3aa
3 files changed
+153
-69
No files matched your search
@@ -352,10 +352,42 @@ func TestPostgresAPersonsCollectionsGoWithTheAccount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgresMeaningOutweighsSharedWords(t *testing.T) {
|
||||
// The PoC's case: the question shares its everyday words with one
|
||||
// passage and its meaning with another.
|
||||
ctx := context.Background()
|
||||
s := openKB(t)
|
||||
kbTwoOrgs(t, s)
|
||||
c := mustCollection(t, s, ScopeProject, "proj1", "", "docs")
|
||||
put := func(name, body string, v []float32) {
|
||||
t.Helper()
|
||||
if _, _, err := s.PutDocument(ctx, c, KBDocument{Name: name, Digest: name}, []KBChunk{{Body: body, Embedding: v}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
put("yillik.md", "yıllık izin kadar izin alır izin", unit(0))
|
||||
put("babalik.md", "babalık hakkı on gündür", unit(1))
|
||||
for _, f := range []string{"a", "b", "c"} {
|
||||
put(f+".md", "başka bir konu", unit(2))
|
||||
}
|
||||
hits, err := s.SearchChunks(ctx, KBSearch{OrgID: "org1", Collections: []KBCollection{c},
|
||||
Embeddings: map[string][]float32{"emb": unit(1)}, Text: "babalar ne kadar izin alır", K: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(hits) != 1 || hits[0].Document != "babalik.md" {
|
||||
t.Errorf("best hit %+v", hits)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrQueryMatchesAnyWord(t *testing.T) {
|
||||
if got := orQuery("Yıllık izin kaç gün? İzin & 'x' -- a"); got != "Yıllık | izin | kaç | gün | İzin" {
|
||||
if got := orQuery("Yıllık izin kaç gün? İzin & 'x' -- a"); got != "Yıllık | izin | gün | İzin" {
|
||||
t.Errorf("orQuery gave %q", got)
|
||||
}
|
||||
// Words every passage has are no evidence of anything.
|
||||
if got := orQuery("Babalar NE kadar izin alır, ve İÇİN"); got != "Babalar | izin | alır" {
|
||||
t.Errorf("stop words kept: %q", got)
|
||||
}
|
||||
if got := orQuery("?!"); got != "" {
|
||||
t.Errorf("no words gave %q", got)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user