codelens_engine/embedding/
mod.rs1use crate::embedding_types::{EmbeddingIndexInfo, EmbeddingRuntimeInfo, SemanticMatch};
5use fastembed::TextEmbedding;
6use serde::Serialize;
7use std::sync::Mutex;
8
9mod cache;
11mod chunk_ops;
12mod engine_impl;
13pub(super) mod ffi;
14mod prompt;
15mod runtime;
16mod vec_store;
17
18use cache::TextEmbeddingCache;
19use vec_store::SqliteVecStore;
20
21pub use chunk_ops::{CategoryScore, DuplicatePair, OutlierSymbol};
23pub use prompt::auto_sparse_should_enable;
24pub use runtime::{
25 configured_embedding_model_name, configured_embedding_runtime_info,
26 configured_embedding_runtime_preference, configured_embedding_threads,
27 embedding_model_assets_available,
28};
29
30pub(super) use chunk_ops::embedding_to_bytes;
33pub(super) use runtime::{CHANGED_FILE_QUERY_CHUNK, DEFAULT_DUPLICATE_SCAN_BATCH_SIZE};
35
36#[cfg(test)]
38pub(super) use crate::project::ProjectRoot;
39#[cfg(test)]
40pub(super) use chunk_ops::duplicate_pair_key;
41#[cfg(test)]
42pub(super) use prompt::{
43 auto_hint_mode_enabled, auto_hint_should_enable, build_embedding_text,
44 contains_format_specifier, extract_api_calls, extract_api_calls_inner, extract_body_hint,
45 extract_comment_body, extract_leading_doc, extract_nl_tokens, extract_nl_tokens_inner,
46 hint_char_budget, hint_line_budget, is_nl_shaped, is_static_method_ident, is_test_only_symbol,
47 language_supports_nl_stack, language_supports_sparse_weighting, looks_like_error_or_log_prefix,
48 looks_like_meta_annotation, nl_tokens_enabled, should_reject_literal_strict,
49 strict_comments_enabled, strict_literal_filter_enabled,
50};
51#[cfg(test)]
52pub(super) use runtime::{
53 CODESEARCH_MODEL_NAME, DEFAULT_MACOS_EMBED_BATCH_SIZE, embed_batch_size,
54 recommended_embed_threads, requested_embedding_model_override, resolve_model_dir,
55};
56
57pub struct EmbeddingEngine {
60 model: Mutex<TextEmbedding>,
61 store: SqliteVecStore,
62 model_name: String,
63 runtime_info: EmbeddingRuntimeInfo,
64 text_embed_cache: Mutex<TextEmbeddingCache>,
65 indexing: std::sync::atomic::AtomicBool,
66}
67
68#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
69pub struct QueryEmbeddingCacheStats {
70 pub enabled: bool,
71 pub entries: usize,
72 pub max_entries: usize,
73}
74
75#[derive(Debug, Clone, Default, Serialize, PartialEq, Eq)]
76pub struct EmbeddingFreshnessReport {
77 pub checked_files: usize,
78 pub unchanged_files: usize,
79 pub refreshed_files: usize,
80 pub removed_files: usize,
81 pub skipped_new_files: usize,
82 pub indexed_symbols: usize,
83}
84
85#[cfg(test)]
87mod tests;