#How do vectorstores work on Convex with Langchain?

9 messages · Page 1 of 1 (latest)

teal saddle
#

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,
});

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?

ember lotus
#

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.

#

There's some other ones in the series if you want to build a fully custom RAG application

teal saddle
#

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();
#

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

ember lotus
#

the field would be the userid, so every user could be filtered with one field. @covert dew may be more familiar with filtering in LangChain

covert dew
#

Hey @teal saddle:

  • 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.

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...

ember lotus