Docs /Templates/ sinapsis-llama-index

LLaMAIndexReranker

sinapsis-llama-indexLlamaIndexembeddingshuggingfacellamaindexquery

Python template · sinapsis_llama_index.templates.llama_index_reranker

Overview

Rerank retrieved LLM contexts with LlamaIndex's `SentenceTransformerRerank`.

This template expects contexts to already be present in `LLMConversationPacket.contexts`, typically from `LLaMAIndexNodeRetriever`. It reranks the contexts using the packet's current `content` as the query and writes the reranked contexts back into the same packet.

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-llama-index==1.0.0
uv pip install sinapsis-llama-index==1.0.0
uv add sinapsis-llama-index==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
rerank_config

Configuration for the sentence-transformer reranker.

SentenceTransformerRerankConfig
Optional
Default: null
model

Cross-encoder model used for reranking. Defaults to `"cross-encoder/stsb-distilroberta-base"`.

str
Optional
Default: "cross-encoder/stsb-distilroberta-base"
top_n

Number of reranked candidates to keep. Defaults to `2`.

int
Optional
Default: 2
device

Device used by the reranker. If `"auto"`, it resolves to `"cuda"` when available, otherwise `"cpu"`. Defaults to `"auto"`.

typing.Literal['auto', 'cuda', 'cpu']
Optional
Default: "auto"
trust_remote_code

Allow execution of remote code for custom models. Defaults to `True`.

bool
Optional
Default: true
keep_retrieval_score

Whether to preserve the original retrieval score in metadata. Defaults to `False`.

bool
Optional
Default: false
rerank_categoriesRequired

Context categories that should be reranked.

list[typing.Literal['rag', 'memory', 'document', 'instruction', 'other']]
Required
Default: null

Configuration example

Example from the Python docstring:

yaml
agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: LLaMAIndexReranker
  class_name: LLaMAIndexReranker
  template_input: InputTemplate
  attributes:
    rerank_config:
      model: "cross-encoder/stsb-distilroberta-base"
      top_n: 2
      device: cpu
    rerank_categories: ["rag", "document"]
Show schema-based configuration skeleton
yaml
templates:
  - template_name: "LLaMAIndexReranker"
    class_name: "LLaMAIndexReranker"
    attributes:
      rerank_config:
        model: "cross-encoder/stsb-distilroberta-base"
        top_n: 2
        device: "auto"
        trust_remote_code: true
        keep_retrieval_score: false
      rerank_categories: "<required>"

Inheritance

Immediate parent: sinapsis_core.template_base.template.Template

Environment variables

Environment definitions belong to their canonical Python modules.

No directly related environment variables listed.