You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hermes Agent needs a knowledgebase RAG system that lets users point to a directory (or multiple directories) of documents and have the agent automatically index, embed, and retrieve relevant content during conversations. This is the retrieval pipeline that powers the workspace concept described in #531 and complements the semantic code search in #489.
The core UX: set a directory in config, the agent indexes it, and relevant knowledge is automatically surfaced when you ask questions — no manual @ references or file paths needed.
# ~/.hermes/config.yamlknowledgebase:
enabled: truedirectories:
- ~/notes
- ~/work/docs
- ~/.hermes/workspaceauto_retrieve: true # inject relevant chunks into context automaticallymax_context_chunks: 8# max chunks to inject per queryembedding_model: local # "local" (default) or "openai" or "ollama"reindex_on_change: true # watch for file changes
Competitive Landscape — How Every Major Agent Does This
Deep document understanding (tables, layouts, PDFs)
48.5k
Mem0
Intelligent memory layer with contradiction resolution
27.3k
txtai
All-in-one embeddings DB + workflow engine
10.7k
Key Takeaway
The field is split ~50/50 between RAG-based and agentic-exploration approaches. Hermes currently sits firmly in Category B (agentic exploration via search_files + read_file). Adding RAG gives users the best of both worlds — fast semantic retrieval for knowledge bases plus precise agentic exploration for code. MCP is emerging as the standard bridge protocol, but a native implementation is more reliable and lower-latency.
Recommended Technical Stack
Based on research into what works best for a single-user CLI agent that needs to be lightweight, fast, and dependency-minimal:
Embedding Model
Model
Params
Dims
Speed
Quality
Notes
all-MiniLM-L6-v2
22M
384
14.7ms/1K tok
Good
Best speed, CPU-friendly
BGE-base-en-v1.5
110M
768
22.5ms/1K tok
Better
Best quality/size ratio
CodeRankEmbed
137M
—
—
Best for code
MIT, 8192 context
nomic-embed-text
137M
768
Via Ollama
Good
Fully open, MoE variant available
EmbeddingGemma-300M
300M
128-768
<22ms
Good
Matryoshka dims, 2048 context
Recommendation: Default to all-MiniLM-L6-v2 via fastembed (pure Python, no Ollama/server needed). Offer ollama and openai as alternatives for users who want better quality or already have those set up.
Vector Store
Store
Type
Hybrid Search
Storage
Performance
sqlite-vec
SQLite extension
YES (with FTS5)
Single .sqlite file
Brute-force, good to ~100K vectors
LanceDB
Embedded Rust
Manual
Lance files
Sub-100ms at 1B vectors
ChromaDB
Embedded Python
No native BM25
SQLite + hnswlib
Easy API, more overhead
FAISS
In-memory library
No
Manual save/load
Fastest raw search
Recommendation: sqlite-vec + FTS5. Hermes already uses SQLite extensively (SessionDB). A single .sqlite file gives us:
Vector similarity search via sqlite-vec extension
BM25 keyword search via FTS5 (built-in to SQLite)
Hybrid search by combining both scores
Zero server processes, zero additional dependencies (beyond the extension)
Natural fit with existing Hermes architecture
Fallback: ChromaDB for users who want HNSW performance at scale. LanceDB as a future option.
Chunking Strategy
For documents (Markdown, text, PDF):
Recursive character splitting: 400-512 tokens, 10-20% overlap
Key insight from research: Quality drops sharply above ~2500 tokens per chunk. Keep chunks concise (400-512) even with large context windows. AST-based chunking for code achieves 70.1% Recall@5 vs 42.4% for fixed-size — a massive difference.
Hybrid Search (Dense + Sparse)
Hybrid search improves recall 15-30% over either method alone. Critical for code (variable names, function names, error codes need exact BM25 matching) and docs (technical jargon + conceptual similarity).
Run hybrid search: sqlite-vec cosine similarity + FTS5 BM25
Score fusion (alpha=0.6 semantic, 0.4 keyword)
Return top-K chunks with file path, score, content, line range
CLI commands:
/kb index [directory] — trigger indexing
/kb search <query> — manual search
/kb status — show indexed directories, file counts, last indexed time
/kb clear [directory] — clear index for a directory
Phase 2: Auto-Retrieval & Smart Injection
Auto-retrieval: When enabled, before the agent sees the user's message, run a background kb_search and inject relevant chunks as a system context block:
Auto-index on startup? Should the agent re-check file hashes on every session start, or only on explicit /kb index? Recommendation: check on startup if reindex_on_change: true, but make the hash check fast (<100ms for ~1000 files).
Index size limits? Should we cap the number of files/chunks per directory? Large directories (node_modules, .git) should be auto-excluded via .gitignore patterns.
Multi-user (gateway)? In messaging mode with multiple users, should each user have their own knowledgebase index, or share one? Recommendation: single shared index (matches current single-workspace design).
Embedding model lock-in? If a user changes embedding models, existing indexes become invalid. Should we auto-detect and re-index, or warn? Recommendation: store model name in index metadata, warn + offer re-index on mismatch.
Privacy for cloud embeddings? When using OpenAI/Gemini embeddings, document content is sent to their API. Should we warn users? Recommendation: yes, print a notice on first index with cloud provider.
Overview
Hermes Agent needs a knowledgebase RAG system that lets users point to a directory (or multiple directories) of documents and have the agent automatically index, embed, and retrieve relevant content during conversations. This is the retrieval pipeline that powers the workspace concept described in #531 and complements the semantic code search in #489.
The core UX: set a directory in config, the agent indexes it, and relevant knowledge is automatically surfaced when you ask questions — no manual
@references or file paths needed.Competitive Landscape — How Every Major Agent Does This
Category A: Full RAG with Vector Search
@Codebase/@Docscodebase_searchtoolCategory B: Agentic Exploration (No RAG)
Category C: Document/Knowledge Indexing
Key Takeaway
The field is split ~50/50 between RAG-based and agentic-exploration approaches. Hermes currently sits firmly in Category B (agentic exploration via search_files + read_file). Adding RAG gives users the best of both worlds — fast semantic retrieval for knowledge bases plus precise agentic exploration for code. MCP is emerging as the standard bridge protocol, but a native implementation is more reliable and lower-latency.
Recommended Technical Stack
Based on research into what works best for a single-user CLI agent that needs to be lightweight, fast, and dependency-minimal:
Embedding Model
Recommendation: Default to
all-MiniLM-L6-v2viafastembed(pure Python, no Ollama/server needed). Offerollamaandopenaias alternatives for users who want better quality or already have those set up.Vector Store
Recommendation:
sqlite-vec+ FTS5. Hermes already uses SQLite extensively (SessionDB). A single .sqlite file gives us:Fallback: ChromaDB for users who want HNSW performance at scale. LanceDB as a future option.
Chunking Strategy
For documents (Markdown, text, PDF):
["\n\n", "\n", ". ", " ", ""]For code files:
# file: src/tools/search.py | class: SearchTool | method: search()Key insight from research: Quality drops sharply above ~2500 tokens per chunk. Keep chunks concise (400-512) even with large context windows. AST-based chunking for code achieves 70.1% Recall@5 vs 42.4% for fixed-size — a massive difference.
Hybrid Search (Dense + Sparse)
Hybrid search improves recall 15-30% over either method alone. Critical for code (variable names, function names, error codes need exact BM25 matching) and docs (technical jargon + conceptual similarity).
Alternative: Reciprocal Rank Fusion (RRF) — more robust, no score normalization needed:
Token Budget Management
For a 128K context agent:
Implementation Plan
Phase 1: Core RAG Pipeline (MVP)
Config:
New files:
tools/knowledgebase_tool.py—kb_search(query, directory?),kb_index(directory?),kb_status()agent/knowledgebase.py— Indexing engine: chunking, embedding, storage, retrievalagent/chunker.py— Document chunking (recursive text splitter + basic code splitter)Index storage:
~/.hermes/knowledgebase/indexes/{dir-hash}.sqlite— one SQLite file per indexed directory containing:chunkstable: id, file_path, chunk_index, content, start_line, end_line, file_hashembeddingsvirtual table (sqlite-vec): vector embeddingschunks_ftsvirtual table (FTS5): full-text search indexfilesmetadata table: path, mtime, size, content_hash, last_indexedSupported file types (Phase 1):
pdftotextorpymupdf— optional dependency)Indexing flow:
Search flow:
kb_search(query="deployment architecture")CLI commands:
/kb index [directory]— trigger indexing/kb search <query>— manual search/kb status— show indexed directories, file counts, last indexed time/kb clear [directory]— clear index for a directoryPhase 2: Auto-Retrieval & Smart Injection
Auto-retrieval: When enabled, before the agent sees the user's message, run a background kb_search and inject relevant chunks as a system context block:
Smart injection rules:
File watching:
watchdoglibrary for real-time file watching (background process)Additional config:
Phase 3: Advanced Features
[Source: ~/docs/file.md:12-45]in agent responses@kbreference syntax: Let users explicitly query knowledgebase in messages/kbcommands in Telegram/Discord/SlackArchitecture Decisions
Why sqlite-vec over ChromaDB/LanceDB?
sqlite3 index.sqliteWhy fastembed as default?
pip install fastembed, no Ollama server, no API keyWhy not just use MCP?
MCP could wrap a RAG server, but:
Native RAG with MCP exposure (Phase 3) gives the best of both worlds.
Context Injection vs Tool-Only
Both approaches have merit:
Recommendation: Hybrid. Auto-inject when score > 0.7 (high confidence). Expose
kb_searchtool for explicit queries. User configurable.Dependency Impact
Required (Phase 1)
fastembed— embedding generation (~80MB model download on first use)sqlite-vec— SQLite vector extension (pip installable)Optional
pymupdforpdftotext— PDF text extractionpython-docx— DOCX text extractionwatchdog— file system watchingtree-sitter+ language grammars — AST-based code chunking (Phase 3)ollama— local embedding via Ollama serveropenai— cloud embedding via OpenAI APIInstallation
Relationship to Other Issues
Open Questions
Auto-index on startup? Should the agent re-check file hashes on every session start, or only on explicit
/kb index? Recommendation: check on startup ifreindex_on_change: true, but make the hash check fast (<100ms for ~1000 files).Index size limits? Should we cap the number of files/chunks per directory? Large directories (node_modules, .git) should be auto-excluded via .gitignore patterns.
Multi-user (gateway)? In messaging mode with multiple users, should each user have their own knowledgebase index, or share one? Recommendation: single shared index (matches current single-workspace design).
Embedding model lock-in? If a user changes embedding models, existing indexes become invalid. Should we auto-detect and re-index, or warn? Recommendation: store model name in index metadata, warn + offer re-index on mismatch.
Privacy for cloud embeddings? When using OpenAI/Gemini embeddings, document content is sent to their API. Should we warn users? Recommendation: yes, print a notice on first index with cloud provider.
References