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, C++, Java, C#, F#, PowerShell, Scala, Ruby, Bash, HCL, Kotlin, Swift, Objective-C, SQL, Protobuf, GraphQL, PHP, Lua, Zig, R, YAML, TOML, Elixir, Erlang, Gleam, Haskell, Julia, OCaml, CSS, Perl, HTML, JSON, XML, INI, Nix, Make, LaTeX, Solidity, CUDA, GLSL, Svelte, Razor, VB.NET, Vue, ASP.NET Web Forms, Markdown (51 languages)
  • GPU acceleration: CUDA/TensorRT with CPU fallback
  • CLI tools: Call graph, impact analysis, test mapping, dead code detection
  • Document conversion: PDF, HTML, CHM, Web Help → cleaned Markdown (optional convert feature)

§Quick Start

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

// 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 (hybrid RRF search)
let query_embedding = embedder.embed_query("parse configuration file")?;
let filter = SearchFilter {
    enable_rrf: true,
    query_text: "parse configuration file".to_string(),
    ..Default::default()
};
let results = store.search_filtered(&query_embedding, &filter, 5, 0.3)?;

Re-exports§

pub use drift::detect_drift;
pub use drift::DriftEntry;
pub use drift::DriftResult;
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 reranker::Reranker;
pub use store::ModelInfo;
pub use store::SearchFilter;
pub use store::Store;

Modules§

audit
Audit mode for excluding notes from search/read
ci
CI pipeline analysis — composable diff review + dead code + gate logic.
config
Configuration file support for cqs
convert
Document-to-Markdown conversion pipeline.
drift
Drift detection — find functions that changed semantically between snapshots
embedder
Embedding generation with ort + tokenizers
health
Health check — codebase quality snapshot
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
reranker
Cross-encoder re-ranking for second-pass scoring
store
SQLite storage for chunks, embeddings, and call graph data.
suggest
Suggest — auto-detect note-worthy patterns in the codebase

Structs§

CallContext
Call graph context for enriching NL descriptions.
CallerDetail
Direct caller with display-ready fields (call-site context + snippet).
ChangedFunction
A function identified as changed by a diff
DiffEntry
A single diff entry
DiffHunk
A single hunk from a unified diff — one changed region in one file
DiffImpactResult
Aggregated impact result from a diff
DiffImpactSummary
Summary counts for diff impact
DiffResult
Result of a semantic diff
DiffTestInfo
A test affected by diff changes, tracking which changed function leads to it
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.
FunctionRisk
Per-function risk assessment from impact analysis.
GatherOptions
Options for gather operation
GatherResult
Result of a gather operation
GatheredChunk
A gathered code chunk with context
ImpactResult
Complete impact analysis result
LocalPatterns
Local code patterns extracted from existing chunks in the target file/module.
OnboardEntry
A code entry in the reading list.
OnboardResult
Result of an onboard analysis — ordered reading list for understanding a concept.
OnboardSummary
Summary statistics for the onboard result.
PlacementOptions
Options for customizing placement suggestion behavior.
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.
ResolvedTarget
Result of resolving a target name to a concrete chunk.
ReviewNoteEntry
A note relevant to the review.
ReviewResult
Result of a comprehensive diff review.
RiskScore
Risk assessment for a single function.
ScoutChunk
A chunk in the scout result with hints
ScoutOptions
Options for customizing scout behavior.
ScoutResult
Complete scout result
ScoutSummary
Summary counts
TaskResult
Complete task analysis result.
TaskSummary
Summary statistics for a task result.
TestEntry
Test that exercises the entry point.
TestInfo
Affected test with call depth
TestSuggestion
A suggested test for an untested caller
TransitiveCaller
Transitive caller at a given depth
TypeImpacted
A function impacted via shared type dependencies (one-hop type expansion).
TypeInfo
Type dependency of the entry point.

Enums§

AnalysisError
Unified error type for analysis operations (scout, where-to-add, etc.)
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
RiskLevel
Risk level for a function based on caller count and test coverage.

Constants§

DEFAULT_MAX_EXPANDED_NODES
Default maximum nodes in BFS expansion to prevent blowup on hub functions.
DEFAULT_MAX_TEST_SEARCH_DEPTH
Default maximum depth for test search BFS. Exposed via max_test_depth parameters on analysis functions.
DEFAULT_ONBOARD_DEPTH
Default callee BFS expansion depth.
DEFAULT_PLACEMENT_SEARCH_LIMIT
Default search result limit for placement suggestions.
DEFAULT_PLACEMENT_SEARCH_THRESHOLD
Default minimum search score threshold for placement suggestions.
DEFAULT_SCOUT_SEARCH_LIMIT
Default number of search results for scout.
DEFAULT_SCOUT_SEARCH_THRESHOLD
Default minimum search score threshold for scout.
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).

Statics§

COMMON_TYPES
Standard library types to exclude from type-edge analysis.

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.
compute_risk_and_tests
Compute risk scores and collect deduplicated tests in a single pass.
compute_risk_batch
Compute risk scores for a batch of function names.
diff_impact_to_json
Serialize diff impact result to JSON
enumerate_files
Enumerate files to index in a project directory.
extract_modify_targets
Extract modify target names from scout results.
find_hotspots
Find the most-called functions in the codebase (hotspots).
find_related
Find functions related to target_name by co-occurrence.
gather
Gather relevant code chunks for a query.
gather_cross_index
Cross-index gather: seed from a reference index, bridge into project code, BFS expand.
gather_cross_index_with_index
Like gather_cross_index but accepts an optional HNSW index for O(log n) bridge searches instead of brute-force scans per reference seed.
gather_with_graph
Like gather but accepts a pre-loaded call graph.
generate_nl_description
Generate natural language description from chunk metadata.
generate_nl_with_call_context
Generate NL description enriched with call graph context.
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)
is_test_chunk
Unified test-chunk detection heuristic.
map_hunks_to_functions
Map diff hunks to function names using the index.
normalize_for_fts
Normalize code text for FTS5 indexing.
normalize_path
Normalize a path to a string with forward slashes.
normalize_slashes
Normalize backslashes to forward slashes in a string path.
onboard
Produce a guided tour of a concept in the codebase.
onboard_to_json
Convert OnboardResult to JSON.
parse_target
Parse a target string into (optional_file_filter, function_name).
parse_unified_diff
Parse unified diff output into hunks.
rel_display
Relativize a path against a root and normalize separators for display.
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 ResolvedTarget.
review_diff
Analyze a unified diff and produce a comprehensive review.
scout
Run scout analysis for a task description.
scout_to_json
Serialize scout result to JSON
scout_with_options
Run scout analysis with configurable search parameters.
search_across_projects
Search across all registered projects
semantic_diff
Run a semantic diff between two stores.
serialize_path_normalized
Serde serializer for PathBuf fields: forward-slash normalized.
suggest_placement
Suggest where to place new code matching a description.
suggest_placement_with_options
Suggest where to place new code matching a description with configurable search parameters.
suggest_tests
Suggest tests for untested callers in an impact result.
task
Produce complete implementation context for a task description.
task_to_json
Serialize task result to JSON.
task_with_resources
Like task but accepts pre-loaded call graph and test chunks.
temp_suffix
Generate an unpredictable u64 suffix for temporary file names.