VolcengineRerank#
- class langchain_community.document_compressors.volcengine_rerank.VolcengineRerank[source]#
Bases:
BaseDocumentCompressor
Document compressor that uses Volcengine 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 ak: str | None = None#
Access Key ID. https://www.volcengine.com/docs/84313/1254553
- param client: Any = None#
Volcengine client to use for compressing documents.
- param host: str = 'cn-beijing'#
- param region: str = 'api-vikingdb.volces.com'#
- param sk: str | None = None#
Secret Access Key. https://www.volcengine.com/docs/84313/1254553
- param top_n: int | None = 3#
Number of documents to return.
- async acompress_documents(documents: Sequence[Document], query: str, callbacks: List[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] #
Async compress retrieved documents given the query context.
- Parameters:
documents (Sequence[Document]) β The retrieved documents.
query (str) β The query context.
callbacks (List[BaseCallbackHandler] | BaseCallbackManager | None) β Optional callbacks to run during compression.
- Returns:
The compressed documents.
- Return type:
Sequence[Document]
- compress_documents(documents: Sequence[Document], query: str, callbacks: List[BaseCallbackHandler] | BaseCallbackManager | None = None) Sequence[Document] [source]#
Compress documents using Volcengineβ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.
- Return type:
Sequence[Document]
- rerank(documents: Sequence[str | Document | dict], query: str, *, top_n: int | None = -1) List[Dict[str, Any]] [source]#
Returns an ordered list of documents ordered by their relevance to the provided query.
- Parameters:
query (str) β The query to use for reranking.
documents (Sequence[str | Document | dict]) β A sequence of documents to rerank.
top_n (int | None) β The number of results to return. If None returns all results. Defaults to self.top_n.
- Return type:
List[Dict[str, Any]]
Examples using VolcengineRerank