Knowledge Base
A knowledge base is a batteries-included RAG system that you can create and insert data into, as well as query as if it was a table.
Internally, it uses a vector store and an embedding model. By default, it uses the ChromaDB vector store and the OpenAI embedding model. However, you can define a vector store and an embedding model as you see fit.
Syntax
Here is a general syntax for creating a knowledge base:
Where the following parameters are optional:
model
can store an embedding model.storage
can store a table from a vector database.metadata_columns
can list columns to store metadata (if not set, there are no metadata columns).content_columns
can list columns to store content (if not set, all columns are content).id_column
can list a column to store a unique identitifier, which isid
by default.
Example
Let’s look at an step-by-step example of how to define a knowledge base.
Here is how you build a knowledge base specifying the embedding model and the vector store.
Create an embedding model for the knowledge base using OpenAI or LangChain as an engine.
Create a connection to the vector store.
This example uses the world_news_with_ids
table that contains the id
and content
columns.
Create an index in the vector store and insert one example point.
Query the vector store:
Create a knowledge base using all components defined above.
Here is how you can automate adding content to this knowledge base every time new data becomes available:
The LAST
keyword enables the quey to select only the newly added data. Learn more about the LAST
keyword here.
Query the knowledge base as below.