Skip to content

feat(embed): Phase 1 — static token embedding engine#354

Merged
ajianaz merged 3 commits into
developfrom
feat/phase1-static-token-embedding
Jul 22, 2026
Merged

feat(embed): Phase 1 — static token embedding engine#354
ajianaz merged 3 commits into
developfrom
feat/phase1-static-token-embedding

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Phase 1: Static Token Embedding (Brain Mode Roadmap)

Dual-backend code embedding for Brain Mode.

What's included

File Purpose
src/embed/tokens.rs Hashing-trick backend (256-dim, zero-dep) + tokenizer with camelCase/snake_case splitting
src/embed/token_vocab.rs Pre-trained nomic-embed-code backend (768-dim, real vectors)
src/embed/mod.rs Module root, re-exports both backends
vendored/nomic/ 30MB int8 blob (40,856 tokens × 768 dims) + vocab + Apache-2.0 license
scripts/extract_code_tokens.py Reference extraction script (for re-generating vectors)
THIRD_PARTY.md License attribution for nomic-embed-code

Architecture

tokenize_code(code) → HashMap<String, u32>
  ├─→ embed() → TokenEmbedding (256-dim, hashing trick, fast)
  └─→ embed_pretrained() → PretrainedEmbedding (768-dim, real vectors)

Tokenizer improvements

  • camelCase splitting: calculateHash → [calculate, hash]
  • snake_case splitting: hello_world → [hello, world]
  • Acronym grouping: HTTPServer → [HTTP, Server]
  • Multi-char operators: ->, ::, += as single tokens
  • Stop punctuation filtering, number normalization

Trade-offs

  • Bag-of-tokens = no positional context (acceptable for code search)
  • 30MB binary size increase (vendored vectors)
  • Hashing trick is noisy for cross-language comparison (expected)

Testing

  • 36 embed-specific tests (all pass)
  • 695 total tests (0 failures)
  • Binary format verification, normalization checks, similarity quality

Roadmap context

Phase 0 (rename) ✅ → Phase 1 (this PR) → Phase 2 (tree-sitter + knowledge graph) → Phase 3 (brain mode commands) → Phase 4 (uteke integration) → Phase 5 (Voyage-4-Nano ONNX)

ajianaz added 3 commits July 22, 2026 11:04
Dual-backend code embedding for Brain Mode:

1. Hashing trick (tokens.rs) — zero-dep, 256-dim, fast.
   Good for dedup/near-duplicate detection.

2. Pre-trained nomic-embed-code (token_vocab.rs) — real 768-dim
   vectors from the 7B code model, vendored as 30MB int8 blob.
   ~94.5% recall@10 vs full model per CBM benchmarks.

Tokenizer handles camelCase/snake_case/acronym splitting for
better vocab coverage (calculateHash → [calculate, hash]).

Vendored from CBM (Apache-2.0): code_vectors.bin (40,856 tokens
× 768 dims, int8 quantized), code_tokens.txt, LICENSE, NOTICE.

36 tests covering both backends, tokenizer, and quality checks.
695 total tests pass (0 failures).

Phase 1 of cora-code Brain Mode roadmap.
See: cora-code-dev skill, Phase 0-5 plan.
- Remove premature pub use re-exports (will add in Phase 3)
- Add #![allow(dead_code)] — API not yet consumed by commands
- Fix test import path for tokenize_code
- Run cargo fmt
@ajianaz
ajianaz merged commit a6098ec into develop Jul 22, 2026
10 checks passed
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.

1 participant