langchain_voyageai.rerank.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 if the input data cannot be parsed to form a valid model.

param aclient: AsyncClient = None

VoyageAI clients to use for compressing documents.

param client: Client = None
param model: str [Required]

Model to use for reranking.

param top_k: Optional[int] = None

Number of documents to return.

param truncation: bool = True
param voyage_api_key: Optional[SecretStr] = None

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

Constraints
  • type = string

  • writeOnly = True

  • format = password

async acompress_documents(documents: Sequence[Document], query: str, callbacks: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = 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 (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – 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: Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]] = 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 (Optional[Union[List[BaseCallbackHandler], BaseCallbackManager]]) – Callbacks to run during the compression process.

Returns

A sequence of compressed documents in relevance_score order.

Return type

Sequence[Document]