pub struct KnowledgeIndex { /* private fields */ }Expand description
In-memory, term-indexed knowledge base built from ingested documents.
Retrieval is based on IDF-weighted token overlap: content words that appear rarely across the corpus are weighted more heavily, focusing results on discriminative evidence.
§Examples
use lmm_agent::cognition::knowledge::KnowledgeIndex;
let mut idx = KnowledgeIndex::new();
idx.ingest_text(
"rust-book",
"Rust prevents data races at compile time through its ownership model.",
);
let hits = idx.query("What prevents data races in Rust?", 3);
assert!(!hits.is_empty());Implementations§
Source§impl KnowledgeIndex
impl KnowledgeIndex
Sourcepub fn ingest_text(&mut self, source: &str, text: &str) -> usize
pub fn ingest_text(&mut self, source: &str, text: &str) -> usize
Ingests a raw text string under the given source label.
The text is split into sentence-level chunks via a lightweight sentence splitter before being indexed. Returns the number of chunks created.
Sourcepub fn query(&self, question: &str, top_k: usize) -> Vec<&DocumentChunk>
pub fn query(&self, question: &str, top_k: usize) -> Vec<&DocumentChunk>
Returns the top_k most relevant DocumentChunks for question.
Chunks are scored by the sum of IDF weights for each question token that appears in the chunk.
Sourcepub fn answer(&self, question: &str, top_k: usize) -> Option<String>
pub fn answer(&self, question: &str, top_k: usize) -> Option<String>
Returns an extractive answer to question from the knowledge base,
or None if no relevant chunks are found.
The top-top_k chunks are concatenated and passed to
lmm::text::TextSummarizer with the original question as a relevance
hint. The summariser selects the sentences most likely to answer the question.
Trait Implementations§
Source§impl Clone for KnowledgeIndex
impl Clone for KnowledgeIndex
Source§fn clone(&self) -> KnowledgeIndex
fn clone(&self) -> KnowledgeIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more