1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Embedding and vector index support for semantic search.
//!
//! This module provides:
//!
//! - **TEI Client** ([`tei_client`]): High-performance gRPC client for
//! text-embeddings-inference with connection pooling and batching
//! - **Vector Index** ([`index`]): HNSW-based approximate nearest neighbor
//! search using usearch
//!
//! # Integration with Semantic Search
//!
//! The typical workflow is:
//!
//! 1. Extract code units using [`semantic::extract_units`](crate::semantic::extract_units)
//! 2. Generate embeddings using [`TeiClient`]
//! 3. Store embeddings in [`VectorIndex`] with unit indices as keys
//! 4. Store metadata (units) in a separate JSON file
//! 5. Search returns keys which map back to units
//!
//! # Example
//!
//! ```no_run
//! use go_brrr::embedding::{VectorIndex, IndexConfig, Metric};
//!
//! // Create index matching your embedding model dimensions
//! let config = IndexConfig::new(768) // MiniLM dimensions
//! .with_metric(Metric::InnerProduct);
//!
//! let index = VectorIndex::with_config(config)?;
//!
//! // Reserve capacity for performance
//! index.reserve(10000)?;
//!
//! // Add embeddings (keys correspond to EmbeddingUnit indices)
//! for (i, embedding) in embeddings.iter().enumerate() {
//! index.add(i as u64, embedding)?;
//! }
//!
//! // Search
//! let results = index.search(&query_embedding, 10)?;
//! for (key, distance) in results {
//! let score = 1.0 - distance; // Convert to similarity
//! println!("Unit {}: score {:.3}", key, score);
//! }
//!
//! // Persist
//! index.save("./index.usearch")?;
//! # Ok::<(), anyhow::Error>(())
//! ```
//!
//! # Metric Selection
//!
//! - Use [`Metric::InnerProduct`] for pre-normalized embeddings (most models)
//! - Use [`Metric::Cosine`] if your embeddings aren't normalized
//! - Use [`Metric::L2Squared`] for absolute distance comparisons
// =============================================================================
// TEI Client Re-exports
// =============================================================================
pub use ;
// =============================================================================
// Vector Index Re-exports
// =============================================================================
pub use ;
// =============================================================================
// Tests
// =============================================================================