I’m using a langchain script in order to make a similarity search of a query embedding in an embedding’s MongoDb collection but I want to pre filter the documents to search only in the documents that are $in an objectId array.
// Get the list of embeddings _ids to preFilter
const documentData = await documentCollection.findOne(
{ "_id": documentId },
{ "embededings": 1 }
)
const documentEmbeddingsId = documentData.embeddings
// Embed query
const query = "What is this document about?"
const embeddings = new OpenAIEmbeddings({
modelName:"XXX",
openAIApiKey: "XXX"
})
const embeddedQuery = await embeddings.embedQuery(query)
// Similarity search
const vectorStore = new MongoDBAtlasVectorSearch(embeddings, {
collection,
indexName: "XXX",
textKey: "XXX",
embeddingKey: "XXX",
});
const preFilter = {
preFilter: {
_id: {
$in: objIds
},
},
}
const storingResponse = await vectorStore.similaritySearchVectorWithScore(embeddedQuery,4,preFilter)
Running this code returns this error:
‘Error: MongoServerError: Operand type is not supported for $vectorSearch: objectId’.
Is the error in the preFilter? Or is this type of filter not supported by mongodb? Any ideas on how I can make this search?