Skip to content

Design Rationale: Decisions & Benchmarks ​

This page explains why key designs are built this way, and the measured benchmarks behind those decisions. All numbers are methodological conclusions on a local corpus (relative relationships and orders of magnitude are reproducible); examples always use generic technical concepts (MVCC, thread pools, cache breakdown).

Methodology: measure first, then design; benchmarks are generated by the product itself and are reproducible.

Benchmark set: generated by the product ​

POST /api/v1/kb/eval/golden auto-extracts 60 heading self-retrieval queries from the current corpus (unique headings, reasonable length, excluding page-number / TOC / trailing-punctuation noise), scores and stores them — all local.

  • Query = a section heading, target = that section itself → measures the lexical leg's ranking quality.
  • Headings that repeat heavily across documents (e.g. many documents have a "References" section) are excluded, so a hit on any same-heading chunk doesn't count as a lucky draw.
  • The semantic leg uses a hand-written rewrite-question annotation set — humans write the targets, so labels reflect real intent.

The benchmark set depends on no fixed in-repo data; switch the corpus and rerun.

Retrieval design rationale ​

Measured quality of the current design on a 14k-chunk corpus:

Eval setrecall@5Notes
Heading self-retrieval (60)81%Lexical-leg ranking quality
Hand-written rewrites22%Semantic-leg rescue effect
Single-retrieval latency~10 msBounded top-200 compact scan

Three supporting designs:

  1. Heading weighting: kb_fts splits heading / text columns; bm25(fts, 0.0, 10.0, 1.0) lets a heading hit outweigh high-frequency body repetition. This is the single largest source of retrieval quality.
  2. Rescue-gated fusion: when query-token coverage in the best lexical hit is ≥ 0.7, the pure lexical leg is used; otherwise the vector leg joins via RRF. When the two legs differ greatly in precision, the gate prevents a weak signal from diluting a strong one. Hash-fallback embeddings never join the fusion.
  3. CLS pooling decided by metadata: the bge family is trained with CLS pooling; install/activate writes ifg-embed.json, and the runtime picks the pooling method from it, keeping vector semantics correct. Index staleness is judged by a fingerprint (engine + width + pooling), so old vectors stay comparable with new queries.

See Retrieval Pipeline.

Model choice ​

The default is bge-small-zh-v1.5 (512d, ONNX-quantized ≈24 MB): ~10 ms per retrieval, fast rebuild, offline-capable, and stable retrieval quality under the rescue gate. The recommended catalog also offers larger models such as bge-base (768d) — switch the corpus and rerun the same benchmark to re-evaluate. Model choice is governed by measured product-path quality and cost, not model size alone.

Topic hierarchy: deterministic clustering + model only names ​

Topics are organized as domain → subject group → topic, with a clear division of labor:

  • Clustering is deterministic and purely local: embed topic names with the current vector model, then greedy agglomeration within a topic (cosine 0.55, group ≥3). The same data yields identical groups every run — reproducible, auditable, free.
  • The model only names: ≤60 groups per batch, sending only member topic names (never body text), reasoningEffort: off.
  • Propose, then apply: results go into kb_topic_proposals; parent_id is written only after user confirmation; re-accepting a same-name group reuses the existing parent.
  • Hash-fallback embeddings refuse clustering: prompt the user to enable a vector model first.

This design adopts the "LLM extracts topics + human confirms" paradigm (TopicGPT), partitions by existing topics to avoid the structural fragmentation of forced cross-partition merging (the SPARROW lesson), and matches the "embedding clustering builds the tree, the model only names" division (TopicForest).

Background reindex ​

Large-batch embedding runs in a dedicated worker thread while the main thread awaits a completion message; the max event-loop pause is ~43 ms (4000-chunk benchmark), and the service keeps responding during rebuild. See Background Reindex.

Evaluated but not in the default ​

Time-sensitive retrieval (TimelyRAG / ETC): incorporate temporal distance into ranking and predict retrieval timing via entropy trends. Not in the default, because:

  1. The private library is whole-document replacement; the index always holds only the current version, so "retrieving an outdated version" doesn't exist;
  2. Retrieval happens when "assembling a question's context", not during streaming decoding; web retrieval already has explicit off / prepare / live / auto control.

If multiple versions of a document ever coexist long-term, this can extend to adding created_at to ranking and labeling version dates in citations — the version table and restore foundation already exist in the shared library.

Reproduce ​

bash
# Retrieval quality (local, no network)
curl -X POST localhost:8787/api/v1/kb/eval/golden -H "authorization: Bearer $T"
# or UI: Knowledge → rebuild benchmark / retrieval eval / recent evals

Model experiments are rerun on the same benchmark after switching — conclusions are reproducible.

Local-first · inference egresses on demand · fully traceable