Helmet
Helmet14mo ago

How do vectorstores work on Convex with Langchain?

I am making a chatbot of sorts with retrieval QA on langchain using Convex's vectorstore. I'm storing documents embedded in Convex, but wondering how I can access multiple vectorstores by name? Currently in schema.ts, I have a basic schema example for a simple vector db.
export default defineSchema({
documents: defineTable({
embedding: v.array(v.number()),
text: v.string(),
metadata: v.any(),
}).vectorIndex("byEmbedding", {
vectorField: "embedding",
dimensions: 1536,
})
},
{
strictTableNameTypes: false,
});
export default defineSchema({
documents: defineTable({
embedding: v.array(v.number()),
text: v.string(),
metadata: v.any(),
}).vectorIndex("byEmbedding", {
vectorField: "embedding",
dimensions: 1536,
})
},
{
strictTableNameTypes: false,
});
I'm wondering how I can make more vector dbs than just one named "documents", ie, for multiple users where each user might have their own vectdb with their name. Currently accessing the vector db in langchain through new ConvexVectorStore(new OpenAIEmbeddings({ openAIApiKey: secretKey }), { ctx });, and I don't see anywhere to pass in string names of the vector db to use or if I wanted to create a new vector db with a specific name. Curious how I might be able to achieve this?
7 Replies
ian
ian14mo ago
Each vector index is on a table. If you want to separate vector stores by user, you can add a filterField and then filter by that user.
ian
ian14mo ago
Here's an article on using Vector search with Langchain and Convex: https://stack.convex.dev/ai-chat-using-langchain-and-convex
Build AI Chat with LangChain and Convex
In this second post in our series, we’ll build an AI-powered chat interface using LangChain and its new Convex integration.
ian
ian14mo ago
There's some other ones in the series if you want to build a fully custom RAG application
Helmet
HelmetOP14mo ago
With langchain though, I'm not sure how to filter it because usage is as follows:
// Get the vectorstore as a retriever
const vectorstore = new ConvexVectorStore(new OpenAIEmbeddings({ openAIApiKey: secretKey }), { ctx }, );
const retriever = vectorstore.asRetriever();
// Get the vectorstore as a retriever
const vectorstore = new ConvexVectorStore(new OpenAIEmbeddings({ openAIApiKey: secretKey }), { ctx }, );
const retriever = vectorstore.asRetriever();
Additionally how can I create filter fields for multiple users? It seems convex is limited to 16 fields as well, so I'm not sure I can create a vector store for each user
ian
ian14mo ago
the field would be the userid, so every user could be filtered with one field. @Michal Srb may be more familiar with filtering in LangChain
Michal Srb
Michal Srb13mo ago
Hey @Helmet: - If you do have different tables, you can configure ConvexVectorStore to read from a different table - Don't use LangChain if you want to filter by another field (see https://stack.convex.dev/ai-chat-with-convex-vector-search instead) - To filter for multiple users, you can run multiple vector search reads, one for each user.
Build AI Chat with Convex Vector Search
Convex is a full-stack development platform and cloud database, including built-in vector search. In this third post in our [series](https://stack.con...
ian
ian13mo ago
And see here for how to use q.or to search for many users with one search: https://docs.convex.dev/vector-search#filter-expressions
Vector Search | Convex Developer Hub
Run vector search queries on embeddings

Did you find this page helpful?