Skip to main content

llama-index postprocessor contextual rerank integration

Project description

Contextual Reranker

This is a Llama_index package that calls Contextual's /rerank endpoint. It will rank a list of documents according to their relevance to a query.

The total request cannot exceed 400,000 tokens. The combined length of any document, instruction and the query must not exceed 4,000 tokens. Email rerank-feedback@contextual.ai with any feedback or questions.

Usage

from llama_index.postprocessor.contextual_rerank import ContextualRerank
from llama_index.core.schema import NodeWithScore, TextNode

nodes = [
    NodeWithScore(node=TextNode(text="the capital of france is paris")),
    NodeWithScore(
        node=TextNode(text="the capital of the United States is Washington DC")
    ),
]

query = "What is the capital of France?"

contextual_rerank = ContextualRerank(
    api_key="key-...",
    model="ctxl-rerank-en-v1-instruct",
    top_n=2,
)

response = contextual_rerank.postprocess_nodes(nodes, query_str=query)

for node in response:
    print(node)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file llama_index_postprocessor_contextual_rerank-0.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_postprocessor_contextual_rerank-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e35d91b11c93e719c8ad784020591ff18e6aa3a7ed918a3f9a8fac7e07c5f05b
MD5 54dea6ad2372b3fcefafb569d03fd95c
BLAKE2b-256 9bb721314ae0ce50bd459f2117b85b68da0e1b2b0de2753e411ad01f508d4a4e

See more details on using hashes here.

File details

Details for the file llama_index_postprocessor_contextual_rerank-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_postprocessor_contextual_rerank-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc01d615eb3ed2bbdbffeddae263202390a283f671e3b3455d2158229cb3e8dc
MD5 1a0368d1f9fd6983716e8f1ed47a741d
BLAKE2b-256 f653094cdcfd685f5f657cb15fad0c7f2b86ac302d9dbed370458314713fa922

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page