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.1.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_postprocessor_contextual_rerank-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e410514f30566fec7c3d2841d1c466d0fff821912a38c024e9c4aab072c62dac
MD5 83fac12963a12f939483b27a5a361490
BLAKE2b-256 e1c0160f364d5ef4c74065bcc9ff954b5f38593442881aba42dd95b1d59b4020

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_postprocessor_contextual_rerank-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 578cb736dd4f22ddda50985b93f84936ef10a4e13ff334cefaa6b8df6893683f
MD5 a706087e5db8c63545d9aad1e6530fc1
BLAKE2b-256 9c3111b126161b64caa7fcdb2a6f2523b7cdb71cd2095a9fff44ad5c08294e87

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