Skip to content

Commit e02d730

Browse files
authored
pgvector document filters (#66)
Document filters in the doc-string for pgvectorstore
1 parent a7d345b commit e02d730

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

langchain_postgres/vectorstores.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,41 @@ class PGVector(VectorStore):
301301
* langchain_postgres now accept async connections. If you want to use the async
302302
version, you need to set `async_mode=True` when initializing the store or
303303
use an async engine.
304+
305+
Supported filter operators:
306+
307+
* $eq: Equality operator
308+
* $ne: Not equal operator
309+
* $lt: Less than operator
310+
* $lte: Less than or equal operator
311+
* $gt: Greater than operator
312+
* $gte: Greater than or equal operator
313+
* $in: In operator
314+
* $nin: Not in operator
315+
* $between: Between operator
316+
* $exists: Exists operator
317+
* $like: Like operator
318+
* $ilike: Case insensitive like operator
319+
* $and: Logical AND operator
320+
* $or: Logical OR operator
321+
322+
Example:
323+
324+
.. code-block:: python
325+
326+
vectorstore.similarity_search('kitty', k=10, filter={
327+
'id': {'$in': [1, 5, 2, 9]}
328+
})
329+
#%% md
330+
331+
If you provide a dict with multiple fields, but no operators,
332+
the top level will be interpreted as a logical **AND** filter
333+
334+
vectorstore.similarity_search('ducks', k=10, filter={
335+
'id': {'$in': [1, 5, 2, 9]},
336+
'location': {'$in': ["pond", "market"]}
337+
})
338+
304339
"""
305340

306341
def __init__(

0 commit comments

Comments
 (0)