feat(query): exact, lexical, fuzzy, graph and slice query surface

- exact channel resolves canonical ids, aliases and unique exact names only;
  multiple exact names are returned as candidates, never silently chosen
- lexical channel uses weighted FTS5 BM25 over CJK-bigram segmented fields and
  reports the matching field; fuzzy channel recalls via the gram index with
  bounded edit distance, CJK single-character and prefix fallbacks for typos
  whose bigrams do not overlap
- weighted RRF fuses per-node ranks (exact 1.5, lexical/fuzzy/semantic 1.0) and
  bounded graph expansion follows references both ways, contains children,
  calls/imports in their direction with --relation/--reverse, depth decay and
  explicit truncation; --kind filters after expansion
- document/execution/hybrid slices share one plan+materialise traversal, skip
  ancestor duplication, include module context for execution imports, report
  external/dynamic gaps, enforce the 32 KiB budget on UTF-8 boundaries and keep
  exact source text with path/span provenance
- stale databases are refused unless --snapshot is explicit; query never
  compiles implicitly and emits the single result envelope with honest
  channels/truncated/diagnostics
- add end-to-end query tests for CJK recall, typo recall, exact/ambiguous ids,
  kind filtering, graph neighbours, slices, staleness, missing database,
  no-result honesty and explicit semantic-config failure
This commit is contained in:
marqdo-knowledge committed 2026-11-26 01:46:17 +08:00
1 parent 66f3e168c4
commit 514d9fbd4c
10 files changed
+2414 -16

No files matched your search

+32
View File
@@ -640,6 +640,38 @@ impl ReadStore {
Ok(out)
}
/// Bounded prefix recall for short/typo queries without shared grams.
pub fn prefix_candidates(
&self,
normalized_prefix: &str,
limit: usize,
) -> Result<Vec<NodeIdHit>, KnowledgeError> {
if normalized_prefix.is_empty() {
return Ok(Vec::new());
}
let like = format!("{}%", escape_like(normalized_prefix));
let mut statement = self
.conn
.prepare(
"SELECT id FROM nodes
WHERE searchable = 1 AND (title_norm LIKE ?1 ESCAPE '\\' OR symbol_norm LIKE ?1 ESCAPE '\\')
ORDER BY id LIMIT ?2",
)
.map_err(db)?;
let rows = statement
.query_map(rusqlite::params![like, limit as i64], |row| {
row.get::<_, i64>(0)
})
.map_err(db)?;
let mut out = Vec::new();
for row in rows {
out.push(NodeIdHit {
node_id: row.map_err(db)?,
});
}
Ok(out)
}
pub fn embeddings(
&self,
model_digest: &str,