Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 229890abd7 | |||
| 0db9ca084c | |||
| 96d97e8964 | |||
| 02f6e8ad4a | |||
| 999a5ad562 | |||
| 2ea39a3d41 | |||
| 8fb6f2154d |
@@ -269,6 +269,16 @@ destination cases and buys 50ms. Read destination as the finding: it names nothi
|
||||
where the 12B names `recall` or `calendar`, which is safe but walks the whole chain.
|
||||
It also has no MTP and cannot be given any here. The only `gemma4-assistant`
|
||||
draft on disk is trained against the 12B's hidden states.
|
||||
**Phrasing was the unmeasured half and it is measured now**
|
||||
(`docs/evals/2026-08-09-e4b-phrasing.md`). E4B scores nudges 15/15 and the
|
||||
36-case talk fixture **29/36 at p50 516ms**, against the resident model's 25/36
|
||||
at p50 2.97s. Persona is clean: `lang`, `feminine` and `address` are all 36/36,
|
||||
where the resident model loses three on `address`. Every failure is `ontopic`
|
||||
and none is a parse error. The 2026-08-05 temperature sweep put this fixture's
|
||||
ceiling at 30/36, because two reply cases fail at every temperature (V-537), and
|
||||
both are in E4B's failure list. So the swap costs nothing here. One defect no
|
||||
check catches: in chat E4B claims "Я записала несколько идей!" when nothing was
|
||||
stored, which is a wrong claim about state.
|
||||
|
||||
**The intended third engine is not a generative model** (owner's call, 05-08-2026, V-546,
|
||||
`docs/plans/18-routing-heads-on-e5-small.md`). Routing has a bounded output space, so it is
|
||||
@@ -675,11 +685,28 @@ world questions, so she needs to read external sources. What replaces it:
|
||||
`wikipedia_ru_all_maxi_2026-02` verbatim** through `kiwix.book_ru`. The RU→EN rewriter
|
||||
is the workaround for an English book and is skipped there. Kiwix catalog names come
|
||||
from the filename, not the `<name>` field.
|
||||
**That verbatim path sent the whole sentence to a keyword engine until 09-08-2026**
|
||||
(V-668, `docs/evals/2026-08-09-kiwix-topic-retrieval.md`). Kiwix ranks by keyword
|
||||
overlap, so the question words outrank the one word naming the article. "что такое TCP"
|
||||
returned "Перехват TCP-соединения". "кто написал Войну и мир" returned an episode of
|
||||
Doctor Who. `kiwix.Topic` drops the narrative request, the interrogative and a verb
|
||||
behind one. `kiwix.TitlePath` tries the exact article first, since a ZIM is addressable
|
||||
by title and a wrong title is a 404. Five of eight questions reach the right article
|
||||
where they did not, one was already right, and nothing regressed. The title needs its
|
||||
leading capital, so `TitleCandidates` tries the spoken form and then the capitalized
|
||||
one. **"столица Франции" is answered by a title redirect to Париж**, which is the case
|
||||
the 2026-08-05 measurement named as unreachable by any lexical signal. Both apply on the
|
||||
verbatim path alone. The rewriter already reduces a question, and reducing twice takes
|
||||
the topic off its input.
|
||||
`Response.Empty()` is the whole gate and there is no quality threshold in front of it:
|
||||
the three signals one could read were measured on 2026-08-05 and none of them separate a
|
||||
real question from an invented one. Token overlap would cost "столица Франции" its
|
||||
answer, because the answer is Париж and that word is not in the question. See
|
||||
`docs/evals/2026-08-05-search-quality-signals.md` (V-539). **Which query source claimed
|
||||
`docs/evals/2026-08-05-search-quality-signals.md` (V-539). **The embedder is not a
|
||||
fourth signal**, measured 2026-08-09 (V-668). Query-to-passage cosine scores 0.79 to
|
||||
0.91 on answerable questions and 0.75 to 0.84 on unanswerable ones, and the sets
|
||||
overlap. The wrong TCP article scored 0.8653, above five of six unanswerable rows. It
|
||||
measures topic and not whether the passage answers, so no threshold splits them. **Which query source claimed
|
||||
a turn is readable on `/chat`** as a badge beside the reply, carried on
|
||||
`ipc.ChatReply.Source` and noted by `noteQuerySource` in `cmd/mavend/querysource.go`. It
|
||||
rides the context, so `handleText` keeps the one string signature the mic, telegram and
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/kami/maven/internal/crawl"
|
||||
"github.com/kami/maven/internal/decision"
|
||||
"github.com/kami/maven/internal/ipc"
|
||||
"github.com/kami/maven/internal/kiwix"
|
||||
"github.com/kami/maven/internal/memory"
|
||||
"github.com/kami/maven/internal/morning"
|
||||
"github.com/kami/maven/internal/phraser"
|
||||
@@ -926,6 +927,28 @@ func (h *reactiveHandler) queryKiwix(ctx context.Context, t *queryTurn) (string,
|
||||
}
|
||||
}
|
||||
|
||||
// The topic, not the sentence (V-668). Kiwix ranks by keyword overlap, so
|
||||
// the question words outrank the one word that names the article: measured
|
||||
// on 2026-08-09, "что такое TCP" returns "Перехват TCP-соединения" and
|
||||
// "TCP" returns TCP. Only the verbatim path needs this. The rewriter
|
||||
// already reduces a question to English keywords, and reducing twice would
|
||||
// take the topic off the input it reads.
|
||||
if verbatim {
|
||||
if topic := kiwix.Topic(pattern); topic != "" {
|
||||
// The article named exactly, before any ranking runs. A ZIM is
|
||||
// addressable by title and a wrong title is a 404, so this either
|
||||
// answers or costs one request that says nothing.
|
||||
for _, cand := range kiwix.TitleCandidates(topic) {
|
||||
page, err := h.kiwix.client.Article(ctxK, kiwix.TitlePath(book, cand), h.kiwix.runes)
|
||||
if err == nil && page.Text != "" {
|
||||
log.Printf("voice: kiwix: %q in %q → title hit %q", topic, book, page.Title)
|
||||
return h.kiwixReply(ctx, t, page.Title, page.Text)
|
||||
}
|
||||
}
|
||||
pattern = topic
|
||||
}
|
||||
}
|
||||
|
||||
hits, err := h.kiwix.client.Search(ctxK, pattern, book, h.kiwix.max)
|
||||
if err != nil {
|
||||
log.Printf("voice: kiwix: search %q: %v", pattern, err)
|
||||
@@ -958,14 +981,18 @@ func (h *reactiveHandler) queryKiwix(ctx context.Context, t *queryTurn) (string,
|
||||
}
|
||||
page = crawl.Page{Title: top.Title, Text: top.Snippet}
|
||||
}
|
||||
// Handed over the same way a note or a page is: context for the question he
|
||||
// asked, not something to recite.
|
||||
snippet := top.Title + "\n" + crawl.TrimRunes(page.Text, h.kiwix.runes)
|
||||
return h.kiwixReply(ctx, t, top.Title, page.Text)
|
||||
}
|
||||
|
||||
// kiwixReply hands one article over the same way a note or a page is handed
|
||||
// over: context for the question he asked, not something to recite.
|
||||
func (h *reactiveHandler) kiwixReply(ctx context.Context, t *queryTurn, title, text string) (string, bool) {
|
||||
snippet := title + "\n" + crawl.TrimRunes(text, h.kiwix.runes)
|
||||
reply := h.phraseSource(ctx, "kiwix", t.dec.Utterance, []string{snippet})
|
||||
if reply == "" {
|
||||
// No phraser, or it failed. Read back the best hit rather than pretend
|
||||
// the search did not happen.
|
||||
return readBack(top.Title + " — " + page.Text), true
|
||||
return readBack(title + " — " + text), true
|
||||
}
|
||||
return reply, true
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ type sileroVAD struct {
|
||||
mu sync.Mutex
|
||||
session *ort.DynamicAdvancedSession
|
||||
|
||||
pending []float32 // samples not yet part of a full window
|
||||
context [sileroContext]float32 // tail of the previous window
|
||||
state []float32 // [2][1][128], carried between windows
|
||||
last float64 // most recent probability, held between windows
|
||||
pending []float32 // samples not yet part of a full window
|
||||
context [sileroContext]float32 // tail of the previous window
|
||||
state []float32 // [2][1][128], carried between windows
|
||||
last float64 // most recent probability, held between windows
|
||||
sr []int64
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# gemma-4-E4B on the phrasing and talk fixtures
|
||||
|
||||
Date: 2026-08-09. Box: workpc up, E4B loaded on 8080.
|
||||
`MAVEN_LLM_URL=http://192.168.1.105:8080 make eval-phrasing`.
|
||||
|
||||
This was the one unmeasured risk of the 2026-08-09 model swap. Routing was
|
||||
measured the same day and E4B lost four destination cases to the 12B. Phrasing
|
||||
was not measured at all, and phrasing is the half the owner hears.
|
||||
|
||||
## Result
|
||||
|
||||
| fixture | E4B | resident Qwen3-1.7B, 2026-08-05 |
|
||||
|---|---|---|
|
||||
| nudges | 15/15 (100%) | 15/15 (100%) |
|
||||
| talk, passes every check | **29/36 (80.6%)** | 25/36 (69.4%) |
|
||||
| lang | 36/36 | — |
|
||||
| feminine | 36/36 | 36/36 |
|
||||
| address | **36/36** | 33/36 |
|
||||
| ontopic | 29/36 | 28/36 |
|
||||
| p50 latency | **516ms** | 2.97s |
|
||||
| p95 latency | 921ms | — |
|
||||
| failed generations | 0 | 0 |
|
||||
|
||||
E4B beats the homesrv floor by four cases and answers about six times faster.
|
||||
Persona is clean: `lang`, `feminine` and `address` are perfect, and `address`
|
||||
is where the resident model still loses three. The 2026-08-05 measurement of the
|
||||
resident model is the comparison, since both ran the same 36-case fixture.
|
||||
|
||||
Every failure is `ontopic`. Nothing failed on persona, nothing failed to parse.
|
||||
|
||||
## The score is at the ceiling, not below it
|
||||
|
||||
The 2026-08-05 temperature sweep found two cases that fail at every temperature
|
||||
in every run: `reply-note-router` and `reply-fact-weight`. It named a defect in
|
||||
the reply phrasing path rather than sampling noise. It put the fixture's ceiling
|
||||
at 30/36 before persona is scored. Both cases are in E4B's failure list.
|
||||
|
||||
So 29/36 is one case off a ceiling nothing about the model can move. The swap is
|
||||
safe on phrasing. Read this next to the routing result, not instead of it. There
|
||||
E4B costs four destination cases and buys 50ms. Here it costs nothing.
|
||||
|
||||
## Two findings no check caught
|
||||
|
||||
**She says she wrote something down when she did not.** Asked what to do this
|
||||
evening, E4B writes "Я записала несколько идей!". Asked for a joke, it writes
|
||||
"Я записала одну забавную ситуацию!". Nothing was stored. No check scores it,
|
||||
because `ontopic` reads the subject and `cringe` reads pet names. A claim to
|
||||
have saved something is a claim about state, and it is wrong.
|
||||
|
||||
**Two `ontopic` failures look like check defects.** `know-dont-know` wants
|
||||
"не зна" or "не мог". It got "Я не умею знать личную информацию о твоих
|
||||
соседях", which declines correctly in words the check does not list.
|
||||
`know-hiccups` is the same shape. Neither is a model failure and both count
|
||||
against the score.
|
||||
|
||||
## Not measured here
|
||||
|
||||
A 12B control on the same fixture, which would need the card reloaded and is the
|
||||
owner's call. The talk fixture through the daemon rather than through the
|
||||
phraser directly. The CPT'd Qwen3-1.7B, which does not exist yet and is the
|
||||
reason `address` is a check at all.
|
||||
@@ -0,0 +1,113 @@
|
||||
# Kiwix answered the wrong question, and the fix was not a relevance gate
|
||||
|
||||
Date: 2026-08-09. Task: V-668. Box: homesrv, workstation off.
|
||||
Book: `wikipedia_ru_all_maxi_2026-02` on `127.0.0.1:8034`.
|
||||
|
||||
## What started it
|
||||
|
||||
Two turns on 2026-08-09 came back wrong from the offline encyclopedia.
|
||||
"почему небо голубое" was answered off the song "Город золотой". "что такое
|
||||
TCP?" was answered off "Перехват TCP-соединения". Both were phrased
|
||||
confidently, because `queryKiwix` claims a turn whenever the search returns
|
||||
anything and `len(hits) == 0` is its only gate.
|
||||
|
||||
The plan was a relevance gate. multilingual-e5-small is asymmetric and trained
|
||||
for exactly this, `query:` against `passage:`, and the query vector is already
|
||||
held on the turn. The 2026-08-05 measurement that killed a search-quality gate
|
||||
killed three lexical signals. It says in its own words that it never probed
|
||||
Kiwix.
|
||||
|
||||
## The gate does not exist
|
||||
|
||||
Fourteen Russian questions, eight the encyclopedia can answer and six it
|
||||
cannot. Each question was searched, the top article read, and the cosine of
|
||||
`EmbedQuery(question)` against `EmbedPassage(article)` recorded.
|
||||
|
||||
| set | n | min | mean | max |
|
||||
|---|---|---|---|---|
|
||||
| answerable | 8 | 0.7934 | 0.8400 | 0.9087 |
|
||||
| not answerable | 6 | 0.7480 | 0.7852 | 0.8367 |
|
||||
|
||||
Two of the six unanswerable score above the weakest answerable one. That alone
|
||||
would be a poor threshold. The log killed it outright: seven of the eight
|
||||
answerable questions got a **wrong** article back, and those wrong articles
|
||||
scored high. The TCP hijacking article scored 0.8653, above five of the six
|
||||
unanswerable rows.
|
||||
|
||||
The finding is that this cosine measures topic and not answerhood. A page about
|
||||
hijacking TCP sessions is about TCP. No threshold separates it from a page that
|
||||
defines TCP, and one that tried would take the definition with it.
|
||||
|
||||
## The defect is retrieval
|
||||
|
||||
`internal/kiwix/client.go` has said it since it was written: ranking is keyword
|
||||
based, "why is the sky blue" finds a TV episode. `queryKiwix` sends the whole
|
||||
sentence. The English path has a rewriter that reduces a question to keywords
|
||||
with a model call. The Russian path reads the book verbatim (V-508) and had
|
||||
nothing. So the question words compete with the one word that names the article.
|
||||
|
||||
Dropping the question words changes the answer:
|
||||
|
||||
| sent | first hit |
|
||||
|---|---|
|
||||
| `кто написал Войну и мир` | Радуйся, мир (Доктор Кто) |
|
||||
| `Война и мир` | Война и мир |
|
||||
| `что такое TCP` | Перехват TCP-соединения |
|
||||
| `TCP` | TCP |
|
||||
|
||||
A ZIM is also addressable by title, which nothing here used. `/A/Франция`,
|
||||
`/A/TCP` and `/A/Небо` are 200. `/A/Трюмбальная_нидроскопия` is 404. So an
|
||||
exact title is safe to try first: it either answers or costs one request that
|
||||
says nothing.
|
||||
|
||||
The title has to carry its capital. `/A/фотосинтез` is a 404 and
|
||||
`/A/Фотосинтез` is a 200. The spoken form is tried first anyway, so a title
|
||||
that begins lowercase on purpose keeps its chance.
|
||||
|
||||
## What shipped, measured
|
||||
|
||||
`kiwix.Topic` drops the narrative request, the interrogative and a verb sitting
|
||||
behind one. It keeps everything else, because a word it cannot classify is more
|
||||
likely the topic than noise. `kiwix.TitlePath` tries the exact article before
|
||||
any ranking runs. Both apply on the verbatim path only, since reducing twice
|
||||
would take the topic off the rewriter's input.
|
||||
|
||||
| question | before | after |
|
||||
|---|---|---|
|
||||
| что такое TCP? | Перехват TCP-соединения | **TCP** (by title) |
|
||||
| что такое фотосинтез | C4-фотосинтез | **Фотосинтез** (by title) |
|
||||
| кто такой Линус Торвальдс? | Tux | **Торвальдс, Линус** (by title) |
|
||||
| кто написал Войну и мир | Радуйся, мир (Доктор Кто) | **Война и мир** |
|
||||
| столица Франции | Список столиц Олимпийских игр | **Париж** (by title) |
|
||||
| что такое чёрная дыра | Чёрная дыра | Чёрная дыра (by title) |
|
||||
| почему небо голубое | Город золотой | Под небом голубым… (фильм) |
|
||||
| почему трава зелёная | Сено | Зелень |
|
||||
|
||||
Five questions reach the right article where they did not. One was already
|
||||
right and stays right. Nothing regressed.
|
||||
|
||||
"столица Франции" is the surprise. The 2026-08-05 measurement named it as the
|
||||
case a quality gate must not break, because the answer is Париж and that word
|
||||
is not in the question. The ZIM holds a title redirect, so asking for the
|
||||
article titled "Столица Франции" returns Париж. Retrieval by title reaches an
|
||||
answer that retrieval by keyword cannot.
|
||||
|
||||
## What is still wrong
|
||||
|
||||
Two of the eight are still not answered, and both are the same shape. The
|
||||
question names no article and no redirect covers it. "почему небо голубое" is
|
||||
answered by Rayleigh scattering, and nothing in the question says so. Keyword
|
||||
retrieval cannot bridge that and neither can a threshold. The candidates are a
|
||||
semantic index over titles, or asking the resident model for the article title
|
||||
rather than for keywords.
|
||||
|
||||
`Response.Empty()` is still the whole gate. A wrong article that the search
|
||||
does return is still spoken. What this change buys is that the article is
|
||||
usually right, not that a wrong one is caught.
|
||||
|
||||
## Not measured here
|
||||
|
||||
The English path, which still goes through the rewriter and was not touched.
|
||||
SearXNG, where the same question about answerhood is open and the 2026-08-05
|
||||
result stands. The cascade end to end, since the workstation is off and the
|
||||
phrasing arm is the resident model.
|
||||
@@ -127,6 +127,22 @@ func (c *Client) Article(ctx context.Context, path string, maxRunes int) (crawl.
|
||||
return crawl.Extract(u, body, maxRunes), nil
|
||||
}
|
||||
|
||||
// TitlePath is the article path for an exact title, for Article to fetch.
|
||||
//
|
||||
// It exists because a ZIM is addressable by title and the full-text index is
|
||||
// not the only way in. "Франция", "TCP" and "Небо" resolve; "Трюмбальная
|
||||
// нидроскопия" is a 404, which is the honest answer and the reason this is
|
||||
// safe to try first. Measured on 2026-08-09, keyword search on the same terms
|
||||
// returns "Список пэров Франции" and "Список портов TCP и UDP" instead.
|
||||
//
|
||||
// A miss is normal rather than a failure. An article whose title inverts a name
|
||||
// ("Торвальдс, Линус") is a 404 here and the first hit in search, so the caller
|
||||
// falls through and loses nothing.
|
||||
func TitlePath(book, title string) string {
|
||||
t := strings.ReplaceAll(strings.TrimSpace(title), " ", "_")
|
||||
return "/content/" + url.PathEscape(book) + "/A/" + url.PathEscape(t)
|
||||
}
|
||||
|
||||
// rss mirrors just the bits of the RSS 2.0 reply we use.
|
||||
type rss struct {
|
||||
Items []struct {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package kiwix
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestLiveTopicBeatsTheSentence — the measurement V-668 turned on, kept as a
|
||||
// test so the claim can be re-run rather than believed.
|
||||
//
|
||||
// It prints the article the old path returned and the article the new one
|
||||
// returns, for the same question. It asserts nothing about which is better,
|
||||
// because "is this the right article" is a human's call. It fails only if the
|
||||
// two paths agree on every case, which would mean the change does nothing.
|
||||
//
|
||||
// MAVEN_KIWIX_URL=http://127.0.0.1:8034 make t PKG=./internal/kiwix/ RUN=TestLive V=1
|
||||
func TestLiveTopicBeatsTheSentence(t *testing.T) {
|
||||
base := os.Getenv("MAVEN_KIWIX_URL")
|
||||
if base == "" {
|
||||
t.Skip("MAVEN_KIWIX_URL unset — point it at the kiwix-server host port")
|
||||
}
|
||||
const book = "wikipedia_ru_all_maxi_2026-02"
|
||||
c := New(base)
|
||||
questions := []string{
|
||||
"что такое TCP?",
|
||||
"что такое фотосинтез",
|
||||
"кто такой Линус Торвальдс?",
|
||||
"кто написал Войну и мир",
|
||||
"что такое чёрная дыра",
|
||||
"почему небо голубое",
|
||||
"почему трава зелёная",
|
||||
"столица Франции",
|
||||
}
|
||||
moved := 0
|
||||
for _, q := range questions {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
before := firstTitle(ctx, c, q, book)
|
||||
topic := Topic(q)
|
||||
after := ""
|
||||
for _, cand := range TitleCandidates(topic) {
|
||||
if page, err := c.Article(ctx, TitlePath(book, cand), 400); err == nil && page.Text != "" {
|
||||
after = page.Title + " (by title)"
|
||||
break
|
||||
}
|
||||
}
|
||||
if after == "" {
|
||||
after = firstTitle(ctx, c, topic, book)
|
||||
}
|
||||
cancel()
|
||||
if before != after {
|
||||
moved++
|
||||
}
|
||||
t.Logf("%-30s before=%-34q after=%q", q, before, after)
|
||||
}
|
||||
t.Logf("%d of %d questions reach a different article", moved, len(questions))
|
||||
if moved == 0 {
|
||||
t.Error("the topic path returns exactly what the sentence path returned")
|
||||
}
|
||||
}
|
||||
|
||||
func firstTitle(ctx context.Context, c *Client, pattern, book string) string {
|
||||
hits, err := c.Search(ctx, pattern, book, 3)
|
||||
if err != nil || len(hits) == 0 {
|
||||
return "(nothing)"
|
||||
}
|
||||
return hits[0].Title
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package kiwix
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/kami/maven/internal/lexicon"
|
||||
"github.com/kami/maven/internal/morph"
|
||||
)
|
||||
|
||||
// Topic reduces a question to the thing it is about, because Kiwix ranks by
|
||||
// keyword overlap and a whole sentence buries the keyword that matters.
|
||||
//
|
||||
// This package's own doc says it: "why is the sky blue" finds a TV episode.
|
||||
// Measured against the Russian ZIM on 2026-08-09, the sentence and the topic
|
||||
// return different articles for the same question. "кто написал Войну и мир"
|
||||
// returns "Радуйся, мир (Доктор Кто)"; "Войну и мир" returns the novel first.
|
||||
// "что такое TCP" returns "Перехват TCP-соединения"; "TCP" returns TCP. The
|
||||
// English path had a rewriter doing this with a model call. The Russian path
|
||||
// reads the book verbatim (V-508) and had nothing.
|
||||
//
|
||||
// It drops three things off the front and stops: the narrative request, the
|
||||
// interrogative, and a verb sitting between them and the noun. Everything else
|
||||
// is kept, because a word this cannot classify is more likely the topic than
|
||||
// noise. An empty return means the utterance was question words alone, and the
|
||||
// caller searches the sentence as before.
|
||||
func Topic(utterance string) string {
|
||||
words := strings.Fields(strings.TrimSpace(utterance))
|
||||
cut := 0
|
||||
for cut < len(words) {
|
||||
w := strings.Trim(strings.ToLower(words[cut]), ".,!?…:;\"'«»")
|
||||
if w == "" {
|
||||
cut++
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case inList(lexicon.NarrativeRequests(), w),
|
||||
inList(lexicon.Interrogatives(), w),
|
||||
inList(lexicon.FirstPerson(), w),
|
||||
// "что ТАКОЕ x", "кто ТАКОЙ x" — the copula that only ever follows
|
||||
// an interrogative, and never a topic on its own.
|
||||
cut > 0 && isCopula(w),
|
||||
// "расскажи ПРО x", "о x". One-letter and two-letter prepositions
|
||||
// are not a closed class worth a lexicon set of their own.
|
||||
cut > 0 && isLeadingPreposition(w),
|
||||
// "кто НАПИСАЛ Войну и мир". A verb here is the question's own
|
||||
// verb, not part of the title. Only after something was already
|
||||
// dropped, so "написал отчёт" as a topic survives intact.
|
||||
cut > 0 && morph.IsVerbForm(w):
|
||||
cut++
|
||||
default:
|
||||
// The question mark is the sentence's, not the title's, and Kiwix
|
||||
// carries it into the keyword match.
|
||||
topic := strings.TrimRight(strings.Join(words[cut:], " "), " .,!?…:;\"'«»")
|
||||
if !hasLetter(topic) {
|
||||
return ""
|
||||
}
|
||||
return topic
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// TitleCandidates is the topic as it might be titled, best first.
|
||||
//
|
||||
// A ZIM title is capitalized and the utterance is not: measured on 2026-08-09,
|
||||
// `/A/фотосинтез` is a 404 and `/A/Фотосинтез` is a 200. The spoken form is
|
||||
// tried first anyway, because a title that begins lowercase on purpose
|
||||
// ("iPhone") would not survive capitalizing it. Both are one request each
|
||||
// against a server on the same box, and a miss is a 404 rather than a wrong
|
||||
// article.
|
||||
func TitleCandidates(topic string) []string {
|
||||
if topic == "" {
|
||||
return nil
|
||||
}
|
||||
r := []rune(topic)
|
||||
up := unicode.ToUpper(r[0])
|
||||
if up == r[0] {
|
||||
return []string{topic}
|
||||
}
|
||||
return []string{topic, string(up) + string(r[1:])}
|
||||
}
|
||||
|
||||
func isCopula(w string) bool {
|
||||
switch w {
|
||||
case "такое", "такой", "такая", "такие", "is", "are", "was", "were":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isLeadingPreposition(w string) bool {
|
||||
switch w {
|
||||
case "про", "о", "об", "обо", "по", "about", "of", "on":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func inList(list []string, w string) bool {
|
||||
for _, x := range list {
|
||||
if x == w {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// hasLetter is the guard against a topic that reduced to punctuation or digits
|
||||
// alone, which no ZIM title matches.
|
||||
func hasLetter(s string) bool {
|
||||
for _, r := range s {
|
||||
if unicode.IsLetter(r) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package kiwix
|
||||
|
||||
import "testing"
|
||||
|
||||
// The cases the 2026-08-09 measurement turned on, plus the ones a topic must
|
||||
// not damage. Each left column returned a wrong article when it was sent whole.
|
||||
func TestTopicKeepsTheThingTheQuestionIsAbout(t *testing.T) {
|
||||
cases := []struct{ utterance, want string }{
|
||||
{"что такое TCP?", "TCP"},
|
||||
{"что такое фотосинтез", "фотосинтез"},
|
||||
{"кто такой Линус Торвальдс?", "Линус Торвальдс"},
|
||||
{"кто написал Войну и мир", "Войну и мир"},
|
||||
{"расскажи про битву при Ватерлоо", "битву при Ватерлоо"},
|
||||
{"what is photosynthesis", "photosynthesis"},
|
||||
// No question word, so there is nothing to drop. The topic is the
|
||||
// whole utterance and the search is what it was before.
|
||||
{"столица Франции", "столица Франции"},
|
||||
{"почему небо голубое", "небо голубое"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := Topic(c.utterance); got != c.want {
|
||||
t.Errorf("Topic(%q) = %q, want %q", c.utterance, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A verb only goes when a question word already went. Otherwise "написал
|
||||
// отчёт" loses the verb that names what he means.
|
||||
func TestTopicDropsAVerbOnlyBehindAQuestionWord(t *testing.T) {
|
||||
if got := Topic("написал отчёт"); got != "написал отчёт" {
|
||||
t.Errorf("Topic dropped a leading verb with no question word: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Question words alone reduce to nothing, and the caller reads that as "no
|
||||
// topic" and searches the sentence rather than searching the empty string.
|
||||
func TestTopicIsEmptyWhenNothingIsLeft(t *testing.T) {
|
||||
for _, q := range []string{"что такое?", "кто?", "почему", "???"} {
|
||||
if got := Topic(q); got != "" {
|
||||
t.Errorf("Topic(%q) = %q, want empty", q, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTitlePathEscapesAndUnderscores(t *testing.T) {
|
||||
got := TitlePath("wikipedia_ru_all_maxi_2026-02", "Чёрная дыра")
|
||||
want := "/content/wikipedia_ru_all_maxi_2026-02/A/%D0%A7%D1%91%D1%80%D0%BD%D0%B0%D1%8F_%D0%B4%D1%8B%D1%80%D0%B0"
|
||||
if got != want {
|
||||
t.Errorf("TitlePath = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// A ZIM title carries a leading capital and the utterance does not. The spoken
|
||||
// form is still tried first, so a title that begins lowercase on purpose keeps
|
||||
// its chance.
|
||||
func TestTitleCandidatesTryTheSpokenFormFirst(t *testing.T) {
|
||||
got := TitleCandidates("фотосинтез")
|
||||
if len(got) != 2 || got[0] != "фотосинтез" || got[1] != "Фотосинтез" {
|
||||
t.Errorf("TitleCandidates = %q", got)
|
||||
}
|
||||
if got := TitleCandidates("TCP"); len(got) != 1 || got[0] != "TCP" {
|
||||
t.Errorf("an already-capital topic was tried twice: %q", got)
|
||||
}
|
||||
if got := TitleCandidates(""); got != nil {
|
||||
t.Errorf("TitleCandidates(\"\") = %q, want nil", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# Raw transcript, two weeks of usage
|
||||
|
||||
YOU: что такое TCP?
|
||||
MAVEN: есть такое: Tcp/Ip — Википедия — TCP позволяет регулировать нагрузку на сеть, а также уменьшать время ожидания данных при передаче на большие расстояния. Более того, TCP гарантирует, что полученные ...
|
||||
[2.1s src=search t=666]
|
||||
|
||||
YOU: кто такой Линус Торвальдс?
|
||||
MAVEN: вот что я нашла: Торвальдс, Линус — Википедия — Ли́нус Бенедикт То́рвальдс (встречается написание Ту́рвальдс, швед. Linus Benedict Torvalds МФА: [ˈliːn.ɵs ˈtuːr.valds] о файле; род. 28 декабря 1969, Хельсинки) — финско-американский программист, создатель ядра Linux.
|
||||
[0.8s src=search t=667]
|
||||
|
||||
YOU: что такое фотосинтез
|
||||
MAVEN: нашла вот это: Фотосинтез — Фотосинтез
|
||||
Схематическое изображение процесса фотосинтеза, происходящего в растениях
|
||||
Упрощённое уравнение фотосинтеза, происходящего в растениях
|
||||
Упрощённая схема фотосинтеза
|
||||
Фотоси́нтез (от др.-греч. φῶς — « свет » и σύνθεσις — «соединённый», «складной», «связывание», « синтез ») — сл…
|
||||
[0.6s src=kiwix t=668]
|
||||
|
||||
YOU: кто написал Войну и мир
|
||||
MAVEN: вот что я нашла: Война и мир — Война и мир
|
||||
Война и мир
|
||||
Война и миръ
|
||||
Обложка издания 1873 года
|
||||
Жанр
|
||||
роман-эпопея
|
||||
Автор
|
||||
Лев Николаевич Толстой
|
||||
Язык оригинала
|
||||
русский, фрагменты на французском и немецком языках
|
||||
Дата написания
|
||||
1863—1869, 1873
|
||||
Дата первой публикации
|
||||
1865—1869
|
||||
Предыдущее
|
||||
Казаки
|
||||
Следующее
|
||||
Анна Каренина
|
||||
Тек…
|
||||
[12.4s src=kiwix t=669]
|
||||
|
||||
```
|
||||
@@ -0,0 +1,4 @@
|
||||
{"reply": "есть такое: Tcp/Ip — Википедия — TCP позволяет регулировать нагрузку на сеть, а также уменьшать время ожидания данных при передаче на большие расстояния. Более того, TCP гарантирует, что полученные ...", "source": "search", "trace": "666", "secs": 2.1235475060530007, "day": 0, "n": 1, "utterance": "что такое TCP?"}
|
||||
{"reply": "вот что я нашла: Торвальдс, Линус — Википедия — Ли́нус Бенедикт То́рвальдс (встречается написание Ту́рвальдс, швед. Linus Benedict Torvalds МФА: [ˈliːn.ɵs ˈtuːr.valds] о файле; род. 28 декабря 1969, Хельсинки) — финско-американский программист, создатель ядра Linux.", "source": "search", "trace": "667", "secs": 0.7689587379572913, "day": 0, "n": 2, "utterance": "кто такой Линус Торвальдс?"}
|
||||
{"reply": "нашла вот это: Фотосинтез — Фотосинтез\nСхематическое изображение процесса фотосинтеза, происходящего в растениях\nУпрощённое уравнение фотосинтеза, происходящего в растениях\nУпрощённая схема фотосинтеза\nФотоси́нтез (от др.-греч. φῶς — « свет » и σύνθεσις — «соединённый», «складной», «связывание», « синтез ») — сл…", "source": "kiwix", "trace": "668", "secs": 0.575586927938275, "day": 0, "n": 3, "utterance": "что такое фотосинтез"}
|
||||
{"reply": "вот что я нашла: Война и мир — Война и мир\nВойна и мир\nВойна и миръ\nОбложка издания 1873 года\nЖанр\nроман-эпопея\nАвтор\nЛев Николаевич Толстой\nЯзык оригинала\nрусский, фрагменты на французском и немецком языках\nДата написания\n1863—1869, 1873\nДата первой публикации\n1865—1869\nПредыдущее\nКазаки\nСледующее\nАнна Каренина\nТек…", "source": "kiwix", "trace": "669", "secs": 12.44599153404124, "day": 0, "n": 4, "utterance": "кто написал Войну и мир"}
|
||||
@@ -0,0 +1,30 @@
|
||||
# Raw transcript, two weeks of usage
|
||||
|
||||
YOU: столица Франции
|
||||
MAVEN: вот что я нашла: Франция — Википедия — Она отличается ... реками. На Сене в 145 км от пролива Ла-Манш расположена столица Франции Париж....
|
||||
[2.3s src=search t=670]
|
||||
|
||||
YOU: что такое фотосинтез
|
||||
MAVEN: есть такое: Фотосинтез: процесс, фазы, функции и значение фотосинтеза — Бестселлеры Фоксфорда: собрали всё, что полюбили тысячи школьников и родителей 🧡 · Фотосинтез происходит в тканях, содержащих хлоропласты, — преимущественно в листе, на который приходится большая часть процессов фотосинтеза. Такая ткань наз…
|
||||
[0.8s src=search t=671]
|
||||
|
||||
YOU: что такое TCP?
|
||||
MAVEN: нашла вот это: TCP — TCP
|
||||
TCP
|
||||
Название
|
||||
Transmission Control Protocol
|
||||
Уровень (по модели OSI )
|
||||
Транспортный
|
||||
Семейство
|
||||
TCP/IP
|
||||
Спецификация
|
||||
RFC 793 (сентябрь 1981 года) / STD 7
|
||||
Основные реализации
|
||||
UNIX , Linux , BSD , Windows
|
||||
Расширяемость
|
||||
Опции
|
||||
Медиафайлы на Викискладе
|
||||
TCP ( англ. Transmission Control Protocol — п…
|
||||
[0.3s src=kiwix t=672]
|
||||
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
{"reply": "вот что я нашла: Франция — Википедия — Она отличается ... реками. На Сене в 145 км от пролива Ла-Манш расположена столица Франции Париж....", "source": "search", "trace": "670", "secs": 2.295847482047975, "day": 0, "n": 1, "utterance": "столица Франции"}
|
||||
{"reply": "есть такое: Фотосинтез: процесс, фазы, функции и значение фотосинтеза — Бестселлеры Фоксфорда: собрали всё, что полюбили тысячи школьников и родителей 🧡 · Фотосинтез происходит в тканях, содержащих хлоропласты, — преимущественно в листе, на который приходится большая часть процессов фотосинтеза. Такая ткань наз…", "source": "search", "trace": "671", "secs": 0.8353607719764113, "day": 0, "n": 2, "utterance": "что такое фотосинтез"}
|
||||
{"reply": "нашла вот это: TCP — TCP\nTCP\nНазвание\nTransmission Control Protocol\nУровень (по модели OSI )\nТранспортный\nСемейство\nTCP/IP\nСпецификация\nRFC 793 (сентябрь 1981 года) / STD 7\nОсновные реализации\nUNIX , Linux , BSD , Windows\nРасширяемость\nОпции\nМедиафайлы на Викискладе\nTCP ( англ. Transmission Control Protocol — п…", "source": "kiwix", "trace": "672", "secs": 0.29547085403464735, "day": 0, "n": 3, "utterance": "что такое TCP?"}
|
||||
@@ -0,0 +1,19 @@
|
||||
# Raw transcript, two weeks of usage
|
||||
|
||||
YOU: что такое TCP?
|
||||
MAVEN: Вот что я нашла: TCP, или Transmission Control Protocol, — это один из основных протоколов передачи данных в интернете. Он работает на транспортном уровне модели OSI и предоставляет поток данных с установкой соединения, гарантируя целостность данных, повторно запрашивая потерянные данные и устраняя дублирование.
|
||||
[2.3s src=kiwix t=673]
|
||||
|
||||
YOU: кто такой Линус Торвальдс?
|
||||
MAVEN: Вот что я нашла: Линус Торвальдс — финно-американский программист, который является создателем ядра Linux. Он швед по имени Linus Benedict Torvalds, родился 28 декабря 1969 года в Хельсинки, Финляндия, и его род деятельности включает программирование, разработку программного обеспечения, писательство, изобретательство, ведение блога, а также он инженер, бизнесмен и специалист в области информатики.
|
||||
[2.4s src=kiwix t=674]
|
||||
|
||||
YOU: столица Франции
|
||||
MAVEN: Вот что я нашла: Столица Франции — Париж.
|
||||
[2.0s src=kiwix t=675]
|
||||
|
||||
YOU: почему небо голубое
|
||||
MAVEN: Я не нашла в источниках ответа на твой вопрос, почему небо голубое.
|
||||
[1.3s src=kiwix t=676]
|
||||
|
||||
```
|
||||
@@ -0,0 +1,4 @@
|
||||
{"reply": "Вот что я нашла: TCP, или Transmission Control Protocol, — это один из основных протоколов передачи данных в интернете. Он работает на транспортном уровне модели OSI и предоставляет поток данных с установкой соединения, гарантируя целостность данных, повторно запрашивая потерянные данные и устраняя дублирование.", "source": "kiwix", "trace": "673", "secs": 2.3279738989658654, "day": 0, "n": 1, "utterance": "что такое TCP?"}
|
||||
{"reply": "Вот что я нашла: Линус Торвальдс — финно-американский программист, который является создателем ядра Linux. Он швед по имени Linus Benedict Torvalds, родился 28 декабря 1969 года в Хельсинки, Финляндия, и его род деятельности включает программирование, разработку программного обеспечения, писательство, изобретательство, ведение блога, а также он инженер, бизнесмен и специалист в области информатики.", "source": "kiwix", "trace": "674", "secs": 2.42521625792142, "day": 0, "n": 2, "utterance": "кто такой Линус Торвальдс?"}
|
||||
{"reply": "Вот что я нашла: Столица Франции — Париж.", "source": "kiwix", "trace": "675", "secs": 1.9803519028937444, "day": 0, "n": 3, "utterance": "столица Франции"}
|
||||
{"reply": "Я не нашла в источниках ответа на твой вопрос, почему небо голубое.", "source": "kiwix", "trace": "676", "secs": 1.2865088270045817, "day": 0, "n": 4, "utterance": "почему небо голубое"}
|
||||
Reference in New Issue
Block a user