community: Fix AWS DocumentDB similarity_search when filter is None (#24777)

**Description**

Fixes DocumentDBVectorSearch similarity_search when no filter is used;
it defaults to None but $match does not accept None, so changed default
to empty {} before pipeline is created.

**Issue**

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

**Dependencies**

No dependencies

**Twitter handle**

https://x.com/perepasamonte

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
Pere Pasamonte 2024-07-29 17:32:05 +02:00 committed by GitHub
parent 7da0597ecb
commit 98175860ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -327,6 +327,10 @@ class DocumentDBVectorSearch(VectorStore):
Returns:
A list of documents closest to the query vector
"""
# $match can't be null, so intializes to {} when None to avoid
# "the match filter must be an expression in an object"
if not filter:
filter = {}
pipeline: List[dict[str, Any]] = [
{"$match": filter},
{