Why LanceDB?
- Serverless: No separate database server required
- Embedded: Runs in-process with your application
- Fast: Native vector search with disk-based persistence
- Zero cost: No cloud infrastructure or API charges
Architecture
Installation
LanceDB is included inrequirements.txt. No additional installation needed.
Initialization
Auto-Initialization
LanceDB auto-creates the vector store on first run:Database path:
data/lancedb/ (configurable via LANCEDB_PATH in .env)Embedding Model
ClinicalPilot uses all-MiniLM-L6-v2 from sentence-transformers:- Dimension: 384
- Model size: ~80MB
- Speed: ~1000 sentences/second on CPU
- Quality: Optimized for semantic similarity
The embedding model downloads automatically on first use (~80MB). Subsequent runs use the cached model.
Ingesting Documents
From Directory
Ingest all.txt, .md, and .pdf files from a directory:
Programmatic Ingestion
Add documents from Python code:Document Chunking
Documents are automatically split into 500-character chunks with 50-character overlap to preserve context.Chunking ensures that embedding quality remains high and search results are granular. A 10-page PDF might generate 50-100 chunks.
Chunking Parameters
Editbackend/rag/lancedb_store.py to customize:
Searching the Vector Store
From Python
From API
The Literature Agent automatically searches LanceDB when processing cases. No manual API calls needed.Configuration
Environment Variables
Absolute Path
You can use an absolute path:Schema
LanceDB table schema:| Field | Type | Description |
|---|---|---|
text | str | Document chunk text |
source | str | Source file or reference |
category | str | Category (e.g., “cardiology”, “pharmacology”) |
vector | list[float] | 384-dimensional embedding |
Performance
Search Latency
- 10K documents: ~10-20ms
- 100K documents: ~50-100ms
- 1M documents: ~200-500ms
LanceDB uses disk-based indices, so performance scales well even with large datasets. RAM usage remains low (~100-200MB).
Embedding Latency
- Single query: ~5-10ms (CPU)
- Batch (100 docs): ~500ms (CPU)
- Batch (1000 docs): ~5s (CPU)
Integration with Agents
The Literature Agent (backend/agents/literature.py) automatically queries LanceDB:
Best Practices
Recommended Content
- Clinical Practice Guidelines (AHA, ACC, ACCP, etc.)
- Pharmacology References (DrugBank extracts, FDA labels)
- Differential Diagnosis Tables
- Your Organization’s Protocols (internal SOPs, pathways)
Avoiding Hallucinations
- Cite sources: Always include
sourcemetadata so agents can reference guidelines - Keep chunks focused: Don’t mix unrelated topics in the same document
- Update regularly: Medical knowledge changes — refresh your RAG store quarterly
Backup and Restore
Backup
Restore
Troubleshooting
”Table not found” Error
Search Returns No Results
Check that documents were ingested:Embedding Model Download Fails
”lancedb not installed” Warning
Advanced: Custom Embeddings
To use OpenAI embeddings instead of sentence-transformers:Next Steps
Observability
Monitor RAG retrieval quality with LangSmith tracing
Testing
Write tests to validate RAG search results