codenib
¶
Public CodeNib API.
Exports are resolved lazily so importing :mod:codenib or starting the CLI
does not initialize optional graph, embedding, and agent runtimes.
Modules:
| Name | Description |
|---|---|
agent |
Agent package consolidating agent utilities and implementations. |
cli |
User-facing CodeNib command line interface. |
clients |
Third-party agent clients (Claude / Codex SDK) used as end-to-end localization baselines. |
code_chunker |
Code chunking module with both file-level and repository-level functionality. |
code_chunking |
Code chunking module for splitting source code files into semantic chunks. |
compat_pickle |
Read pickles written before the package rename. |
compiler |
Compiler infrastructure for CodeNib. |
dataset |
|
graph |
Graph-related modules for CodeNib. |
index |
Index-related components: sparse, dense, and regex. |
integrations |
Compatibility providers for external coding-agent runtimes. |
languages |
Central language metadata registry. |
llm |
LLM module for CodeNib. |
log_utils |
|
ls_index |
Language-server indexers and decoders. |
ls_router |
Unified language-server router for indexing and decoding across all languages. |
mcp |
CodeNib MCP server - exposes backbone capabilities over stdio. |
model |
Model module for CodeNib. |
ops |
Composable retrieval operators: retrieve, expand, filter, rerank, transform. |
paths |
Canonical filesystem locations owned by CodeNib. |
profiler |
|
repository_filters |
Shared repository traversal policy for user-facing index builders. |
repository_summary |
Extract a concise project purpose from repository README files. |
scip_interface |
Language-specific SCIP indexing and decoding. |
search |
|
source_fingerprint |
Deterministic content identity for repository files visible to CodeNib. |
types |
|
utils |
|
web |
DeepWiki-style demo backend. |
wiki |
Index-derived wiki generation for the DeepWiki-style demo. |
Classes:
| Name | Description |
|---|---|
KeywordExtractor |
Agent for extracting keywords from problem statements. |
RerankAgent |
Agent for reranking code nodes based on query relevance using LLM APIs. |
CodeChunker |
Unified code chunker that supports both file-level and repository-level processing. |
RepoChunkingConfig |
Configuration for repository chunking. |
CodeGraph |
A class to represent and manipulate a code graph using igraph. |
CodeVectorStore |
Vector store for code embeddings using FAISS and sentence-transformers. |
RegexNodeIndex |
In-memory regex-based index for CodeGraph nodes. |
BM25CodeIndexer |
A class that builds a BM25 index from CodeGraph nodes and provides |
LSIndexer |
Unified indexer that delegates to language-specific implementations. |
CodeSearchEngine |
Integrated search engine that combines SCIP indexing, code graph representation, |
Functions:
| Name | Description |
|---|---|
create_code_vector_store |
Factory function to create a CodeVectorStore. |
KeywordExtractor
¶
KeywordExtractor(llm: LiteLLMChat)
Agent for extracting keywords from problem statements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LiteLLMChat
|
A configured LiteLLMChat instance. |
required |
Methods:
| Name | Description |
|---|---|
extract_keywords |
Extract keywords from a problem statement. |
Source code in codenib/agent/extract_agent.py
extract_keywords
¶
extract_keywords(problem_statement: str) -> KeywordExtraction
Extract keywords from a problem statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_statement
|
str
|
The problem statement to extract keywords from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
KeywordExtraction |
KeywordExtraction
|
Structured output with extracted keywords |
Source code in codenib/agent/extract_agent.py
RerankAgent
¶
RerankAgent(
llm: LiteLLMChat, listwise_format: Literal["structured", "rankgpt"] = "structured"
)
Agent for reranking code nodes based on query relevance using LLM APIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LiteLLMChat
|
A configured LiteLLMChat instance. |
required |
listwise_format
|
Literal['structured', 'rankgpt']
|
How to ask the LLM to format the ranking.
|
'structured'
|
Methods:
| Name | Description |
|---|---|
rerank_nodes |
Rerank nodes based on their relevance to the query. |
Source code in codenib/agent/rerank_agent.py
rerank_nodes
¶
rerank_nodes(
query: str,
nodes: list[NodeInfo],
top_k: int | None = None,
window_size: int | None = None,
window_step: int | None = None,
include_content: bool = False,
) -> list[QueriedNode]
Rerank nodes based on their relevance to the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The query to rank nodes against |
required |
nodes
|
list[NodeInfo]
|
List of nodes with content to rank |
required |
top_k
|
int | None
|
Maximum number of results to return (None for all) |
None
|
window_size
|
int | None
|
Number of nodes per rerank window. None -> all nodes. |
None
|
window_step
|
int | None
|
Step size between sliding windows. Defaults to window_size. |
None
|
include_content
|
bool
|
Whether to include node content in the result objects. |
False
|
Returns:
| Type | Description |
|---|---|
list[QueriedNode]
|
List[QueriedNode]: Ranked nodes with relevance scores (optionally with content) |
Notes
When a sliding window is configured, each window is reranked independently and the averaged scores across all windows determine the final ordering.
Source code in codenib/agent/rerank_agent.py
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 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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
CodeChunker
¶
CodeChunker(
language: str = "python",
repo_config: RepoChunkingConfig | None = None,
max_lines_per_chunk: int | None = None,
chunk_depth: int = 2,
include_header_epilogue: bool = False,
l2_level_exclusive: bool = True,
skeleton_mode: bool = False,
include_l2_in_file_skeleton: bool = True,
)
Unified code chunker that supports both file-level and repository-level processing. Maintains backward compatibility with the old API while adding repository functionality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language
|
str
|
Programming language to parse ('python', 'cpp', 'java', etc.) |
'python'
|
repo_config
|
RepoChunkingConfig | None
|
Configuration for repository-level chunking. Uses defaults if None. |
None
|
max_lines_per_chunk
|
int | None
|
Maximum number of lines per emitted chunk. Default: None (no splitting) |
None
|
chunk_depth
|
int
|
Depth of AST traversal (1=top-level only, 2=include methods) |
2
|
include_header_epilogue
|
bool
|
Whether to include file headers and epilogues. Default: False |
False
|
l2_level_exclusive
|
bool
|
When chunk_depth is 2, whether to omit L1 container nodes (classes/structs/impls) and emit only L2 members. Default: True. |
True
|
skeleton_mode
|
bool
|
Emit signature-only skeletons instead of full bodies when True. |
False
|
include_l2_in_file_skeleton
|
bool
|
When chunk_depth is 0, include member signatures in file-level skeletons. Default: True. |
True
|
Methods:
| Name | Description |
|---|---|
chunk_file |
Chunk a code file into function/class level pieces. |
save_chunks_to_json |
Save chunks to a JSON file. |
print_chunk_summary |
Print a summary of the generated chunks. |
chunk_repository |
Chunk all relevant files in a repository. |
get_repository_stats |
Get statistics about the repository without processing files. |
print_repository_summary |
Print a summary of all chunks from the repository. |
chunk_swebench_instance |
Chunk a SWE-bench instance repository. |
save_swebench_chunks |
Save SWE-bench chunking result to JSON file. |
clear_nodes |
Clear the collected nodes list. |
Source code in codenib/code_chunker.py
chunk_file
¶
Chunk a code file into function/class level pieces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the code file to chunk |
required |
relative_path
|
str | None
|
Relative path for node_id generation. If None, uses file_path. |
None
|
skeleton_mode
|
bool | None
|
Override instance-level skeleton setting. When True, chunk content contains signatures only. |
None
|
Returns:
| Type | Description |
|---|---|
|
List of CodeChunk objects |
Source code in codenib/code_chunker.py
save_chunks_to_json
¶
print_chunk_summary
¶
chunk_repository
¶
Chunk all relevant files in a repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the repository root. Languages come from RepoChunkingConfig; when empty they are inferred from file extensions present in the repo. |
required |
Returns:
| Type | Description |
|---|---|
list[CodeChunk]
|
List of CodeChunk objects from all processed files |
Raises:
| Type | Description |
|---|---|
ValueError
|
If repo_path doesn't exist or languages are unsupported |
Source code in codenib/code_chunker.py
get_repository_stats
¶
Get statistics about the repository without processing files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the repository root. Languages come from RepoChunkingConfig; when empty they are inferred. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing repository statistics |
Source code in codenib/code_chunker.py
print_repository_summary
¶
Print a summary of all chunks from the repository.
Source code in codenib/code_chunker.py
chunk_swebench_instance
¶
chunk_swebench_instance(
instance: dict[str, Any],
cache_dir: str | None = None,
languages: list[str] | None = None,
) -> dict[str, Any]
Chunk a SWE-bench instance repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
dict[str, Any]
|
SWE-bench instance dictionary containing repo, base_commit, instance_id, etc. |
required |
cache_dir
|
str | None
|
Directory to cache repositories. Defaults to ~/.codenib |
None
|
languages
|
list[str] | None
|
List of languages to process. If None, uses repository's primary language |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing instance info, repo path, and chunks |
Source code in codenib/code_chunker.py
save_swebench_chunks
¶
Save SWE-bench chunking result to JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
swebench_result
|
dict[str, Any]
|
Result from chunk_swebench_instance() |
required |
output_path
|
str
|
Path to save the JSON file |
required |
Source code in codenib/code_chunker.py
RepoChunkingConfig
dataclass
¶
RepoChunkingConfig(
languages: list[str] = list(),
python_extensions: set[str] | None = None,
cpp_extensions: set[str] | None = None,
csharp_extensions: set[str] | None = None,
rust_extensions: set[str] | None = None,
go_extensions: set[str] | None = None,
java_extensions: set[str] | None = None,
ruby_extensions: set[str] | None = None,
php_extensions: set[str] | None = None,
kotlin_extensions: set[str] | None = None,
swift_extensions: set[str] | None = None,
scala_extensions: set[str] | None = None,
lua_extensions: set[str] | None = None,
javascript_extensions: set[str] | None = None,
typescript_extensions: set[str] | None = None,
ignore_dirs: set[str] = None,
include_dirs: set[str] = None,
ignore_patterns: set[str] = None,
max_file_size_mb: float = 10.0,
filter_tests: bool = True,
skip_minified: bool = True,
minified_line_threshold: int = 10000,
)
Configuration for repository chunking.
Methods:
| Name | Description |
|---|---|
__post_init__ |
Initialize default values. |
__post_init__
¶
Initialize default values.
Source code in codenib/code_chunker.py
CodeGraph
¶
A class to represent and manipulate a code graph using igraph. start_line uses 0-based index.
Methods:
| Name | Description |
|---|---|
add_file_node |
Add a file node to the graph and set it as the current file and scope. |
add_symbol_node |
Add a symbol node to the graph. |
add_symbol_reference |
Add a reference to a symbol. |
update_current_scope |
Update the current scope to the given symbol with its range. |
exit_scopes_by_line |
Exit scopes that have ended based on current line number. |
add_containment_edge |
Add a containment edge from current scope to a symbol. |
batch_edges |
Defer igraph edge insertion until the block exits, flushing all |
build_range_indexes |
Rebuild per-file line-range indexes from current graph state. |
merge_from |
Merge another |
query_range |
Query the graph by source-file line range (LSP-aligned). |
query_range_by_symbol |
Range-query by symbol identity ( |
layers |
Build a multi-graph layer index over this graph. |
layer |
Return one named graph layer view. |
add_root_node |
Add the root node to the graph |
add_directory_node |
Add a directory node to the graph |
save_graph |
Save the graph to a pickle file for fast serialization. |
load_graph |
Load a graph from a pickle file. |
get_graph |
Get the igraph Graph object. |
unified_index |
Readable |
display_name |
Readable label for a canonical name ( |
resolve_symbol |
Map a readable/bare symbol to (canonical_name | None, candidates). |
get_node_info_by_name |
Get information about a node in the graph. |
get_node_info_by_id |
Get information about a node in the graph. |
get_node_content |
Get the content of a node in the graph. |
get_neighbors |
Get the neighbors of a node in the graph. |
get_successors |
Get the successors of a node_name (outgoing edges). |
get_predecessors |
Get the predecessors of a node_name (incoming edges). |
print_graph_basic_info |
Print basic information about the graph. |
visualize_graph |
Visualize the code graph with different colors for different node and edge types. |
Source code in codenib/graph/code_graph.py
add_file_node
¶
Add a file node to the graph and set it as the current file and scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path of the file to add |
required |
Source code in codenib/graph/code_graph.py
add_symbol_node
¶
Add a symbol node to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Symbol name |
required | |
line
|
Line number of the symbol |
required | |
scope_start_line
|
Start line of the symbol's scope (optional) |
None
|
|
scope_end_line
|
End line of the symbol's scope (optional) |
None
|
|
symbol_type
|
Type of symbol (NODE_TYPE_CLASS, NODE_TYPE_METHOD, NODE_TYPE_FUNCTION) (optional) |
None
|
Source code in codenib/graph/code_graph.py
add_symbol_reference
¶
add_symbol_reference(
symbol,
module_path=None,
symbol_type=None,
anchor_file: str | None = None,
anchor_line: int | None = None,
)
Add a reference to a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Symbol being referenced |
required | |
module_path
|
Path of the module containing the symbol (optional) |
None
|
|
symbol_type
|
Type of symbol (NODE_TYPE_CLASS, NODE_TYPE_METHOD, NODE_TYPE_FUNCTION) (optional) |
None
|
|
anchor_file
|
str | None
|
File where the reference site is located (optional) |
None
|
anchor_line
|
int | None
|
0-based line of the reference site (optional) |
None
|
Source code in codenib/graph/code_graph.py
update_current_scope
¶
Update the current scope to the given symbol with its range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Symbol to set as current scope |
required | |
start_line
|
Start line of the symbol's scope |
None
|
|
end_line
|
End line of the symbol's scope |
None
|
Source code in codenib/graph/code_graph.py
exit_scopes_by_line
¶
Exit scopes that have ended based on current line number. File scope (with None range) is never popped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_line
|
Current line number being processed |
required |
Source code in codenib/graph/code_graph.py
add_containment_edge
¶
Add a containment edge from current scope to a symbol.
CONTAIN edges deliberately carry no anchor — containment is a
structural relation, not a call/reference site. (See anchor invariant
ii on query_range.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_symbol
|
Symbol being contained. |
required |
Source code in codenib/graph/code_graph.py
batch_edges
¶
Defer igraph edge insertion until the block exits, flushing all
buffered edges in a single add_edges call.
igraph rebuilds its internal adjacency index on every add_edges
call, so inserting one edge at a time (as bare _add_edge does) is
O(E^2) in the number of edges — the dominant cost when decoding a large
repo. Wrapping a build loop in this context collapses that to O(E):
with graph.batch_edges():
# ... many add_symbol_reference / _add_edge calls ...
Edge dedup is unaffected (the dedup index is updated as edges are
buffered). Edge ids returned by _add_edge while buffering are
provisional and only become real after flush; no caller relies on them
mid-build. Outside this block _add_edge inserts immediately, so the
incremental patcher and all other callers are unchanged. Nesting is a
no-op (the outermost block owns the flush).
Source code in codenib/graph/code_graph.py
build_range_indexes
¶
Rebuild per-file line-range indexes from current graph state.
Call this after the graph is fully constructed by a decoder, and
again after any incremental patcher batch. The two indexes are
pickled with the graph by save_graph, so subsequent load_graph
calls do not need to rebuild.
Cost: O(V + E) — one linear pass over vertices and edges.
Source code in codenib/graph/code_graph.py
merge_from
¶
merge_from(other: CodeGraph) -> None
Merge another CodeGraph into this one.
Vertices are keyed by their canonical name attribute. Existing
vertices receive any attributes from other; missing vertices are
inserted. Edges are copied through _add_edge so structural edge
deduplication and anchored reference multi-edges keep the same
semantics as decoder-built graphs.
Source code in codenib/graph/code_graph.py
query_range
¶
query_range(
file: str,
start_line: int,
end_line: int,
kinds: set | None = None,
depth: int = 1,
*,
layer: str | None = None
) -> RangeQueryResult
Query the graph by source-file line range (LSP-aligned).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
source file (graph-relative path). |
required |
start_line
|
int
|
first line of the inclusive 0-based span. |
required |
end_line
|
int
|
last line of the inclusive 0-based span. |
required |
kinds
|
set | None
|
edge kinds to include in |
None
|
depth
|
int
|
reserved for future multi-hop expansion. Only |
1
|
layer
|
str | None
|
optional named graph layer ( |
None
|
Returns: RangeQueryResult with typed NodeRef/EdgeRef records.
Anchor invariants
(i) anchor_file == source.file (anchor lives at the call site, never the target). (ii) anchor_* is meaningful only on EDGE_TYPE_REFERENCE; CONTAIN edges leave both fields None. (iii) outgoing ∩ incoming = ∅ for any single query (call site and target are in distinct scopes by definition).
Source code in codenib/graph/code_graph.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
query_range_by_symbol
¶
query_range_by_symbol(
name: str, kinds: set | None = None, depth: int = 1, *, layer: str | None = None
) -> RangeQueryResult
Range-query by symbol identity (name).
Resolves name -> vid -> (file, start_line, end_line) and forwards
to query_range. name is the globally-unique identity attribute
(semi-raw SCIP symbol), not the unified_name display.
Returns an empty RangeQueryResult if the symbol is unknown or has no associated file/range (e.g. a SCIP reference-only vertex).
Source code in codenib/graph/code_graph.py
layers
¶
layer
¶
add_root_node
¶
add_directory_node
¶
save_graph
¶
Save the graph to a pickle file for fast serialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path to save the pickle file |
required |
Source code in codenib/graph/code_graph.py
load_graph
classmethod
¶
Load a graph from a pickle file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path to the pickle file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CodeGraph |
Loaded graph instance |
Source code in codenib/graph/code_graph.py
get_graph
¶
unified_index
¶
Readable unified_name (full + bare) -> [canonical names], cached.
Rebuilds from vertex attributes when the persisted _unified_to_names
is empty (older prebuilt graphs ship it empty even though every vertex
carries a unified_name).
Source code in codenib/graph/code_graph.py
display_name
¶
Readable label for a canonical name (unified_name or itself).
resolve_symbol
¶
Map a readable/bare symbol to (canonical_name | None, candidates).
Tries the canonical name first, then the readable unified_name
(full display, then bare token), then a substring match. None when
ambiguous or missing; candidates are readable display names.
Source code in codenib/graph/code_graph.py
get_node_info_by_name
¶
Get information about a node in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
Name of the node |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with vertex attributes or None if not found |
Source code in codenib/graph/code_graph.py
get_node_info_by_id
¶
Get information about a node in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
ID of the node |
required |
Returns:
| Type | Description |
|---|---|
|
Dictionary with vertex attributes or None if not found |
Source code in codenib/graph/code_graph.py
get_node_content
¶
Get the content of a node in the graph. Read the file from start_line to end_line. If the node is a file, return the file content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
ID of the node |
required |
Returns:
| Type | Description |
|---|---|
|
Content of the node or None if not found |
Source code in codenib/graph/code_graph.py
get_neighbors
¶
Get the neighbors of a node in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
Name of the node |
required |
Returns:
| Type | Description |
|---|---|
|
List of neighbor vertex IDs |
Source code in codenib/graph/code_graph.py
get_successors
¶
Get the successors of a node_name (outgoing edges).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
Name of the node |
required | |
edge_types
|
Optional edge types to retain. Typed traversal returns unique neighbors even when the graph contains multi-edges. |
None
|
Returns:
| Type | Description |
|---|---|
|
List of successor vertex IDs |
Source code in codenib/graph/code_graph.py
get_predecessors
¶
Get the predecessors of a node_name (incoming edges).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
Name of the node |
required | |
edge_types
|
Optional edge types to retain. Typed traversal returns unique neighbors even when the graph contains multi-edges. |
None
|
Returns:
| Type | Description |
|---|---|
|
List of predecessor vertex IDs |
Source code in codenib/graph/code_graph.py
print_graph_basic_info
¶
Print basic information about the graph.
Source code in codenib/graph/code_graph.py
visualize_graph
¶
Visualize the code graph with different colors for different node and edge types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path to save the visualization (optional) |
None
|
|
width
|
Width of the plot in pixels |
800
|
|
height
|
Height of the plot in pixels |
600
|
|
layout
|
Layout algorithm to use ('fruchterman_reingold', 'kk', 'grid', etc.) |
'fruchterman_reingold'
|
Returns:
| Type | Description |
|---|---|
|
A matplotlib figure object if output_path is not provided |
Source code in codenib/graph/code_graph.py
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | |
CodeVectorStore
¶
CodeVectorStore(
embedding_model: str = "text-embedding-ada-002",
embedding_provider: str = "openai",
dimension: int = 1536,
index_type: str = "flat",
index_metric: str = "ip",
ivf_nlist: int = 100,
ivf_nprobe: int = 8,
store_path: str | None = None,
profiler: Profiler | None = None,
embedding: Any | None = None,
**embedding_kwargs
)
Vector store for code embeddings using FAISS and sentence-transformers. Provides semantic search capabilities over code chunks.
Supports hierarchical indexing: - L0: File-level skeletons - L2: Function/method-level chunks for fine-grained retrieval (default)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_model
|
str
|
Name of the embedding model to use |
'text-embedding-ada-002'
|
embedding_provider
|
str
|
Provider for embeddings ("openai", "huggingface") |
'openai'
|
dimension
|
int
|
Dimension of the embedding vectors |
1536
|
index_type
|
str
|
FAISS index type — "flat" (exact brute force, default) or "ivf" (IVF inverted-file; approximate, faster at scale). IVF indices are trained lazily on the first batch of vectors. |
'flat'
|
index_metric
|
str
|
Distance metric ("ip" for inner product, "l2" for L2 distance) |
'ip'
|
ivf_nlist
|
int
|
IVF only — number of Voronoi cells (coarse centroids). On
small corpora it is clamped down to the training-set size, since
FAISS k-means needs at least |
100
|
ivf_nprobe
|
int
|
IVF only — cells probed per query; the recall/latency
knob. Clamped to the effective |
8
|
store_path
|
str | None
|
Path to store/load the vector store |
None
|
profiler
|
Profiler | None
|
Optional profiler instance to capture detailed timings |
None
|
embedding
|
Any | None
|
A pre-built embedding wrapper to reuse. When several stores share one model (e.g. one per repo), pass the same instance so the model is loaded onto the GPU only once. |
None
|
**embedding_kwargs
|
Additional arguments for embedding model |
{}
|
Methods:
| Name | Description |
|---|---|
reuse_query_embedding |
Reuse one query vector within a composed request, then discard it. |
clear_query_cache |
Clear the single-query embedding reused by consecutive search stages. |
swap_index |
Hot-swap the FAISS index without reloading the embedding model. |
close |
Release embeddings and FAISS resources to free memory. |
add_code_chunks |
Add code chunks to the vector store. |
add_nodes_with_content |
Add NodeInfo objects (with content) to the vector store. |
search |
Search for similar code chunks using semantic similarity. |
search_with_content |
Search and return results with content included. |
search_within_ids |
Search only within a restricted set of node IDs. |
hierarchical_search |
Note: This method is implemented by Claude and is just for future reference. |
save |
Save the vector store to disk. |
load |
Load the vector store from disk. |
get_stats |
Get statistics about the vector store. |
get_embeddings_by_content_hash |
Extract raw embedding vectors from the FAISS index, keyed by content hash. |
rebuild_from_embeddings |
Clear level and rebuild its FAISS index from pre-computed embeddings. |
delta_update |
Patch the FAISS index in place when the change set is small. |
clear |
Clear data from the vector store. |
Source code in codenib/index/embedding/vector_store.py
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 | |
reuse_query_embedding
¶
Reuse one query vector within a composed request, then discard it.
Source code in codenib/index/embedding/vector_store.py
clear_query_cache
¶
Clear the single-query embedding reused by consecutive search stages.
swap_index
¶
Hot-swap the FAISS index without reloading the embedding model.
Frees the current L0/L2 FAISS indices and documents from memory, then loads a new index from path. The embedding model is left intact so the caller can reuse the same model across many instances.
Source code in codenib/index/embedding/vector_store.py
close
¶
Release embeddings and FAISS resources to free memory.
Source code in codenib/index/embedding/vector_store.py
add_code_chunks
¶
Add code chunks to the vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_chunks
|
list[dict[str, Any]]
|
List of code chunk dictionaries with content and metadata |
required |
level
|
Level
|
Index level to add chunks to ("l0" for file skeletons, "l2" for functions/methods) |
'l2'
|
Source code in codenib/index/embedding/vector_store.py
add_nodes_with_content
¶
add_nodes_with_content(nodes: list[NodeInfo], level: Level = 'l2') -> None
Add NodeInfo objects (with content) to the vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[NodeInfo]
|
List of NodeInfo objects |
required |
level
|
Level
|
Index level to add nodes to ("l0" or "l2") |
'l2'
|
Source code in codenib/index/embedding/vector_store.py
search
¶
search(
query: str,
top_k: int = 10,
score_threshold: float | None = None,
level: Level = "l2",
mask_node_ids: set[str] | None = None,
) -> list[NodeInfo]
Search for similar code chunks using semantic similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query text |
required |
top_k
|
int
|
Number of top results to return |
10
|
score_threshold
|
float | None
|
Minimum similarity score threshold |
None
|
level
|
Level
|
Index level to search ("l0" for file skeletons, "l2" for functions/methods) |
'l2'
|
mask_node_ids
|
set[str] | None
|
Optional set of CodeChunk.node_id values to filter results. |
None
|
Returns:
| Type | Description |
|---|---|
list[NodeInfo]
|
List of NodeInfo objects with scores populated |
Source code in codenib/index/embedding/vector_store.py
search_with_content
¶
search_with_content(
query: str,
top_k: int = 10,
score_threshold: float | None = None,
level: Level = "l2",
mask_node_ids: set[str] | None = None,
) -> list[NodeInfo]
Search and return results with content included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query text |
required |
top_k
|
int
|
Number of top results to return |
10
|
score_threshold
|
float | None
|
Minimum similarity score threshold |
None
|
level
|
Level
|
Index level to search ("l0" for file skeletons, "l2" for functions/methods) |
'l2'
|
mask_node_ids
|
set[str] | None
|
Optional set of CodeChunk.node_id values to filter results. |
None
|
Returns:
| Type | Description |
|---|---|
list[NodeInfo]
|
List of NodeInfo objects with content populated |
Source code in codenib/index/embedding/vector_store.py
search_within_ids
¶
search_within_ids(
query: str, mask_node_ids: set[str], top_k: int = 10, level: Level = "l2"
) -> list[NodeInfo]
Search only within a restricted set of node IDs.
Instead of searching the full FAISS index globally and filtering afterwards, this method restricts the search space before computing similarity. It reconstructs stored vectors for matching documents and computes similarity against the query embedding directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query text. |
required |
mask_node_ids
|
set[str]
|
Set of node_id / node_name values to restrict search to. |
required |
top_k
|
int
|
Number of top results to return. |
10
|
level
|
Level
|
Index level to search. |
'l2'
|
Returns:
| Type | Description |
|---|---|
list[NodeInfo]
|
List of NodeInfo objects sorted by similarity score. |
Source code in codenib/index/embedding/vector_store.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
hierarchical_search
¶
hierarchical_search(
query: str,
l0_top_k: int = 5,
l2_top_k: int = 10,
l0_score_threshold: float | None = None,
l2_score_threshold: float | None = None,
filter_l2_by_l0: bool = True,
) -> dict[str, list[NodeInfo]]
Note: This method is implemented by Claude and is just for future reference. Perform hierarchical search: first L0 (files), then L2 (functions).
This implements a coarse-to-fine retrieval strategy: 1. Search L0 to find relevant files based on their skeletons 2. Search L2 for specific functions/methods 3. Optionally filter L2 results to only include those from L0 files
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query text |
required |
l0_top_k
|
int
|
Number of top L0 results (files) |
5
|
l2_top_k
|
int
|
Number of top L2 results (functions/methods) |
10
|
l0_score_threshold
|
float | None
|
Score threshold for L0 results |
None
|
l2_score_threshold
|
float | None
|
Score threshold for L2 results |
None
|
filter_l2_by_l0
|
bool
|
If True, only return L2 results from files found in L0 |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, list[NodeInfo]]
|
Dict with 'l0' and 'l2' keys containing search results |
Source code in codenib/index/embedding/vector_store.py
save
¶
Save the vector store to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Path to save the store (uses self.store_path if not provided) |
None
|
Source code in codenib/index/embedding/vector_store.py
load
¶
Load the vector store from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Path to load the store from (uses self.store_path if not provided) |
None
|
Source code in codenib/index/embedding/vector_store.py
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | |
get_stats
¶
Get statistics about the vector store.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with store statistics |
Source code in codenib/index/embedding/vector_store.py
get_embeddings_by_content_hash
¶
Extract raw embedding vectors from the FAISS index, keyed by content hash.
This is used to seed the EmbeddingsCache after a full build so that
the first incremental update achieves ~100% cache hit rate for unchanged
chunks.
Each document's content is MD5-hashed to produce the key. If the
document metadata already contains a content_hash field it is used
directly; otherwise the hash is computed on the fly.
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dict mapping content_hash → np.ndarray (float32 vectors). |
Source code in codenib/index/embedding/vector_store.py
rebuild_from_embeddings
¶
Clear level and rebuild its FAISS index from pre-computed embeddings.
Used by the incremental update path: unchanged chunks contribute their cached vectors, so only genuinely new/modified chunks require model inference. No embedding model calls are made by this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
list
|
Document-like objects with |
required |
embeddings
|
list[ndarray]
|
Corresponding embedding vectors as |
required |
level
|
Level
|
Which index level to rebuild ( |
'l2'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If documents and embeddings have different lengths. |
Source code in codenib/index/embedding/vector_store.py
delta_update
¶
delta_update(
all_documents: list,
all_embeddings: list[ndarray],
changed_content_hashes: set[str],
level: Level = "l2",
threshold: float = 0.1,
) -> None
Patch the FAISS index in place when the change set is small.
When the fraction of changed chunks is below threshold, this uses
IndexFlat.remove_ids + add to modify only the affected rows,
keeping unchanged vectors and their aligned documents untouched. If
the change ratio exceeds the threshold (or the index is empty), it
falls back to a full rebuild via :meth:rebuild_from_embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_documents
|
list
|
The complete desired set of documents for level
after the update. Must carry |
required |
all_embeddings
|
list[ndarray]
|
Corresponding embedding vectors, aligned with all_documents. |
required |
changed_content_hashes
|
set[str]
|
Content hashes of chunks that were added, removed, or modified in this update cycle. Used both to decide between delta/rebuild and to identify stale rows. |
required |
level
|
Level
|
Which index level to update. |
'l2'
|
threshold
|
float
|
Maximum change ratio (changed/total) for the delta path; above this a full rebuild is performed. |
0.1
|
Source code in codenib/index/embedding/vector_store.py
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
clear
¶
Clear data from the vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
Level | None
|
If specified, only clear that level ("l0" or "l2"). If None, clear both levels. |
None
|
Source code in codenib/index/embedding/vector_store.py
RegexNodeIndex
¶
RegexNodeIndex(code_graph: CodeGraph)
In-memory regex-based index for CodeGraph nodes. Supports regex pattern matching on node content with glob filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_graph
|
CodeGraph
|
CodeGraph instance containing nodes to index |
required |
Methods:
| Name | Description |
|---|---|
search |
Search for pattern in node content (grep-like functionality). |
Source code in codenib/index/regex_idx/regex_idx.py
search
¶
search(
pattern: str,
file_glob: str | None = None,
node_type: str | None = None,
case_sensitive: bool = False,
use_regex: bool = True,
) -> list[NodeInfo]
Search for pattern in node content (grep-like functionality).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Search pattern (regex or plain string) |
required |
file_glob
|
str | None
|
Optional glob to filter by file path (e.g., '.py', '*/calc.py') |
None
|
node_type
|
str | None
|
Optional node type to filter (e.g., 'function', 'class', 'file') |
None
|
case_sensitive
|
bool
|
Whether search is case-sensitive (default: False) |
False
|
use_regex
|
bool
|
Whether to use regex (default: True) or plain string matching |
True
|
Returns:
| Type | Description |
|---|---|
list[NodeInfo]
|
List of NodeInfo objects matching the pattern |
Examples:
>>> idx.search(r'def\s+\w+', file_glob='*.py') # Find function defs
>>> idx.search('calculator', use_regex=False) # Plain string search
>>> idx.search('class', node_type='file') # Search in file nodes only
Source code in codenib/index/regex_idx/regex_idx.py
BM25CodeIndexer
¶
BM25CodeIndexer(
code_graph=None,
chunks=None,
max_k: int = 15,
language: str = "english",
project_root: str | None = None,
)
A class that builds a BM25 index from CodeGraph nodes and provides search functionality with stemming support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_graph
|
CodeGraph instance containing nodes to index. If provided, the index will be built immediately. |
None
|
|
chunks
|
List of CodeChunk objects to index. If provided, the index will be built immediately. |
None
|
|
max_k
|
int
|
Maximum number of results to return in searches |
15
|
language
|
str
|
Language for stopword removal Default is "english" which works well for processing code tokens as it treats special characters as separators |
'english'
|
project_root
|
str | None
|
Repository root used to resolve relative source paths |
None
|
Methods:
| Name | Description |
|---|---|
build_index_from_graph |
Build a BM25 index from a CodeGraph. |
build_index_from_chunks |
Build a BM25 index from a list of CodeChunk objects. |
search |
Search the index for nodes matching the query. |
search_identifier_occurrences |
Find source chunks that reference an exact code identifier. |
save_index |
Save the index to a directory. |
load_index |
Load the index from a directory. |
Source code in codenib/index/sparse_idx/bm25_index.py
build_index_from_graph
¶
build_index_from_graph(code_graph: CodeGraph) -> BM25Retriever
Build a BM25 index from a CodeGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_graph
|
CodeGraph
|
CodeGraph instance containing nodes to index |
required |
Source code in codenib/index/sparse_idx/bm25_index.py
build_index_from_chunks
¶
build_index_from_chunks(
chunks: list[CodeChunk], *, project_root: str | None = None
) -> BM25Retriever
Build a BM25 index from a list of CodeChunk objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
list[CodeChunk]
|
List of CodeChunk objects (with node_id, chunk_type, name, file, etc.) |
required |
project_root
|
str | None
|
Repository root used to resolve relative source paths |
None
|
Returns:
| Type | Description |
|---|---|
BM25Retriever
|
BM25Retriever instance |
Source code in codenib/index/sparse_idx/bm25_index.py
search
¶
search(
query: str,
top_k: int | None = None,
return_code_content: bool = False,
wrap_with_ln: bool = True,
filter_test: bool = False,
) -> list[NodeInfo]
Search the index for nodes matching the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query |
required |
top_k
|
int | None
|
Number of top results to return (defaults to max_k if not specified) |
None
|
return_code_content
|
bool
|
Whether to include code content in the results |
False
|
wrap_with_ln
|
bool
|
Whether to wrap code content with line numbers |
True
|
filter_test
|
bool
|
Whether to filter out test files from the results |
False
|
Returns:
| Type | Description |
|---|---|
list[NodeInfo]
|
List of NodeInfo objects containing matched nodes with optional content |
Source code in codenib/index/sparse_idx/bm25_index.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
search_identifier_occurrences
¶
search_identifier_occurrences(
identifier: str,
*,
context_query: str | None = None,
top_k: int = 20,
wrap_with_ln: bool = True,
filter_test: bool = False
) -> list[NodeInfo]
Find source chunks that reference an exact code identifier.
BM25 ranks lexical relevance, but it does not guarantee exhaustive exact-symbol coverage. This complementary path scans persisted chunk ranges so a symbol query can return callers/usages without requiring a graph index.
Source code in codenib/index/sparse_idx/bm25_index.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
save_index
¶
Save the index to a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
Path to save the index to |
required |
Source code in codenib/index/sparse_idx/bm25_index.py
load_index
¶
Load the index from a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path
|
str
|
Path to load the index from |
required |
Source code in codenib/index/sparse_idx/bm25_index.py
LSIndexer
¶
LSIndexer(
project_root: str | Path,
output_dir: str | Path | None = None,
exclude_patterns: list | None = None,
profiler: Profiler | None = None,
language: str | None = None,
decoder_backend: str | None = None,
graph_route: str = ACTIVE_GRAPH_ROUTE,
)
Unified indexer that delegates to language-specific implementations.
Methods:
| Name | Description |
|---|---|
graph_patch |
Incrementally update graph using LSP graph-patching. |
Attributes:
| Name | Type | Description |
|---|---|---|
index_quality_report |
Latest backend quality report, when the indexer provides one. |
Source code in codenib/ls_router.py
index_quality_report
property
¶
Latest backend quality report, when the indexer provides one.
graph_patch
¶
graph_patch(graph: CodeGraph, base_commit: str, target_commit: str = 'HEAD') -> dict
Incrementally update graph using LSP graph-patching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
CodeGraph
|
Existing CodeGraph to update in place. |
required |
base_commit
|
str
|
Git commit hash the graph was built from. |
required |
target_commit
|
str
|
Git commit hash to patch to (default HEAD). |
'HEAD'
|
Returns:
| Type | Description |
|---|---|
dict
|
Statistics dict from the patcher. |
Source code in codenib/ls_router.py
CodeSearchEngine
¶
CodeSearchEngine(
repo_path: str,
llm_model: str = "gpt-4o",
llm_temperature: float = 0.0,
llm_max_tokens: int = 8192,
top_k: int = 10,
language: str = "english",
instance_id: str | None = None,
)
Integrated search engine that combines SCIP indexing, code graph representation, BM25 indexing, and keyword extraction to provide context-aware code search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
str
|
Path to the repository to index and search. |
required |
llm_model
|
str
|
Full litellm model identifier for keyword extraction
(e.g., |
'gpt-4o'
|
llm_temperature
|
float
|
Temperature for LLM sampling. |
0.0
|
llm_max_tokens
|
int
|
Maximum tokens for LLM responses. |
8192
|
top_k
|
int
|
Number of top results to return. |
10
|
language
|
str
|
Language for BM25 indexer (default is "english"). |
'english'
|
instance_id
|
str | None
|
Optional instance ID for the dataset. |
None
|
Methods:
| Name | Description |
|---|---|
index_repository |
Index the repository using SCIP and build BM25 index. |
extract_keywords |
Extract keywords from a problem statement. |
search |
Search the repository for code relevant to the problem statement. |
get_code_context |
Get source code context for a search result. |
get_code_context_by_node_name |
Get source code context for a node by its name. |
get_predecessor_nodes |
Get predecessor nodes for a given node name. |
get_rich_result_context |
Enhance a search result with source code context. |
search_with_context |
Search and include source code context in the results. |
Source code in codenib/search.py
index_repository
¶
Index the repository using SCIP and build BM25 index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_name
|
str | None
|
Optional name for the repository |
None
|
instance_id
|
str | None
|
Optional instance ID for the dataset |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if indexing was successful, False otherwise |
Source code in codenib/search.py
extract_keywords
¶
extract_keywords(problem_statement: str) -> KeywordExtraction
Extract keywords from a problem statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_statement
|
str
|
The problem statement to analyze |
required |
Returns:
| Type | Description |
|---|---|
KeywordExtraction
|
KeywordExtraction object containing extracted keywords |
Source code in codenib/search.py
search
¶
Search the repository for code relevant to the problem statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_statement
|
str
|
The problem statement or query |
required |
use_keyword_extraction
|
bool
|
Whether to use keyword extraction. |
True
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of search results with scores and locations |
Source code in codenib/search.py
get_code_context
¶
Get source code context for a search result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
dict[str, Any]
|
A single search result from the search method |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Source code context as a string, or None if not available |
Source code in codenib/search.py
get_code_context_by_node_name
¶
Get source code context for a node by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
str
|
The name of the graph node |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Source code context as a string, or None if not available |
Source code in codenib/search.py
get_predecessor_nodes
¶
Get predecessor nodes for a given node name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
str
|
The name of the graph node |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of predecessor node names |
Source code in codenib/search.py
get_rich_result_context
¶
Enhance a search result with source code context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
dict[str, Any]
|
A single search result from the search method |
required |
context_lines
|
int
|
Number of context lines to include before and after |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Enhanced result with source code context |
Source code in codenib/search.py
search_with_context
¶
search_with_context(
problem_statement: str, context_lines: int = 5, use_keyword_extraction: bool = True
) -> list[dict[str, Any]]
Search and include source code context in the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem_statement
|
str
|
The problem statement or query |
required |
context_lines
|
int
|
Number of context lines to include |
5
|
use_keyword_extraction
|
bool
|
Whether to use keyword extraction |
True
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of search results with code context |
Source code in codenib/search.py
create_code_vector_store
¶
create_code_vector_store(
embedding_model: str = "text-embedding-ada-002",
embedding_provider: str = "openai",
store_path: str | None = None,
**kwargs
) -> CodeVectorStore
Factory function to create a CodeVectorStore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_model
|
str
|
Name of the embedding model |
'text-embedding-ada-002'
|
embedding_provider
|
str
|
Provider for embeddings |
'openai'
|
store_path
|
str | None
|
Path to store/load the vector store |
None
|
**kwargs
|
Additional arguments for CodeVectorStore |
{}
|
Returns:
| Type | Description |
|---|---|
CodeVectorStore
|
CodeVectorStore instance |