VoyageAIRerank#

class langchain_voyageai.rerank.VoyageAIRerank[source]#

Bases: BaseDocumentCompressor

Document compressor that uses VoyageAI Rerank API.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param aclient: voyageai.AsyncClient = None#

VoyageAI clients to use for compressing documents.

param client: voyageai.Client = None#
param model: str [Required]#

Model to use for reranking.

param top_k: int | None = None#

Number of documents to return.

param truncation: bool = True#
param voyage_api_key: SecretStr | None = None#

VoyageAI API key. Must be specified directly or via environment variable VOYAGE_API_KEY.

async acompress_documents(documents: Sequence[Document], query: str, callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None) → Sequence[Document][source]#

Compress documents using VoyageAI’s rerank API.

Parameters:
  • documents (Sequence[Document]) – A sequence of documents to compress.

  • query (str) – The query to use for compressing the documents.

  • callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None) – Callbacks to run during the compression process.

Returns:

A sequence of compressed documents in relevance_score order.

Return type:

Sequence[Document]

compress_documents(documents: Sequence[Document], query: str, callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None = None) → Sequence[Document][source]#

Compress documents using VoyageAI’s rerank API.

Parameters:
  • documents (Sequence[Document]) – A sequence of documents to compress.

  • query (str) – The query to use for compressing the documents.

  • callbacks (list[BaseCallbackHandler] | BaseCallbackManager | None) – Callbacks to run during the compression process.

Returns:

A sequence of compressed documents in relevance_score order.

Return type:

Sequence[Document]