vectorsearch by filter fields is not working?
I have following definition of vector index:
.vectorIndex("by_embedding", {
vectorField: "profileEmbedding",
dimensions: 3072,
filterFields: ["user", "isOpenToWork", "geo", "summary", "headline"]
})
In my app I am using following filtering:
const searchResults: SearchResult[] = await ctx.vectorSearch("linkedInProfiles", "by_embedding", {
vector: embedding,
limit: 16,
filter: (q) => q.eq("user", user._id) && q.eq("isOpenToWork", args.isOpenToWork ?? false)
});
And for some reason the results never filter by user. The data is fine, the types are fine ((property) _id: GenericId<"users">)
How to enable filtering by multiple firlds as AND and how to make sure the user will get only his records?
2 Replies
Please format your code correctly. This helps us investigate your problem. https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51#syntax-highlighting
@Marcin
https://docs.convex.dev/search/vector-search#filter-expressions
filter doesn't support AND currently - only OR. You can filter after retrieving results.
Vector Search | Convex Developer Hub
Run vector search queries on embeddings