codenib.ops.rerank
¶
Classes:
| Name | Description |
|---|---|
CrossEncoderContext |
Context for cross-encoder reranking. |
RerankContext |
Shared context carrying the rerank agent and configuration. |
Functions:
| Name | Description |
|---|---|
rerank_by_embedding |
Score candidate contents online with an embedding model. |
rerank_by_indexed_embedding |
Rerank candidates using vectors already stored in the search index. |
rerank_by_cross_encoder |
Rerank candidate contents with a shared cross-encoder context. |
CrossEncoderContext
dataclass
¶
Context for cross-encoder reranking.
Wraps either :class:STCrossEncoderWrapper (sentence-transformers
CrossEncoder — mxbai-rerank-, bge-reranker-, jina-reranker-) or
:class:QwenRerankerWrapper (Qwen3-Reranker- yes/no logit scoring).
The underlying wrapper is loaded lazily on first :meth:score call so
that building a CrossEncoderContext at startup costs nothing until the
skill is actually invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
HuggingFace model id (e.g. |
required |
backend
|
str | None
|
|
None
|
batch_size
|
int
|
Scoring batch size forwarded to the wrapper. |
16
|
Methods:
| Name | Description |
|---|---|
score |
Score (query, doc) pairs; higher = more relevant. |
score
¶
RerankContext
dataclass
¶
RerankContext(
llm: LiteLLMChat | None = None,
agent: RerankAgent | None = None,
embedding_store: CodeVectorStore | None = None,
top_k: int | None = None,
candidate_top_k: int | None = None,
window_size: int | None = None,
window_step: int | None = None,
listwise_format: Literal["structured", "rankgpt"] = "structured",
embedding_source: Literal["content", "index"] = "content",
)
Shared context carrying the rerank agent and configuration.
rerank_by_embedding
¶
rerank_by_embedding(
query: str,
candidates: Sequence[QueriedNode],
embedding_store: CodeVectorStore,
*,
top_k: int | None = None
) -> list[QueriedNode]
Score candidate contents online with an embedding model.
This operator intentionally does not search the global vector index. It only re-embeds the provided candidate contents and sorts those candidates by similarity to the query. Use it after retrieval/graph expansion has already assembled the candidate set.
Source code in codenib/ops/rerank.py
rerank_by_indexed_embedding
¶
rerank_by_indexed_embedding(
query: str,
candidates: Sequence[QueriedNode],
embedding_store: CodeVectorStore,
*,
top_k: int | None = None,
level: str = "l2"
) -> list[QueriedNode]
Rerank candidates using vectors already stored in the search index.
Dense-first graph pipelines expand compact graph nodes identified by the
same stable node_id values persisted in the vector store. Reusing those
vectors keeps dense and graph candidates in one calibrated score space and
avoids re-embedding potentially very large source spans online. Candidates
absent from the index are retained at the end in their original order.
Source code in codenib/ops/rerank.py
rerank_by_cross_encoder
¶
rerank_by_cross_encoder(
query: str,
candidates: Sequence[QueriedNode],
context: CrossEncoderContext,
*,
top_k: int | None = None
) -> list[QueriedNode]
Rerank candidate contents with a shared cross-encoder context.