Skip to content

API Reference parrot.stores.kb.local

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

parrot.stores.kb.local

View source

LocalKB: Knowledge Base from local text and markdown files with FAISS vector store.

Alias AbstractKnowledgeBase

Re-exported from parrot.stores.kb.abstract.AbstractKnowledgeBase.

Alias Document

Re-exported from parrot.stores.models.Document.

Class LocalKB

Local Knowledge Base that loads markdown and text documents from a local directory.

Uses FAISS for semantic search with disk persistence for fast loading. Ideal for agent-specific knowledge like:

  • Database query patterns
  • Tool usage examples
  • Domain-specific procedures
  • Analysis templates
Parameter Type Default Description
name str Name of the KB (e.g., agent name)
kb_directory Path Path to directory containing .md and .txt files
category str 'local' Category identifier
description str None KB description
activation_patterns List[str] None Patterns that activate this KB
embedding_model str 'sentence-transformers/all-mpnet-base-v2' Model for embeddings
dimension int 384 Embedding dimension
chunk_size int 4096 Size of text chunks
chunk_overlap int 100 Overlap between chunks
always_active bool True Always include in context
auto_load bool True Load on initialization
**kwargs {}

Method LocalKB.should_activate

Determine if KB should activate. For local KB, usually always active.

should_activate(query: str, context: Dict[str, Any]) -> Tuple[bool, float]

Parameter Type Default Description
query str
context Dict[str, Any]

Returns: Tuple[bool, float]

Method LocalKB.load_documents

Load markdown documents from kb_directory into FAISS.

load_documents(force_reload: bool = False) -> int

Parameter Type Default Description
force_reload bool False Force reload even if cache exists

Returns: int — Number of documents loaded

Method LocalKB.search

Search for relevant knowledge in markdown files.

search(query: str, k: int = 5, score_threshold: float = 0.5, user_id: str = None, session_id: str = None, ctx: RequestContext = None, **kwargs) -> List[Dict[str, Any]]

Parameter Type Default Description
query str Search query
k int 5 Number of results
score_threshold float 0.5 Minimum similarity score
user_id str None
session_id str None
ctx RequestContext None
**kwargs {}

Returns: List[Dict[str, Any]] — List of relevant chunks with metadata

Method LocalKB.format_context

Format search results for prompt injection.

Groups results by source file for clarity.

format_context(results: List[Dict]) -> str

Parameter Type Default Description
results List[Dict]

Returns: str

Method LocalKB.close

Cleanup resources.

close()

Alias RequestContext

Re-exported from parrot.utils.helpers.RequestContext.

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