Skip to content

pgvector document filters #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions langchain_postgres/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,41 @@ class PGVector(VectorStore):
* langchain_postgres now accept async connections. If you want to use the async
version, you need to set `async_mode=True` when initializing the store or
use an async engine.

Supported filter operators:

* $eq: Equality operator
* $ne: Not equal operator
* $lt: Less than operator
* $lte: Less than or equal operator
* $gt: Greater than operator
* $gte: Greater than or equal operator
* $in: In operator
* $nin: Not in operator
* $between: Between operator
* $exists: Exists operator
* $like: Like operator
* $ilike: Case insensitive like operator
* $and: Logical AND operator
* $or: Logical OR operator

Example:

.. code-block:: python

vectorstore.similarity_search('kitty', k=10, filter={
'id': {'$in': [1, 5, 2, 9]}
})
#%% md

If you provide a dict with multiple fields, but no operators,
the top level will be interpreted as a logical **AND** filter

vectorstore.similarity_search('ducks', k=10, filter={
'id': {'$in': [1, 5, 2, 9]},
'location': {'$in': ["pond", "market"]}
})

"""

def __init__(
Expand Down
Loading