Skip to content

API Reference parrot.stores.kb.store

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.stores.kb.store

View source

KnowledgeBaseStore — In-memory fact store with FAISS-backed similarity search.

Embedding models are loaded lazily via EmbeddingRegistry on first access to self.embeddings. Construction no longer loads a SentenceTransformer directly, eliminating 5-30 s startup latency when the KB is never queried.

Two KnowledgeBaseStore instances sharing the same embedding_model name will reuse a single cached EmbeddingModel object from the registry.

Class KnowledgeBaseStore

Lightweight in-memory store for validated facts.

Parameter Type Default Description
embedding_model str 'all-MiniLM-L6-v2' HuggingFace model name (e.g. "all-MiniLM-L6-v2"). The model is loaded lazily on first add_facts() / search_facts() call via EmbeddingRegistry.
dimension int 384 Embedding vector dimension (must match the model output).
index_type str 'Flat' FAISS index type — "Flat" (exact) or "HNSW" (approximate, faster for larger KBs).

Attributes:

Attribute Type Description
facts List[str]
fact_metadata List[dict]
embeddings Return the cached embedding model, loading it on first access. Uses EmbeddingRegistry for deduplication — multiple KnowledgeBaseStore instances with the same model name share one object.

Method KnowledgeBaseStore.add_fact

Add a single validated fact to the KB.

add_fact(fact: Dict[str, Any])

Parameter Type Default Description
fact Dict[str, Any]

Method KnowledgeBaseStore.add_facts

Add validated facts to the KB.

Triggers lazy loading of the embedding model on first call.

add_facts(facts: List[Dict[str, Any]])

Parameter Type Default Description
facts List[Dict[str, Any]] List of fact dicts. Each dict must have a "content" key and an optional "metadata" dict.

Method KnowledgeBaseStore.search_facts

Ultra-fast fact retrieval.

Triggers lazy loading of the embedding model on first call.

search_facts(query: str, k: int = 5, score_threshold: float = 0.5) -> List[Dict[str, Any]]

Parameter Type Default Description
query str Free-text query string.
k int 5 Maximum number of results to return.
score_threshold float 0.5 Minimum cosine similarity score (0-1).

Returns: List[Dict[str, Any]] — List of result dicts with "fact", "score", and "metadata" keys, sorted by descending score.

Method KnowledgeBaseStore.get_facts_by_category

Retrieve all facts in a category.

get_facts_by_category(category: str) -> List[Dict]

Parameter Type Default Description
category str Category string.

Returns: List[Dict] — List of fact dicts.

Method KnowledgeBaseStore.get_entity_facts

Get all facts related to an entity.

get_entity_facts(entity: str) -> List[Dict]

Parameter Type Default Description
entity str Entity string.

Returns: List[Dict] — List of fact dicts.

Method KnowledgeBaseStore.close

Cleanup resources if needed.

close()

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally