langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.98k stars 14.93k forks source link

AWS DocumentDB similarity search does not work when no filter is used. Error msg: "the match filter must be an expression in an object" #24775

Closed perepc closed 2 months ago

perepc commented 2 months ago

Checked other resources

Example Code

vectorstore = DocumentDBVectorSearch.from_connection_string(
    connection_string=connection_string,
    namespace=namespace,
    embedding=embeddings,
    index_name=INDEX_NAME,
)

# calling similarity_search without filter, makes filter get the default value None and 
docs = vectorstore.similarity_search(query=keyword)

Error Message and Stack Trace (if applicable)

Error message: the match filter must be an expression in an object, full error: {'ok': 0.0, 'code': 15959, 'errmsg': 'the match filter must be an expression in an object', 'operationTime': Timestamp(1722245629, 1)}.

Description

I am trying to use AWS DocumentDB as vector database and when I call similarity_search method from a DocumentDBVectorSearch instance, without filter, only query text, DocumentDB returns an error like: "the match filter must be an expression in an object". This is because None $match expressions are not supported and have to be removed from the pipeline when filter is None.

System Info

langchain==0.2.11 langchain-aws==0.1.6 langchain-cohere==0.1.9 langchain-community==0.2.10 langchain-core==0.2.23 langchain-experimental==0.0.63 langchain-openai==0.1.17 langchain-text-splitters==0.2.2

platform=mac python=3.12.4

ccurme commented 2 months ago

Believe this is resolved in https://github.com/langchain-ai/langchain/pull/24777.