GitHub Issue: CodeContext Sparse Vector Index Issue
Issue Title: CodeContext fails to create sparse_vector index in Milvus, causing semantic search to fail
Labels: bug, needs-investigation, milvus
Environment Configuration
- Development Machine: Windows 11 (Goose AI with Qwen3-coder-next)
- Milvus Server: Linux (Ubuntu 22.04) - IP: 192.168.1.100
- Ollama Server: Linux (Ubuntu 22.04) - IP: 192.168.1.101
- Milvus Version: 2.6.12 (pymilvus 2.6.12)
- CodeContext MCP Server: Latest version (zilliztech/claude-context-mcp)
Summary
CodeContext/Claude Context MCP server fails to create required vector indexes for sparse_vector fields in Milvus, causing semantic search to fail with error:
"ErrorCode: UnexpectedError. Reason: there is no vector index on field: [sparse_vector], please create index firstly"
Expected Behavior
The CodeContext MCP server should:
- Automatically create the sparse_vector index when indexing a codebase
- Preserve indexes when re-indexing (no collection recreation that orphan indexes)
- Enable semantic search without manual intervention
Actual Behavior
- Indexing completes (files get chunked and embeddings generated)
- Collection created but sparse_vector field has no index
- Search fails with "no vector index" error
- Collection hash changes between indexing attempts (hybrid_code_chunks_865434e6 → hybrid_code_chunks_f817ae2e)
- Manual intervention required to create sparse_vector index
Reproduction Steps
- Install CodeContext MCP server
- Configure with Milvus server at 192.168.1.100:19530
- Index a codebase with custom extensions (e.g., .pas, .dfm)
- Attempt semantic search using
Codecontext.searchCode()
- Observe error: "no vector index on field: [sparse_vector]"
Error Messages
❌ Codebase 'D:\medfamserv' indexing failed.
🚨 Error: Failed to load collection 'hybrid_code_chunks_f817ae2e' after 5 attempts:
Error: ErrorCode: UnexpectedError. Reason: there is no vector index on field: [sparse_vector],
please create index firstly
📊 Failed at: 0.0% progress
Workaround
Manually create sparse_vector index using pymilvus:
from pymilvus import MilvusClient
from pymilvus.milvus_client.index import IndexParams, IndexParam
client = MilvusClient(uri="192.168.1.100:19530")
collection_name = "hybrid_code_chunks_f817ae2e"
# Create IndexParams object
index_params = IndexParams()
# Add sparse_vector index with correct type
index_params.add_index(
field_name="sparse_vector",
index_type="SPARSE_WAND",
index_name="sparse_wand_index",
metric_type="IP",
params={"index_level": 1, "reorder_k": 100}
)
# Create index in Milvus
client.create_index(
collection_name=collection_name,
index_params=index_params
)
Technical Details
Collection Structure
Fields:
- id (VARCHAR, max_length=512, primary)
- content (VARCHAR, max_length=65535, analyzer enabled)
- vector (FLOAT_VECTOR, dim=768) ← Dense embedding
- sparse_vector (SPARSE_FLOAT_VECTOR) ← BM25 sparse vector
- relativePath (VARCHAR, max_length=1024)
- startLine (INT64)
- endLine (INT64)
- fileExtension (VARCHAR, max_length=32)
- metadata (VARCHAR, max_length=65535)
Required Indexes (Auto-Created vs Missing)
vector_index: HNSW on 'vector' field ✅
sparse_wand_index: SPARSE_WAND on 'sparse_vector' field ❌ (missing)
Investigation Results
Root Cause Analysis
- Missing default index creation - MCP server doesn't create sparse_vector indexes automatically
- Collection recreation - Hash changes between indexing attempts orphan old indexes
- Index persistence - Indexes not transferred to new collections
API Requirements Discovered
- pymilvus 2.6.12
IndexParams is a list subclass, not dict-like
- Requires
add_index() method for adding index configurations
- Sparse vector search requires
SPARSE_WAND (not SPARSE_INVERTED)
Environment Architecture
┌─────────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Windows Machine │ │ Linux Server │ │ Linux Server │
│ (Goose + Qwen) │────>│ (Milvus) │────>│ (Ollama) │
│ 192.168.1.102 │ │ 192.168.1.100 │ │ 192.168.1.101 │
└─────────────────────┘ └──────────────────┘ └──────────────────┘
Files Created for Investigation
Diagnostic Scripts
- fix_sparse_index_v2.py - Creates sparse_vector index for any CodeContext collection
- diagnose_indexparams.py - Analyzes IndexParams class hierarchy
- diagnose_indexparam.py - Analyzes IndexParam constructor
- test_sparse_wand.py - Tests different index types
- test_direct_search.py - Direct Milvus search testing
Documentation
- CODECONTEXT_DIAGNOSTIC_REPORT.md - Full technical report
- INDEX_FIX_SUMMARY.md - Quick reference for the fix
Suggestions for Fix
- Add automatic index creation - MCP server should create indexes after collection creation
- Fix collection naming - Use consistent collection names or migration strategy
- Add config option - Allow users to specify index parameters for different vector fields
- Add health check - Verify indexes exist before search attempts
Workaround Script (For Deployment)
#!/usr/bin/env python3
# auto_fix_codecontext_index.py
from pymilvus import MilvusClient
from pymilvus.milvus_client.index import IndexParams, IndexParam
client = MilvusClient(uri="192.168.1.100:19530")
collections = client.list_collections()
codecontext_collections = [c for c in collections if 'hybrid_code_chunks' in c.lower()]
for collection_name in codecontext_collections:
try:
collection_info = client.describe_collection(collection_name)
field_names = [f['name'] for f in collection_info['fields']]
if 'sparse_vector' not in field_names:
continue
current_indexes = client.list_indexes(collection_name)
if any('sparse' in idx.lower() for idx in current_indexes):
continue
index_params = IndexParams()
index_params.add_index(
field_name="sparse_vector",
index_type="SPARSE_WAND",
index_name="sparse_wand_index",
metric_type="IP",
params={"index_level": 1, "reorder_k": 100}
)
client.create_index(collection_name=collection_name, index_params=index_params)
print(f"✓ Index created for {collection_name}")
except Exception as e:
print(f"✗ Error for {collection_name}: {e}")
Questions for Maintainers
- Is automatic sparse_vector index creation expected behavior?
- Are there configuration options for customizing vector indexes?
- Why does collection hash change between indexing attempts?
- Is this a known issue with specific versions of pymilvus/Milvus?
- Are there recommended versions for compatibility?
Report generated: May 2026
Maintainer: CodeContext tester
AI Tools Used: Goose & Qwen3-coder-next
Report Version: 1.0
GitHub Issue: CodeContext Sparse Vector Index Issue
Issue Title: CodeContext fails to create sparse_vector index in Milvus, causing semantic search to fail
Labels: bug, needs-investigation, milvus
Environment Configuration
Summary
CodeContext/Claude Context MCP server fails to create required vector indexes for sparse_vector fields in Milvus, causing semantic search to fail with error:
Expected Behavior
The CodeContext MCP server should:
Actual Behavior
Reproduction Steps
Codecontext.searchCode()Error Messages
Workaround
Manually create sparse_vector index using pymilvus:
Technical Details
Collection Structure
Required Indexes (Auto-Created vs Missing)
Investigation Results
Root Cause Analysis
API Requirements Discovered
IndexParamsis alistsubclass, not dict-likeadd_index()method for adding index configurationsSPARSE_WAND(notSPARSE_INVERTED)Environment Architecture
Files Created for Investigation
Diagnostic Scripts
Documentation
Suggestions for Fix
Workaround Script (For Deployment)
Questions for Maintainers
Report generated: May 2026
Maintainer: CodeContext tester
AI Tools Used: Goose & Qwen3-coder-next
Report Version: 1.0