Skip to main content

Crate cqs

Crate cqs 

Source
Expand description

Local semantic search for code using ML embeddings. Find functions by what they do, not just their names.

§Features

  • Semantic search: Uses E5-base-v2 embeddings (769-dim: 768 model + sentiment)
  • Notes with sentiment: Unified memory system for AI collaborators
  • Multi-language: Rust, Python, TypeScript, JavaScript, Go, C, Java, SQL, Markdown
  • GPU acceleration: CUDA/TensorRT with CPU fallback
  • CLI tools: Call graph, impact analysis, test mapping, dead code detection

§Quick Start

use cqs::{Embedder, Parser, Store};

// Initialize components
let parser = Parser::new()?;
let embedder = Embedder::new()?;
let store = Store::open(std::path::Path::new(".cqs/index.db"))?;

// Parse and embed a file
let chunks = parser.parse_file(std::path::Path::new("src/main.rs"))?;
let embeddings = embedder.embed_documents(
    &chunks.iter().map(|c| c.content.as_str()).collect::<Vec<_>>()
)?;

// Search for similar code
let query_embedding = embedder.embed_query("parse configuration file")?;
let results = store.search(&query_embedding, 5, 0.3)?;

Re-exports§

pub use audit::parse_duration;
pub use embedder::Embedder;
pub use embedder::Embedding;
pub use hnsw::HnswIndex;
pub use index::IndexResult;
pub use index::VectorIndex;
pub use note::parse_notes;
pub use note::path_matches_mention;
pub use note::rewrite_notes_file;
pub use note::NoteEntry;
pub use note::NoteError;
pub use note::NoteFile;
pub use note::NOTES_HEADER;
pub use parser::Chunk;
pub use parser::Parser;
pub use store::ModelInfo;
pub use store::SearchFilter;
pub use store::Store;

Modules§

audit
Audit mode for excluding notes from search/read
config
Configuration file support for cqs
diff_parse
Unified diff parser for cqs impact-diff
embedder
Embedding generation with ort + tokenizers
hnsw
HNSW (Hierarchical Navigable Small World) index for fast vector search
index
Vector index trait for nearest neighbor search
language
Language registry for code parsing
note
Note parsing and types
parser
Code parsing with tree-sitter
reference
Reference index support for multi-index search
store
SQLite storage for chunks and embeddings (sqlx async with sync wrappers)

Structs§

ChangedFunction
A function identified as changed by a diff
DiffImpactResult
Aggregated impact result from a diff
DiffResult
Result of a semantic diff
FileGroup
A file group in the scout result
FileSuggestion
Suggestion for where to place new code
FunctionHints
Lightweight caller + test coverage hints for a function.
GatherOptions
Options for gather operation
ImpactResult
Complete impact analysis result
LocalPatterns
Local patterns observed in a file
PlacementResult
Result from placement analysis
ProjectRegistry
Global registry of indexed cqs projects
RelatedFunction
A function related to the target with overlap count.
RelatedResult
Result of co-occurrence analysis for a target function.
ScoutChunk
A chunk in the scout result with hints
ScoutResult
Complete scout result
ScoutSummary
Summary counts
TestSuggestion
A suggested test for an untested caller

Enums§

ChunkRole
Role classification for chunks in scout results
GatherDirection
Direction of call graph expansion
NlTemplate
Template variants for NL description generation.
Pattern
Known structural patterns

Constants§

EMBEDDING_DIM
Embedding dimension: 768 from E5-base-v2 model + 1 sentiment dimension. Single source of truth — all modules import this constant.
INDEX_DIR
Name of the per-project index directory (created by cqs init).

Functions§

analyze_diff_impact
Run impact analysis across all changed functions from a diff.
analyze_impact
Run impact analysis: find callers, affected tests, and transitive callers.
compute_hints
Compute caller count and test count for a single function.
compute_hints_with_graph
Core implementation — accepts pre-loaded graph and test chunks.
diff_impact_to_json
Serialize diff impact result to JSON
enumerate_files
Enumerate files to index in a project directory.
extract_type_names
Extract non-standard type names from a function signature.
find_related
Find functions related to target_name by co-occurrence.
gather
Gather relevant code chunks for a query
generate_nl_description
Generate natural language description from chunk metadata.
generate_nl_with_template
Generate NL description using a specific template variant.
impact_to_json
Serialize impact result to JSON, relativizing paths against the project root
impact_to_mermaid
Generate a mermaid diagram from impact result
index_notes
Index notes into the database (embed and store)
map_hunks_to_functions
Map diff hunks to function names using the index.
normalize_for_fts
Normalize code text for FTS5 indexing.
parse_target
Parse a target string into (optional_file_filter, function_name).
resolve_index_dir
Resolve the index directory for a project, migrating from .cq/ to .cqs/ if needed.
resolve_target
Resolve a target string to a ChunkSummary.
scout
Run scout analysis for a task description.
scout_to_json
Serialize scout result to JSON
search_across_projects
Search across all registered projects
semantic_diff
Run a semantic diff between two stores
strip_unc_prefix
No-op on non-Windows platforms
suggest_placement
Suggest where to place new code matching a description.
suggest_tests
Suggest tests for untested callers in an impact result.