Skip to content

feat: Phase 3 — Brain Mode hybrid search (usearch + RRF)#362

Merged
ajianaz merged 2 commits into
developfrom
feat/brain-mode-phase3
Jul 22, 2026
Merged

feat: Phase 3 — Brain Mode hybrid search (usearch + RRF)#362
ajianaz merged 2 commits into
developfrom
feat/brain-mode-phase3

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Phase 3: Brain Mode — hybrid code search combining 3 signals with RRF fusion.

What's new

Component Description
CodeVectorIndex usearch HNSW vector index with fs2 file locking, key↔symbol mapping
brain_search() FTS5 + vector KNN + graph BFS → RRF (k=60) fusion
Schema v4 embedding_tier, embedding_dims, embedding_model, last_embedded_at on projects
cora brain <query> CLI command with --json and --limit flags
cora.brain_search MCP tool for LLM-driven code search
Index-time embedding Static token embeddings (256d) computed during cora index

Architecture

cora index
  → walk files, parse symbols, build FTS5 + graph
  → embed_project(): load all symbols, embed via static tokens, insert to usearch

cora brain "error handling"
  → FTS5 keyword search (top 50)
  → usearch KNN cosine (top 50)
  → graph BFS depth-2 from top-5 FTS hits
  → RRF fusion: score += 1/(60+rank) per signal
  → sorted results with provenance (fts, vector, graph)

Files

  • src/index/vector.rs (384 lines) — CodeVectorIndex: usearch wrapper with CRUD, persistence, locking
  • src/index/brain.rs (257 lines) — Hybrid search engine + index-time embedding
  • src/index/schema.rs — Schema v4 migration
  • src/index/mod.rs — Wire embed_project into index pipeline
  • src/main.rs — Brain CLI command
  • src/mcp/tools.rs — MCP tool registration + handler
  • Cargo.toml — usearch v2, fs2 v0.4

Test results

  • 692 tests pass, 0 failures
  • Clippy: 0 errors (16 dead_code warnings — expected for Phase 3 scope)
  • Manual test: cora index → 1734 symbols embedded, cora brain "TokenEmbedding" → top result = TokenEmbedding struct with fts,vector signals

Closes #359

ajianaz added 2 commits July 22, 2026 23:51
- Add CodeVectorIndex (usearch HNSW) with file locking (fs2)
- Schema v4: embedding metadata columns on projects table
- brain_search(): FTS5 + vector KNN + graph BFS → RRF k=60 fusion
- Index-time embedding via static tokens (256d) during cora index
- CLI: cora brain <query> [--json] [--limit N]
- MCP tool: cora.brain_search

Closes #359
- Add #![allow(dead_code)] to vector.rs (Phase 4+ API) and token_vocab.rs (Phase 5)
- Add #[allow(dead_code)] on TokenEmbedding::into_vec
- Add #[cfg(test)] on cosine_similarity (test-only)
- Remove unused codecora_home import from brain.rs
@ajianaz
ajianaz merged commit 12b6695 into develop Jul 22, 2026
10 checks passed
@ajianaz
ajianaz deleted the feat/brain-mode-phase3 branch July 22, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 3: Brain Mode — Hybrid Search (usearch + RRF)

1 participant