This project uses the existing retrieval pipeline service instead of directly embedding FAISS or BM25 libraries.
┌─────────────────────────────────┐
│ User Memory RAG Agent │
│ │
│ - Chunks conversations │
│ - Prepares documents │
│ - Manages local chunk storage │
└────────────┬────────────────────┘
│
│ HTTP API
▼
┌─────────────────────────────────┐
│ Retrieval Pipeline Service │
│ (Port 4242) │
│ │
│ - Dense indexing (FAISS) │
│ - Sparse indexing (BM25) │
│ - Hybrid search │
│ - Reranking │
└─────────────────────────────────┘
The retrieval pipeline must be running before using this system:
cd projects/week3/retrieval-pipeline
python api_server.pyThis will start the retrieval pipeline service on http://localhost:4242
This project no longer requires FAISS or BM25 directly:
pip install -r requirements.txtRequired packages:
openai- For LLM interactionsrequests- For communicating with retrieval pipelinepyyaml- For loading test casesrich- For terminal UIpython-dotenv- For environment variables
Create a .env file with your API keys:
# LLM Provider (at least one required)
KIMI_API_KEY=your_kimi_api_key
OPENAI_API_KEY=your_openai_api_key # Optional, for other providers
# Configuration
LLM_PROVIDER=kimi
INDEX_MODE=hybridDocuments are sent to the retrieval pipeline in this format:
{
"text": "Document content to index",
"metadata": {
"doc_id": "unique_identifier",
"test_id": "test_case_id",
"conversation_id": "conv_123",
# ... other metadata
}
}The retrieval pipeline:
- Generates embeddings for dense search
- Builds BM25 index for sparse search
- Returns a generated
doc_idwhich we map to our chunk IDs
- Query Submission: Sends search query to retrieval pipeline
- Retrieval: Pipeline performs dense/sparse/hybrid search
- ID Resolution: Maps returned doc_ids back to our chunk IDs
- Result Construction: Builds SearchResult objects with local chunks
GET /health- Check if service is availablePOST /clear- Clear existing indexPOST /index- Index a single documentPOST /search- Search indexed documents
Run the pipeline integration test:
python test_pipeline.pyThis verifies:
- Retrieval pipeline connectivity
- Document indexing
- Search functionality
Test system initialization:
python test_startup.pyRun the interactive demo:
python main.py --mode demoOr use the interactive interface:
python main.pySolution: Start the retrieval pipeline service:
cd projects/week3/retrieval-pipeline
python api_server.pyCause: Document format mismatch
Solution: Ensure documents have text field at root level, not in a documents array
Cause: Doc ID mapping issue Solution: The system now handles this automatically by:
- Storing doc_id mappings during indexing
- Checking metadata in search results
- Using fallback to mapped IDs
- No Direct Index Management: The retrieval pipeline handles all indexing
- HTTP Communication: All operations go through REST API
- Doc ID Mapping: We maintain mapping between our chunk IDs and pipeline's generated IDs
- Simplified Dependencies: No need for faiss-cpu, rank-bm25, or nltk
- Service Dependency: Requires retrieval pipeline to be running
- Latency: HTTP overhead adds ~10-50ms per operation
- Batch Operations: Documents are indexed one at a time (pipeline limitation)
- Caching: Local chunk storage reduces retrieval overhead
- Scalability: Retrieval pipeline can be scaled independently
- Batch Indexing: Add batch endpoint to retrieval pipeline
- Persistent Mapping: Save doc_id mappings to disk
- Connection Pooling: Reuse HTTP connections
- Retry Logic: Add exponential backoff for failures
- Async Operations: Use async HTTP client for better performance