Rerank documents according to their relevance to a query using Pinecone's hosted reranking models.
Arguments
- model
The reranking model to use. Available models include: - "pinecone-rerank-v0" See Pinecone documentation for the full list of available models.
- query
The query string to rank documents against.
- documents
A character vector of documents to rerank, or a list of named lists where each contains a "text" field (and optionally an "id" field).
- top_n
The number of top results to return. Default is to return all documents.
- return_documents
Whether to include the document text in the response. Default is TRUE.
- tidy
Whether to return a tidy tibble format (default: TRUE).
Value
List with http response, content (reranked results), and status_code. When tidy = TRUE, content is a tibble with columns: - index: original position of the document - score: relevance score (higher is more relevant) - document: the document text (if return_documents = TRUE)
Examples
if (FALSE) { # \dontrun{
# Rerank search results
documents <- c(
"The quick brown fox jumps over the lazy dog",
"A fast auburn fox leaps above a sleepy canine",
"The weather is nice today"
)
result <- rerank(
model = "pinecone-rerank-v0",
query = "What did the fox do?",
documents = documents,
top_n = 2
)
# View reranked results
result$content
# Rerank with document IDs
docs_with_ids <- list(
list(id = "doc1", text = "The quick brown fox jumps over the lazy dog"),
list(id = "doc2", text = "A fast auburn fox leaps above a sleepy canine"),
list(id = "doc3", text = "The weather is nice today")
)
result <- rerank(
model = "pinecone-rerank-v0",
query = "What did the fox do?",
documents = docs_with_ids
)
} # }