codenib.search
¶
Classes:
| Name | Description |
|---|---|
CodeSearchEngine |
Integrated search engine that combines SCIP indexing, code graph representation, |
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 |