How abhi-lash19/vera works
Purpose and Entry Points
Enterprise Knowledge Brain is a terminal-oriented, grounded engineering-knowledge assistant. It ingests local documentation/code artifacts into persistent retrieval indexes, then answers queries through tool-directed retrieval and LLM synthesis. Primary entry points are ingestion/main.py for offline corpus construction, cli.py / cli/__main__.py for interactive use, retrieval/main.py for retrieval access, and mcp_server/main.py for MCP exposure.
Offline Ingestion and Persistence
The ingestion pipeline converts supported artifacts into a common chunk schema, cleans and enriches them, embeds content, and writes retrievable stores. Loaders cover archives, code, PDFs, Word, Markdown, spreadsheets, structured documents, and transcripts in ingestion/loaders/; processing stages are in ingestion/processors/sanitizer.py, ingestion/processors/chunker.py, and ingestion/processors/metadata_enricher.py. ingestion/models/chunk_model.py defines chunk records.
Indexes and metadata are materialized outside the package under ~/.ekb/: dense FAISS, lexical BM25, and SQLite-backed chunk/metadata storage. Key boundaries are ingestion/index/index_manager.py, ingestion/index/faiss_index.py, ingestion/index/bm25_index.py, and ingestion/storage/sqlite_writer.py.
Retrieval Pipeline
Query retrieval combines semantic and lexical search against persisted ingestion outputs. retrieval/embedders/query_embedder.py creates query vectors; retrieval/retrievers/faiss_retriever.py and retrieval/retrievers/bm25_retriever.py retrieve candidate sets. retrieval/fusion/hybrid_retriever.py is the hybrid/RRF fusion boundary, with metadata filtering and cross-encoder reranking in retrieval/filters/metadata_filter.py and retrieval/rerankers/cross_encoder_reranker.py. Results use retrieval/models/result_model.py; SQLite reads are isolated in retrieval/storage/sqlite_reader.py.
Query Orchestration and Tool Planning
The orchestration layer selects an intent, plans tools, executes staged work, and traces execution. Core control points are orchestration/orchestrator.py, orchestration/intent_classifier.py, orchestration/tool_planner.py, and orchestration/stages.py; construction and lifecycle hooks sit in orchestration/factory.py and orchestration/hooks.py. Intent patterns and tool retrieval policy are externalized in config/intent_patterns.yaml and config/tool_retrieval.yaml.
MCP Tool Boundary
mcp_server packages capabilities as seven request-validated tools: flow explanation, component tracing, knowledge search, direct file context, integration listing, debugging, and design comparison. The server entry and dispatch boundary are mcp_server/main.py, mcp_server/registry/tool_registry.py, and mcp_server/executor/tool_executor.py. Tool implementations live in mcp_server/tools/, notably search_knowledge.py, get_file_context.py, and compare_design.py. Direct metadata tools can bypass LLM generation.
Context, Prompts, and LLM Providers
Retrieved chunks are deduplicated, diversified, compressed, validated, and constrained before model invocation. The context boundary is ai_client/context/context_builder.py, with token enforcement in ai_client/context/token_budget.py and models in ai_client/context/models.py. Prompt assembly, XML formatting, citations, safety, and validation are concentrated in ai_client/prompts/builder.py, ai_client/prompts/assembler.py, and ai_client/prompts/xml_formatter.py.
LLM integrations are provider-adapted behind ai_client/llm/base.py and ai_client/llm/provider.py, with Anthropic/Claude and OpenAI clients in ai_client/llm/anthropic_client.py, ai_client/llm/claude_client.py, and ai_client/llm/openai_client.py. Anthropic Claude is the intended reasoning service; OpenAI embeddings are used during ingestion.
Terminal Presentation
The CLI owns stdin/stdout interaction, streaming, local UI state, and debug rendering rather than retrieval or generation logic. Its main surfaces are cli.py, cli_ui/console.py, cli_ui/stream.py, and cli_ui/display.py. Final output formatting and source/token presentation are handled by ai_client/formatter/response_formatter.py and ai_client/formatter/terminal_renderer.py.
Main entry points: index_manager.py Index manager · hybrid_retriever.py Hybrid retrieval · tool_executor.py MCP tool executor · main.py Retrieval entry
Components 23
Offline Ingestion
Builds persistent knowledge indexes from local artifacts.
- Ingestion entry
ingestion/main.py - Artifact loaders · Supports documents, code, archives, and transcripts.
- Chunk processing · Sanitizes, chunks, and enriches common chunk records.
ingestion/processors/chunker.py - Chunk schema
ingestion/models/chunk_model.py - Index manager · Coordinates dense, lexical, and metadata writes.
ingestion/index/index_manager.py - FAISS index
ingestion/index/faiss_index.py - BM25 index
ingestion/index/bm25_index.py - SQLite chunk store · Persistent chunk and metadata storage under ~/.ekb.
ingestion/storage/sqlite_writer.py
Retrieval
Combines persisted semantic and lexical search.
- Retrieval entry
retrieval/main.py - Query embedder
retrieval/embedders/query_embedder.py - Hybrid retrieval · Fuses FAISS and BM25 candidate sets.
retrieval/fusion/hybrid_retriever.py - Metadata filter
retrieval/filters/metadata_filter.py - Cross-encoder reranker
retrieval/rerankers/cross_encoder_reranker.py - SQLite reader
retrieval/storage/sqlite_reader.py
Orchestration
Plans and executes query work.
- Query orchestrator · Classifies intent, plans tools, stages execution, and traces work.
orchestration/orchestrator.py - Intent and tool planner · Uses external intent patterns and retrieval policy.
orchestration/tool_planner.py
AI Response
Builds grounded context and invokes providers.
- Context builder · Deduplicates, diversifies, compresses, validates, and token-bounds evidence.
ai_client/context/context_builder.py - Prompt assembly · Builds XML-formatted, cited, validated prompts.
ai_client/prompts/builder.py - LLM provider adapter · Routes reasoning to Claude and supports provider clients.
ai_client/llm/provider.py - Terminal renderer · Formats final answers, sources, and token presentation.
ai_client/formatter/terminal_renderer.py
Interfaces
Terminal and MCP access surfaces.
- Terminal CLI · Owns terminal interaction, streaming, UI state, and debug rendering.
cli.py - MCP server · Exposes validated engineering-knowledge tools.
mcp_server/main.py - MCP tool executor · Executes search, file context, design comparison, and metadata tools.
mcp_server/executor/tool_executor.py
Connections 26
- Ingestion entry → Artifact loaders: loads artifacts
- Artifact loaders → Chunk processing: normalizes content
- Chunk processing → Chunk schema: produces
- Chunk schema → Index manager: indexes chunks
- Index manager → FAISS index: writes dense vectors
- Index manager → BM25 index: writes lexical terms
- Index manager → SQLite chunk store: writes chunks and metadata
- Retrieval entry → Query embedder: embeds query
- Query embedder → Hybrid retrieval: query vector
- FAISS index → Hybrid retrieval: semantic candidates
- BM25 index → Hybrid retrieval: lexical candidates
- Hybrid retrieval → Metadata filter: fused results
- Metadata filter → Cross-encoder reranker: filtered candidates
- SQLite chunk store → SQLite reader: persisted metadata
- SQLite reader → Metadata filter: chunk metadata
- Query orchestrator → Intent and tool planner: selects intent and tools
- Intent and tool planner → Retrieval entry: plans retrieval
- Cross-encoder reranker → Context builder: ranked evidence
- Context builder → Prompt assembly: grounded context
- Prompt assembly → LLM provider adapter: assembled prompt
- Terminal CLI → Query orchestrator: interactive queries
- MCP server → MCP tool executor: validated tool requests
- MCP tool executor → Query orchestrator: LLM-backed tools
- MCP tool executor → Retrieval entry: direct retrieval tools
- LLM provider adapter → Terminal renderer: generated response
- Terminal renderer → Terminal CLI: formatted output