Skip to main content

Overview

This will help you getting started with the Watsonx document compressor. For detailed documentation of all Watsonx document compressor features and configurations head to the API reference.

Integration details

Setup

To access IBM WatsonxAI models you’ll need to create an IBM watsonx.ai account, get an API key or any other type of credentials, and install the @langchain/ibm integration package.

Credentials

Head to IBM Cloud to sign up to IBM watsonx.ai and generate an API key or provide any other authentication form as presented below.

IAM authentication

Bearer token authentication

IBM watsonx.ai software authentication

Once these are placed in your environment variables and object is initialized authentication will proceed automatically. Authentication can also be accomplished by passing these values as parameters to a new instance.

IAM authentication

Bearer token authentication

IBM watsonx.ai software authentication

If you want to get automated tracing from individual queries, you can also set your LangSmith API key by uncommenting below:

Installation

This document compressor lives in the @langchain/ibm package:

Instantiation

Now we can instantiate our compressor:

Usage

First, set up a basic RAG ingest pipeline with embeddings, a text splitter and a vector store. We’ll use this to and rerank some documents regarding the selected query:
Pass selected documents to rerank and receive specific score for each
Or else you could have the documents returned with the result, for that use .compressDocuments() method as below.

API reference

For detailed documentation of all Watsonx document compressor features and configurations head to the API reference.