Setup
Install the Xata CLI
Create a database to be used as a vector store
In the Xata UI create a new database. You can name it whatever you want, but for this example we’ll uselangchain
.
Create a table, again you can name it anything, but we will use vectors
. Add the following columns via the UI:
content
of type “Text”. This is used to store theDocument.pageContent
values.embedding
of type “Vector”. Use the dimension used by the model you plan to use (1536 for OpenAI).- any other columns you want to use as metadata. They are populated from the
Document.metadata
object. For example, if in theDocument.metadata
object you have atitle
property, you can create atitle
column in the table and it will be populated.
Initialize the project
In your project, run:xata.ts
or xata.js
file that defines the client you can use to interact with the database. See the Xata getting started docs for more details on using the Xata JavaScript/TypeScript SDK.
Usage
npm
Example: Q&A chatbot using OpenAI and Xata as vector store
This example uses theVectorDBQAChain
to search the documents stored in Xata and then pass them as context to the OpenAI model, in order to answer the question asked by the user.
Example: Similarity search with a metadata filter
This example shows how to implement semantic search using LangChain.js and Xata. Before running it, make sure to add anauthor
column of type String to the vectors
table in Xata.
Related
- Vector store conceptual guide
- Vector store how-to guides