Skip to content
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

docs: Add FAISS Filter with Advanced Query Operators Documentation & Demonstration #28938

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
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
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
Loading