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:
contentof type “Text”. This is used to store theDocument.pageContentvalues.embeddingof 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.metadataobject. For example, if in theDocument.metadataobject you have atitleproperty, you can create atitlecolumn 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
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.