Skip to content

Commit

Permalink
docs: Add FAISS Filter with Advanced Query Operators Documentation & …
Browse files Browse the repository at this point in the history
…Demonstration (#28938)

## Description
This pull request updates the documentation for FAISS regarding filter
construction, following the changes made in commit `df5008f`.

## Issue
None. This is a follow-up PR for documentation of
[#28207](#28207)

## Dependencies:
None.

---------

Co-authored-by: Chester Curme <[email protected]>
  • Loading branch information
RuofanChen03 and ccurme authored Jan 2, 2025
1 parent ba9dfd9 commit 5c32307
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/docs/integrations/vectorstores/faiss.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,52 @@
" print(f\"* {res.page_content} [{res.metadata}]\")"
]
},
{
"cell_type": "markdown",
"id": "39cb1496",
"metadata": {},
"source": [
"Some [MongoDB query and projection operators](https://www.mongodb.com/docs/manual/reference/operator/query/) are supported for more advanced metadata filtering. The current list of supported operators are as follows:\n",
"- `$eq` (equals)\n",
"- `$neq` (not equals)\n",
"- `$gt` (greater than)\n",
"- `$lt` (less than)\n",
"- `$gte` (greater than or equal)\n",
"- `$lte` (less than or equal)\n",
"- `$in` (membership in list)\n",
"- `$nin` (not in list)\n",
"- `$and` (all conditions must match)\n",
"- `$or` (any condition must match)\n",
"- `$not` (negation of condition)\n",
"\n",
"Performing the same above similarity search with advanced metadata filtering can be done as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b3dd99d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Building an exciting new project with LangChain - come check it out! [{'source': 'tweet'}]\n",
"* LangGraph is the best framework for building stateful, agentic applications! [{'source': 'tweet'}]\n"
]
}
],
"source": [
"results = vector_store.similarity_search(\n",
" \"LangChain provides abstractions to make working with LLMs easy\",\n",
" k=2,\n",
" filter={\"source\": {\"$eq\": \"tweet\"}},\n",
")\n",
"for res in results:\n",
" print(f\"* {res.page_content} [{res.metadata}]\")"
]
},
{
"cell_type": "markdown",
"id": "5ae35069",
Expand Down
43 changes: 43 additions & 0 deletions docs/docs/integrations/vectorstores/faiss_async.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,49 @@
" print(f\"Content: {doc.page_content}, Metadata: {doc.metadata}\")"
]
},
{
"cell_type": "markdown",
"id": "8dead085",
"metadata": {},
"source": [
"Some [MongoDB query and projection operators](https://www.mongodb.com/docs/manual/reference/operator/query/) are supported for more advanced metadata filtering. The current list of supported operators are as follows:\n",
"- `$eq` (equals)\n",
"- `$neq` (not equals)\n",
"- `$gt` (greater than)\n",
"- `$lt` (less than)\n",
"- `$gte` (greater than or equal)\n",
"- `$lte` (less than or equal)\n",
"- `$in` (membership in list)\n",
"- `$nin` (not in list)\n",
"- `$and` (all conditions must match)\n",
"- `$or` (any condition must match)\n",
"- `$not` (negation of condition)\n",
"\n",
"Performing the same above similarity search with advanced metadata filtering can be done as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af47c6f9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Content: foo, Metadata: {'page': 1}\n"
]
}
],
"source": [
"results = await db.asimilarity_search(\n",
" \"foo\", filter={\"page\": {\"$eq\": 1}}, k=1, fetch_k=4\n",
")\n",
"for doc in results:\n",
" print(f\"Content: {doc.page_content}, Metadata: {doc.metadata}\")"
]
},
{
"cell_type": "markdown",
"id": "1becca53",
Expand Down

0 comments on commit 5c32307

Please sign in to comment.