codenib.model
¶
Model module for CodeNib.
Modules:
| Name | Description |
|---|---|
agentless_pipeline |
|
bm25_retrieve_pipeline |
|
dense_graph_expand_rerank_pipeline |
|
embedding_retrieve_pipeline |
|
graph_augmented_rerank_pipeline |
|
graph_retrieve_pipeline |
|
hybrid_retrieve_pipeline |
Cascade-style hybrid retrieval: BM25 → embedding rerank (no agent loop). |
retrieval_planner |
Query- and budget-aware retrieval path planner. |
retrieve_rerank_pipeline |
|
Classes:
| Name | Description |
|---|---|
AgentlessPipeline |
The Agentless approach from the `"Agentless: Demystifying LLM-based |
BM25RetrievePipeline |
BM25-only retrieval pipeline. |
DenseGraphExpandRerankPipeline |
Dense-first graph expansion retrieval pipeline. |
EmbeddingRetrievePipeline |
Embedding-only retrieval pipeline. |
GraphAugmentedRerankPipeline |
Compatibility alias for :class: |
GraphRetrievePipeline |
Compatibility alias for :class: |
SparseSeededGraphRetrievePipeline |
Sparse-seeded graph-first retrieval pipeline. |
HybridRetrievePipeline |
Two-stage cascade retrieval: BM25 → embedding rerank. |
GraphExpansionPlan |
Graph expansion controls for structural retrieval paths. |
RetrievalBudget |
Coarse retrieval budget used for path selection. |
RetrievalCapabilities |
Backends that a planner may use for this pipeline instance. |
RetrievalPathPlan |
Concrete path selected for a query. |
RetrievalPlanner |
Select one of CodeNib's retrieval paths for a query and budget. |
RetrievalStagePlan |
Declarative retrieval branch selected by the planner. |
RetrieveRerankPipeline |
Composable code retrieval pipeline built from retrieval + rerank ops. |
RetrieveStageConfig |
Declarative configuration for an individual retrieval branch. |
Functions:
| Name | Description |
|---|---|
build_retrieve_plan |
Convenience helper for common retrieval plan presets. |
AgentlessPipeline
¶
AgentlessPipeline(
repo_path: str,
repo_commit: str,
llm_model: str = "gpt-4o",
llm_temperature: float = 0.0,
llm_max_tokens: int = 2048,
top_n_files: int = 3,
languages: list[str] | None = None,
cache_dir: str | None = None,
instance_id: str | None = None,
)
The Agentless approach from the "Agentless: Demystifying LLM-based
Software Engineering Agents" <https://arxiv.org/abs/2407.01489>_ paper.
:class:~codenib.model.AgentlessPipeline localizes code locations that
need modification by employing a simplistic three-phase process:
Phase 1 - File Localization: Identifies relevant files using repository structure and LLM reasoning:
.. math:: \mathcal{F} = \text{LLM}(\text{problem}, \text{structure}(\mathcal{R}))
where :math:\mathcal{R} is the repository and :math:\mathcal{F} is the
set of candidate files.
TODO: add dense retrieval to the file localization phase¶
Phase 2 - Node Localization: Narrows down to specific code entities (functions, classes, methods) within the identified files:
.. math:: \mathcal{N} = \text{LLM}(\text{problem}, {\text{structure}(f) \mid f \in \mathcal{F}})
where :math:\mathcal{N} is the set of candidate nodes (symbols).
Phase 3 - Node Refinement: Validates and refines the final set of nodes using full code content:
.. math:: \mathcal{N}^* = \text{LLM}(\text{problem}, {\text{content}(n) \mid n \in \mathcal{N}})
where :math:\mathcal{N}^* is the refined set of nodes requiring changes.
The localization results can be used for downstream tasks such as automated
program repair, code synthesis, or interactive code editing via
:meth:~codenib.model.AgentlessPipeline.query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the repository to analyze. |
required |
repo_commit
|
str
|
Git commit hash for version identification. |
required |
llm_model
|
str
|
Full litellm model identifier
(e.g., |
'gpt-4o'
|
llm_temperature
|
float
|
Temperature for LLM sampling.
(default: :obj: |
0.0
|
llm_max_tokens
|
int
|
Maximum tokens for LLM responses.
(default: :obj: |
2048
|
top_n_files
|
int
|
Number of top files to consider in Stage 1.
(default: :obj: |
3
|
languages
|
list[str]
|
Programming languages to index.
If set to :obj: |
None
|
cache_dir
|
str
|
Directory for caching SCIP indices and graphs.
If set to :obj: |
None
|
instance_id
|
str
|
Instance identifier for organizing cache.
If provided, uses :obj: |
None
|
Source code in codenib/model/agentless_pipeline.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
BM25RetrievePipeline
¶
BM25RetrievePipeline(
repo_path: str,
index_path: str,
*,
top_k: int = 50,
project_name: str | None = None,
language: str = "python",
languages: list[str] | None = None,
graph_route: str = "active"
)
BM25-only retrieval pipeline.
Builds a code graph via SCIP indexing, then retrieves top-K nodes using BM25 sparse search. Useful as a baseline to isolate whether poor graph retrieval performance is due to bad BM25 seeds or bad graph expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Repository root to index. |
required |
index_path
|
str
|
Directory used for SCIP index caches. |
required |
top_k
|
int
|
Number of results to retrieve (default: 50). |
50
|
project_name
|
str | None
|
Project name for SCIP indexing; defaults to index_path basename. |
None
|
language
|
str
|
Backward-compatible single graph-indexing language. |
'python'
|
languages
|
list[str] | None
|
Graph-indexing languages. When provided, overrides
|
None
|
graph_route
|
str
|
|
'active'
|
Methods:
| Name | Description |
|---|---|
query |
Retrieve top-K nodes using BM25 sparse search. |
close |
Release pipeline resources. |
Source code in codenib/model/bm25_retrieve_pipeline.py
query
¶
query(query: str, top_k: int | None = None) -> list[QueriedNode]
Retrieve top-K nodes using BM25 sparse search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query (e.g., problem statement). |
required |
top_k
|
int | None
|
Number of results; overrides the instance default if provided. |
None
|
Returns:
| Type | Description |
|---|---|
list[QueriedNode]
|
List of QueriedNode sorted by BM25 score. |
Source code in codenib/model/bm25_retrieve_pipeline.py
DenseGraphExpandRerankPipeline
¶
DenseGraphExpandRerankPipeline(
retriever: EmbeddingRetrievePipeline,
code_graph: CodeGraph | None = None,
*,
rerank_context: RerankContext | None = None,
repo_path: str | None = None,
dense_top_k: int = 20,
graph_seed_top_k: int | None = None,
graph_neighbors_per_seed: int = 5,
graph_direction: str = "both",
graph_edge_types: Sequence[str] | None = (EDGE_TYPE_REFERENCE,),
graph_fusion_weight: float = 0.0,
graph_fusion_rrf_k: int = 60,
final_top_k: int = 10,
candidate_top_k: int | None = None,
candidate_filters: Sequence[CandidatePredicate] | None = None,
include_graph_content: bool = True,
graph_symbol_only: bool = True,
graph_require_span: bool = True,
close_retriever: bool = False
)
Dense-first graph expansion retrieval pipeline.
Stage 1: retrieve dense top-K candidates from the full vector index. Stage 2: append one-hop graph neighbors for those dense candidates. Stage 3: optionally filter and deduplicate the combined candidate set. Stage 4: optionally rerank only the assembled candidates.
This pipeline is intended for the "embedding baseline plus graph
augmentation" experiment family. It is intentionally different from
:class:SparseSeededGraphRetrievePipeline, which uses sparse/BM25 seeds and
ranks inside the graph-expanded set.
Methods:
| Name | Description |
|---|---|
load_index |
Hot-swap the backing dense retrieval index. |
load_graph |
Hot-swap the graph used for neighbor expansion. |
query |
Retrieve dense candidates, append graph neighbors, dedup, and rerank. |
close |
Release owned resources. |
Source code in codenib/model/dense_graph_expand_rerank_pipeline.py
load_index
¶
load_graph
¶
load_graph(code_graph: CodeGraph | None, *, repo_path: str | None = None) -> None
Hot-swap the graph used for neighbor expansion.
Source code in codenib/model/dense_graph_expand_rerank_pipeline.py
query
¶
query(
query: str,
*,
top_k: int | None = None,
dense_top_k: int | None = None,
profiler: Profiler | None = None
) -> list[QueriedNode]
Retrieve dense candidates, append graph neighbors, dedup, and rerank.
Source code in codenib/model/dense_graph_expand_rerank_pipeline.py
EmbeddingRetrievePipeline
¶
EmbeddingRetrievePipeline(
repo_path: str | None = None,
index_path: str | None = None,
*,
embedding_model: str = "nomic-ai/CodeRankEmbed",
embedding_provider: str = "huggingface",
embedding_dimension: int = 768,
languages: list[str] | None = None,
max_lines_per_chunk: int = 300,
top_k: int = 50,
embedding_kwargs: dict | None = None,
force_rebuild: bool = False,
index_type: str = "flat",
ivf_nlist: int = 100,
ivf_nprobe: int = 8
)
Embedding-only retrieval pipeline.
Typical single-instance usage (loads or builds index immediately)::
pipeline = EmbeddingRetrievePipeline(
repo_path=repo_path,
index_path=index_path,
embedding_model="Qwen/Qwen3-Embedding-0.6B",
embedding_dimension=1024,
)
results = pipeline.query(problem_statement)
pipeline.close()
Multi-instance / hot-swap usage (load model once, swap index per instance)::
pipeline = EmbeddingRetrievePipeline(
embedding_model="Qwen/Qwen3-Embedding-0.6B",
embedding_dimension=1024,
)
for instance in dataset:
pipeline.load_index(index_path_for_instance)
results = pipeline.query(instance["problem_statement"])
pipeline.close()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str | None
|
Repository root to index. Only required when
|
None
|
index_path
|
str | None
|
Directory used for vector index caches. When |
None
|
embedding_model
|
str
|
Embedding model name. |
'nomic-ai/CodeRankEmbed'
|
embedding_provider
|
str
|
Embedding provider ( |
'huggingface'
|
embedding_dimension
|
int
|
Embedding vector dimension. |
768
|
languages
|
list[str] | None
|
Languages to chunk for indexing (default: |
None
|
max_lines_per_chunk
|
int
|
Maximum lines per chunk. |
300
|
top_k
|
int
|
Default number of results to retrieve. |
50
|
embedding_kwargs
|
dict | None
|
Extra kwargs forwarded to the embedding wrapper. |
None
|
force_rebuild
|
bool
|
Re-chunk and re-embed even if a cached index exists. |
False
|
Methods:
| Name | Description |
|---|---|
load_index |
Hot-swap the FAISS index without reloading the embedding model. |
query |
Retrieve top-K nodes using embedding similarity search. |
close |
Release all resources including the embedding model. |
Source code in codenib/model/embedding_retrieve_pipeline.py
load_index
¶
Hot-swap the FAISS index without reloading the embedding model.
Frees the current index and loads the pre-built index at index_path.
The embedding model stays in memory, so this is much faster than
creating a new :class:EmbeddingRetrievePipeline for each instance.
Source code in codenib/model/embedding_retrieve_pipeline.py
query
¶
query(query: str, top_k: int | None = None) -> list[QueriedNode]
Retrieve top-K nodes using embedding similarity search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query (e.g., problem statement). |
required |
top_k
|
int | None
|
Number of results; overrides the instance default if provided. |
None
|
Returns:
| Type | Description |
|---|---|
list[QueriedNode]
|
List of QueriedNode sorted by similarity score. |
Source code in codenib/model/embedding_retrieve_pipeline.py
close
¶
Release all resources including the embedding model.
GraphAugmentedRerankPipeline
¶
GraphAugmentedRerankPipeline(
retriever: EmbeddingRetrievePipeline,
code_graph: CodeGraph | None = None,
*,
rerank_context: RerankContext | None = None,
repo_path: str | None = None,
dense_top_k: int = 20,
graph_seed_top_k: int | None = None,
graph_neighbors_per_seed: int = 5,
graph_direction: str = "both",
graph_edge_types: Sequence[str] | None = (EDGE_TYPE_REFERENCE,),
graph_fusion_weight: float = 0.0,
graph_fusion_rrf_k: int = 60,
final_top_k: int = 10,
candidate_top_k: int | None = None,
candidate_filters: Sequence[CandidatePredicate] | None = None,
include_graph_content: bool = True,
graph_symbol_only: bool = True,
graph_require_span: bool = True,
close_retriever: bool = False
)
Bases: DenseGraphExpandRerankPipeline
Compatibility alias for :class:DenseGraphExpandRerankPipeline.
The old name was ambiguous: the pipeline is specifically dense-first,
graph-expansion-augmented, then reranked. New code should import
DenseGraphExpandRerankPipeline.
Source code in codenib/model/dense_graph_expand_rerank_pipeline.py
GraphRetrievePipeline
¶
GraphRetrievePipeline(
repo_path: str,
index_path: str,
*,
stage1_topk: int = 5,
stage2_topk: int = 50,
k_hop: int = 2,
use_ppr: bool = False,
ppr_damping: float = 0.85,
use_embedding_rerank: bool = False,
embedding_model: str = "nomic-ai/CodeRankEmbed",
embedding_provider: str = "huggingface",
embedding_dimension: int = 768,
languages: list[str] | None = None,
graph_route: str = "active",
max_lines_per_chunk: int = 300,
project_name: str | None = None,
profiler: Profiler | None = None
)
Bases: SparseSeededGraphRetrievePipeline
Compatibility alias for :class:SparseSeededGraphRetrievePipeline.
Source code in codenib/model/graph_retrieve_pipeline.py
SparseSeededGraphRetrievePipeline
¶
SparseSeededGraphRetrievePipeline(
repo_path: str,
index_path: str,
*,
stage1_topk: int = 5,
stage2_topk: int = 50,
k_hop: int = 2,
use_ppr: bool = False,
ppr_damping: float = 0.85,
use_embedding_rerank: bool = False,
embedding_model: str = "nomic-ai/CodeRankEmbed",
embedding_provider: str = "huggingface",
embedding_dimension: int = 768,
languages: list[str] | None = None,
graph_route: str = "active",
max_lines_per_chunk: int = 300,
project_name: str | None = None,
profiler: Profiler | None = None
)
Sparse-seeded graph-first retrieval pipeline.
Stage 1: BM25 sparse search selects a small set of seed nodes. Stage 2: Graph expansion via k-hop BFS or Personalized PageRank. Stage 3 (optional): Embedding rerank within the expanded set.
This is a graph-first baseline. It should not be used as the direct comparison point for dense embedding retrieval unless that sparse seeding design is the intended ablation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Repository root to index. |
required |
index_path
|
str
|
Directory used for graph and vector index caches. |
required |
stage1_topk
|
int
|
Number of BM25 seed nodes (default: 5). |
5
|
stage2_topk
|
int
|
Max nodes after graph expansion (default: 50). |
50
|
k_hop
|
int
|
BFS expansion depth (default: 2). Ignored when use_ppr=True. |
2
|
use_ppr
|
bool
|
Use Personalized PageRank instead of BFS for Stage 2. |
False
|
ppr_damping
|
float
|
PPR damping factor (default: 0.85). |
0.85
|
use_embedding_rerank
|
bool
|
Enable embedding rerank in Stage 3. |
False
|
embedding_model
|
str
|
Embedding model for Stage 3. |
'nomic-ai/CodeRankEmbed'
|
embedding_provider
|
str
|
Embedding provider for Stage 3. |
'huggingface'
|
embedding_dimension
|
int
|
Embedding vector dimension for Stage 3. |
768
|
languages
|
list[str] | None
|
Languages to index. Multiple entries build per-language graphs and merge them before BM25/graph expansion. The full list is also used for Stage 3 chunking. |
None
|
graph_route
|
str
|
|
'active'
|
max_lines_per_chunk
|
int
|
Maximum lines per chunk. |
300
|
project_name
|
str | None
|
Project name for SCIP indexing; defaults to index_path basename. |
None
|
Methods:
| Name | Description |
|---|---|
query |
Run the three-stage graph retrieval pipeline. |
close |
Release pipeline resources. |
Source code in codenib/model/graph_retrieve_pipeline.py
query
¶
query(query: str, profiler: Profiler | None = None) -> list[QueriedNode]
Run the three-stage graph retrieval pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query (e.g., problem statement). |
required |
profiler
|
Profiler | None
|
Optional profiler. When provided, stages are recorded as
|
None
|
Returns:
| Type | Description |
|---|---|
list[QueriedNode]
|
List of QueriedNode results. |
Source code in codenib/model/graph_retrieve_pipeline.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
HybridRetrievePipeline
¶
HybridRetrievePipeline(
repo_path: str,
*,
index_cache_dir: str | None = None,
stage1_topk: int = 128,
stage2_topk: int = 50,
embedding_model: str = "nomic-ai/CodeRankEmbed",
embedding_dimension: int = 768,
languages: Sequence[str] = ("python",),
embedding_batch_size: int = 8
)
Two-stage cascade retrieval: BM25 → embedding rerank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Repository root to index. |
required |
index_cache_dir
|
str | None
|
Directory for cached indexes (default: |
None
|
stage1_topk
|
int
|
Number of BM25 candidates to retrieve (default: 128). |
128
|
stage2_topk
|
int
|
Final number of results after embedding rerank (default: 50). |
50
|
embedding_model
|
str
|
Embedding model name (default: nomic-ai/CodeRankEmbed). |
'nomic-ai/CodeRankEmbed'
|
embedding_dimension
|
int
|
Embedding vector dimension (default: 768). |
768
|
languages
|
Sequence[str]
|
Languages to index (default: ["python"]). |
('python',)
|
embedding_batch_size
|
int
|
Batch size for embedding inference (default: 8 to avoid CUDA OOM). |
8
|
Example
pipeline = HybridRetrievePipeline( ... repo_path="/path/to/repo", ... index_cache_dir="~/.codenib/cache", ... ) results = pipeline.query("how to parse CSV files", top_k=10) for node in results[:5]: ... print(f"{node.file}:{node.node_name} (score={node.score:.3f})")
Methods:
| Name | Description |
|---|---|
query |
Run cascade retrieval: BM25 → embedding rerank. |
close |
Release pipeline resources. |
Source code in codenib/model/hybrid_retrieve_pipeline.py
query
¶
query(query: str, top_k: int | None = None) -> list[QueriedNode]
Run cascade retrieval: BM25 → embedding rerank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query (e.g., problem statement). |
required |
top_k
|
int | None
|
Number of final results (overrides stage2_topk if provided). |
None
|
Returns:
| Type | Description |
|---|---|
list[QueriedNode]
|
List of QueriedNode sorted by embedding similarity (descending). |
Source code in codenib/model/hybrid_retrieve_pipeline.py
GraphExpansionPlan
dataclass
¶
GraphExpansionPlan(
seed_engine: str = "sparse",
seed_top_k: int = 8,
expand_top_k: int = 80,
hops: int = 2,
direction: str = "both",
use_ppr: bool = False,
)
Graph expansion controls for structural retrieval paths.
RetrievalBudget
dataclass
¶
RetrievalBudget(
tier: str = "balanced",
retrieve_top_k: int = 100,
rerank_candidate_top_k: int | None = 50,
allow_graph: bool = True,
allow_rerank: bool = True,
allow_llm_rerank: bool = False,
prefer_rrf: bool = True,
)
Coarse retrieval budget used for path selection.
RetrievalCapabilities
dataclass
¶
RetrievalCapabilities(
has_dense: bool = True,
has_sparse: bool = True,
has_graph: bool = False,
has_embedding_rerank: bool = True,
has_llm_rerank: bool = False,
)
Backends that a planner may use for this pipeline instance.
RetrievalPathPlan
dataclass
¶
RetrievalPathPlan(
name: str,
intent: str,
stages: tuple[RetrievalStagePlan, ...],
retrieval_top_k: int,
fusion: str = "weighted",
enable_rerank: bool = False,
rerank_strategy: str | None = None,
rerank_candidate_top_k: int | None = None,
graph: GraphExpansionPlan | None = None,
rationale: str = "",
)
Concrete path selected for a query.
RetrievalPlanner
¶
Select one of CodeNib's retrieval paths for a query and budget.
Methods:
| Name | Description |
|---|---|
normalize_budget |
Return a validated budget object from a preset name or custom budget. |
classify_query |
Classify a query into lexical, semantic, and structural signals. |
select |
Select a concrete retrieval path for query under budget. |
normalize_budget
¶
normalize_budget(budget: BudgetInput = 'balanced') -> RetrievalBudget
Return a validated budget object from a preset name or custom budget.
Source code in codenib/model/retrieval_planner.py
classify_query
¶
Classify a query into lexical, semantic, and structural signals.
Source code in codenib/model/retrieval_planner.py
select
¶
select(
query: str,
budget: BudgetInput = "balanced",
capabilities: RetrievalCapabilities | None = None,
) -> RetrievalPathPlan
Select a concrete retrieval path for query under budget.
Source code in codenib/model/retrieval_planner.py
RetrievalStagePlan
dataclass
¶
RetrievalStagePlan(
engine: str,
weight: float = 1.0,
top_k: int | None = None,
params: dict[str, object] = dict(),
)
Declarative retrieval branch selected by the planner.
RetrieveRerankPipeline
¶
RetrieveRerankPipeline(
repo_path: str,
index_path: str,
*,
retrieval_plan: Sequence[RetrieveStageConfig] | None = None,
retrieval_mode: str = "dense",
retrieval_level: str = "l2",
planning_budget: BudgetInput = "balanced",
retrieval_planner: RetrievalPlanner | None = None,
planner_capabilities: RetrievalCapabilities | None = None,
code_graph: CodeGraph | None = None,
fusion_strategy: str = "weighted",
rrf_k: int = 60,
embedding_model: str = "nomic-ai/CodeRankEmbed",
embedding_provider: str = "huggingface",
embedding_dimension: int = 768,
embedding_model_kwargs: dict | None = None,
rerank_model: str = "openai/Qwen/Qwen2.5-Coder-7B",
rerank_temperature: float = 0.0,
rerank_max_tokens: int = 2048,
rerank_strategy: str = "llm",
rerank_embedding_model: str | None = None,
rerank_embedding_provider: str | None = None,
rerank_embedding_dimension: int | None = None,
rerank_embedding_model_kwargs: dict | None = None,
rerank_index_metric: str = "ip",
crossencoder_model: str = "Qwen/Qwen3-Reranker-0.6B",
crossencoder_batch_size: int = 8,
languages: list[str] | None = None,
max_lines_per_chunk: int = 100,
sparse_max_k: int = 128,
rerank_window_size: int | None = None,
rerank_window_step: int | None = None,
rerank_listwise_format: str = "structured",
enable_rerank: bool = True,
vector_masks: dict[str, set[str]] | None = None,
rerank_candidate_top_k: int | None = None
)
Composable code retrieval pipeline built from retrieval + rerank ops.
The pipeline wires :mod:codenib.ops.retrieve (sparse/dense/hybrid) with
:mod:codenib.ops.rerank to form a two-stage search baseline. Retrieval
branches are described through :class:RetrieveStageConfig objects, which
can be combined (e.g., hybrid BM25 + embedding) and weighted before
feeding results to an LLM reranker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Repository root to index. |
required |
index_path
|
str
|
Directory used for vector index caches. |
required |
retrieval_plan
|
Sequence[RetrieveStageConfig] | None
|
Optional sequence of :class: |
None
|
retrieval_mode
|
str
|
Shortcut for :func: |
'dense'
|
retrieval_level
|
str
|
Context expansion level, either |
'l2'
|
planning_budget
|
BudgetInput
|
Budget used by automatic retrieval planning. |
'balanced'
|
retrieval_planner
|
RetrievalPlanner | None
|
Planner used when |
None
|
planner_capabilities
|
RetrievalCapabilities | None
|
Optional capability override supplied to the planner. |
None
|
code_graph
|
CodeGraph | None
|
Graph used to expand retrieved code context. |
None
|
fusion_strategy
|
str
|
Strategy used to combine multiple retrieval branches. |
'weighted'
|
rrf_k
|
int
|
Rank constant used by reciprocal-rank fusion. |
60
|
embedding_model
|
str
|
Dense embedding model identifier. |
'nomic-ai/CodeRankEmbed'
|
embedding_provider
|
str
|
Backend serving |
'huggingface'
|
embedding_dimension
|
int
|
Dense vector width. |
768
|
embedding_model_kwargs
|
dict | None
|
Extra keyword arguments for the dense encoder. |
None
|
rerank_model
|
str
|
Reranker model identifier. |
'openai/Qwen/Qwen2.5-Coder-7B'
|
rerank_temperature
|
float
|
Sampling temperature for the LLM reranker. |
0.0
|
rerank_max_tokens
|
int
|
Token budget for a single rerank call. |
2048
|
rerank_strategy
|
str
|
Reranking backend: |
'llm'
|
rerank_embedding_model
|
str | None
|
Model used by embedding-based reranking. |
None
|
rerank_embedding_provider
|
str | None
|
Backend for |
None
|
rerank_embedding_dimension
|
int | None
|
Vector width for embedding-based reranking. |
None
|
rerank_embedding_model_kwargs
|
dict | None
|
Extra keyword arguments for the rerank embedding model. |
None
|
rerank_index_metric
|
str
|
Similarity metric for the rerank vector index. |
'ip'
|
crossencoder_model
|
str
|
Model used by cross-encoder reranking. |
'Qwen/Qwen3-Reranker-0.6B'
|
crossencoder_batch_size
|
int
|
Batch size used by the cross-encoder. |
8
|
languages
|
list[str] | None
|
Languages to chunk for indexing (default: ["python"]). |
None
|
max_lines_per_chunk
|
int
|
Maximum lines per chunk passed to chunker. |
100
|
sparse_max_k
|
int
|
Upper bound for BM25 index fan-out; defaults to 128. |
128
|
rerank_window_size
|
int | None
|
Sliding window width for the reranker (see
:meth: |
None
|
rerank_window_step
|
int | None
|
Stride between consecutive rerank windows. |
None
|
rerank_listwise_format
|
str
|
Output format requested from listwise reranking. |
'structured'
|
enable_rerank
|
bool
|
Whether to apply the configured reranking stage. |
True
|
vector_masks
|
dict[str, set[str]] | None
|
Optional per-language symbol masks for vector retrieval. |
None
|
rerank_candidate_top_k
|
int | None
|
Maximum candidates passed into reranking. |
None
|
Methods:
| Name | Description |
|---|---|
close |
Release model/index resources held by the pipeline. |
query |
Execute retrieve + rerank plan for the provided query. |
Source code in codenib/model/retrieve_rerank_pipeline.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
close
¶
Release model/index resources held by the pipeline.
Source code in codenib/model/retrieve_rerank_pipeline.py
query
¶
query(
query: str, top_k: int = 10, *, budget: BudgetInput | None = None
) -> list[QueriedNode]
Execute retrieve + rerank plan for the provided query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The search query. |
required |
top_k
|
int
|
Number of results to return. If rerank is enabled, this controls the rerank output. Retrieval always fetches RETRIEVAL_TOP_K candidates internally. |
10
|
budget
|
BudgetInput | None
|
Optional per-query planner budget. Only used when a
retrieval planner is configured, including |
None
|
Source code in codenib/model/retrieve_rerank_pipeline.py
RetrieveStageConfig
dataclass
¶
RetrieveStageConfig(
engine: str = "dense",
weight: float = 1.0,
top_k: int | None = None,
params: dict[str, object] = dict(),
)
Declarative configuration for an individual retrieval branch.
build_retrieve_plan
¶
build_retrieve_plan(mode: str = 'dense') -> list[RetrieveStageConfig]
Convenience helper for common retrieval plan presets.
auto returns the dense+sparse preload set used by
:class:RetrievalPlanner; the per-query path is selected at query time.