This notebook shows how to use PineconeRerank for two-stage vector retrieval reranking using Pinecone’s hosted reranking API as demonstrated in langchain_pinecone/libs/pinecone/rerank.py
.
Setup
Install thelangchain-pinecone
package.
Credentials
Set your Pinecone API key to use the reranking API.Instantiation
UsePineconeRerank
to rerank a list of documents by relevance to a query.
Usage
Reranking with Top-N
Specifytop_n
to limit the number of returned documents.
Reranking with Custom Rank Fields
If your documents are dictionaries or have custom fields, userank_fields
to specify the field to rank on.
Reranking with Additional Parameters
You can pass model-specific parameters (e.g.,truncate
) directly to .rerank()
.
How to handle inputs longer than those supported by the model. Accepted values: END or NONE.
END truncates the input sequence at the input token limit. NONE returns an error when the input exceeds the input token limit.
Use within a chain
API reference
PineconeRerank(model, top_n, rank_fields, return_documents)
.rerank(documents, query, rank_fields=None, model=None, top_n=None, truncate="END")
.compress_documents(documents, query)
(returnsDocument
objects withrelevance_score
in metadata)