The indexing system is correctly configured and the semantic retrieval problem has been RESOLVED via query expansion for rare entities.
Problem: Queries like "explain litvm" failed to retrieve LitVM documents because:
- LitVM document was at rank 422 (outside top 24 retrieval window)
- Semantic similarity was only 0.291 (below 0.3 threshold)
- BM25 prioritized "explain" over "litvm"
Solution: Added automatic query expansion in backend/utils/litecoin_vocabulary.py:
LTC_ENTITY_EXPANSIONS = {
"litvm": "litecoin virtual machine zero-knowledge omnichain smart contracts",
"mweb": "mimblewimble extension blocks privacy confidential transactions",
# ... more entities
}Result:
| Metric | Before | After |
|---|---|---|
| LitVM Rank | 422 | Top 12 ✅ |
| Similarity Score | 0.291 | 0.448 ✅ |
| Vector Candidates | Not retrieved | 24 above threshold ✅ |
| Documents Retrieved | 0 | 8 unique ✅ |
- Status: ✅ Fixed
- Issue: Previously using
IndexFlatL2(L2 distance) instead ofIndexFlatIP(inner product for cosine similarity) - Fix: Reindexed with
IndexFlatIPafter L2 normalization - Verification:
- Index type:
IndexFlatIP✅ - Metric: 0 (InnerProduct) ✅
- Dimension: 1024 ✅
- Vectors: 2,107 ✅
- Index type:
- Status: ✅ Correct
- Embedding Service: Infinity (
BAAI/bge-m3) - Dimension Match: Query embeddings (1024) = Index dimension (1024) ✅
- Index Path:
/app/backend/faiss_index_1024✅ - Environment:
USE_INFINITY_EMBEDDINGS=true✅
- Status: ✅ Correct
- Reindex Script: Uses
InfinityEmbeddings.embed_documents()✅ - Index Building: Uses
InfinityEmbeddingsfor both indexing and retrieval ✅ - Normalization: L2 normalization applied before creating
IndexFlatIP✅
- Status: ✅ Implemented
- Function:
expand_ltc_entities()inbackend/utils/litecoin_vocabulary.py - Integration: Applied in both
aquery()andastream_query()methods - Example: "explain litvm" → "explain litvm litecoin virtual machine zero-knowledge omnichain smart contracts"
- Query: "explain litvm"
- Best LitVM Document: Rank 422, Score 0.291
- Threshold: 0.3 (lowered to 0.28)
- Retrieval Limit: Top 24 documents (RETRIEVER_K * 2)
Why LitVM documents ranked low:
- Query was generic: "explain litvm" didn't contain specific technical terms
- Document structure: LitVM documents have prepended metadata that dilutes semantic signal
- Embedding mismatch: BGE-M3 prioritizes semantic meaning over keyword matching
- Semantic Embedding Limitations: Query "explain litvm" is semantically generic
- Document Structure: Prepended metadata dilutes embedding signal
- Keyword vs Semantic Mismatch: BM25 didn't prioritize rare entity "litvm"
- ✅ Lowered similarity threshold: 0.3 → 0.28
- ✅ Fixed index type: L2 → InnerProduct
- ✅ Reindexed with correct settings: All 2,107 documents re-embedded
- ✅ Query Expansion: Appends synonyms for rare entities (NEW)
backend/utils/litecoin_vocabulary.py- AddedLTC_ENTITY_EXPANSIONSandexpand_ltc_entities()backend/rag_pipeline.py- Integrated expansion inaquery()andastream_query()
# Test query
curl -X POST http://localhost:8000/api/v1/query \
-H "Content-Type: application/json" \
-d '{"query": "explain litvm"}'
# Expected: LitVM documents in top results with high similarity scores
# Result: ✅ Working as of 2024-12-19The retrieval problem for rare entities like "litvm" has been RESOLVED through query expansion. The system now:
- Detects rare entities in queries
- Appends synonyms to improve semantic matching
- Successfully retrieves relevant documents within the top 24 candidates