store: keep what she read out of what he said
Nothing at read time told a feed item or a crawled page apart from his own notes. QueryNotes ranked every note by cosine and the notes answer handed the nearest five to the phraser, so "что я говорил про переезд" could be answered out of a stranger's web page, prefixed with "вот что я нашла: ". Recall now excludes the read sources, rss: and crawl:, and the list is one place. The feed answer needed a different read as a result, and it needed one anyway: it scanned the last 200 notes of any source, so a busy day of voice notes pushed the newest headline out of the window and she said "в лентах пока ничего нового" while the poller was working fine. RecentNotesFromSource asks for feed notes by source, so the window holds 200 of them. Found in review of #66 and #67.
This commit is contained in:
@@ -36,3 +36,43 @@ func TestQueryNotesRanksByCosine(t *testing.T) {
|
||||
t.Errorf("scores not descending: %.3f then %.3f", got[0].Score, got[1].Score)
|
||||
}
|
||||
}
|
||||
|
||||
// Recall answers questions about HIM. A feed item and a crawled page are text
|
||||
// Maven read somewhere, and letting them into the nearest-neighbour pool means
|
||||
// "что я говорил про переезд" can be answered with a stranger's sentence, under
|
||||
// the line "вот что я нашла: ".
|
||||
func TestQueryNotesLeavesOutWhatSheOnlyRead(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
st := newTestStore(t)
|
||||
now := time.Now()
|
||||
// The read sources sit exactly on the query vector; his own note is further
|
||||
// away, so ranking alone would put them first.
|
||||
for _, n := range []struct{ text, source string }{
|
||||
{"переезд в новую квартиру описан тут", "rss:habr"},
|
||||
{"страница про переезд", "crawl:changelog"},
|
||||
} {
|
||||
if _, err := st.WriteNote(ctx, now, n.text, []float32{1, 0, 0}, n.source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := st.WriteNote(ctx, now, "переезд в субботу", []float32{0.8, 0.6, 0}, "tap:voice"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := st.QueryNotes(ctx, []float32{1, 0, 0}, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got) != 1 || got[0].Source != "tap:voice" {
|
||||
t.Fatalf("recall returned %+v; want only what he said himself", got)
|
||||
}
|
||||
|
||||
// They are still reachable, by source.
|
||||
feed, err := st.RecentNotesFromSource(ctx, "rss:", 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(feed) != 1 || feed[0].Source != "rss:habr" {
|
||||
t.Fatalf("RecentNotesFromSource(rss:) = %+v; want the one feed note", feed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user