Skip to main content

Code

cookbook/11_models/ibm/watsonx/knowledge.py

Usage

1

Set up your virtual environment

2

Set your API key

3

Install dependencies

4

Set up PostgreSQL with pgvector

You need a PostgreSQL database with the pgvector extension installed. Adjust the db_url in the code to match your database configuration.
5

Run Agent

6

For subsequent runs

After the first run, comment out the knowledge_base.load(recreate=True) line to avoid reloading the PDF.
This example shows how to integrate a knowledge base with IBM WatsonX. It loads a PDF from a URL, processes it into a vector database (PostgreSQL with pgvector in this case), and then creates an agent that can query this knowledge base. Note: You need to install several packages (pgvector, pypdf, etc.) and have a PostgreSQL database with the pgvector extension available.