Skip to content

Commit 5c32307

Browse files
RuofanChen03ccurme
andauthored
docs: Add FAISS Filter with Advanced Query Operators Documentation & 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]>
1 parent ba9dfd9 commit 5c32307

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

docs/docs/integrations/vectorstores/faiss.ipynb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,52 @@
286286
" print(f\"* {res.page_content} [{res.metadata}]\")"
287287
]
288288
},
289+
{
290+
"cell_type": "markdown",
291+
"id": "39cb1496",
292+
"metadata": {},
293+
"source": [
294+
"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",
295+
"- `$eq` (equals)\n",
296+
"- `$neq` (not equals)\n",
297+
"- `$gt` (greater than)\n",
298+
"- `$lt` (less than)\n",
299+
"- `$gte` (greater than or equal)\n",
300+
"- `$lte` (less than or equal)\n",
301+
"- `$in` (membership in list)\n",
302+
"- `$nin` (not in list)\n",
303+
"- `$and` (all conditions must match)\n",
304+
"- `$or` (any condition must match)\n",
305+
"- `$not` (negation of condition)\n",
306+
"\n",
307+
"Performing the same above similarity search with advanced metadata filtering can be done as follows:"
308+
]
309+
},
310+
{
311+
"cell_type": "code",
312+
"execution_count": null,
313+
"id": "1b3dd99d",
314+
"metadata": {},
315+
"outputs": [
316+
{
317+
"name": "stdout",
318+
"output_type": "stream",
319+
"text": [
320+
"* Building an exciting new project with LangChain - come check it out! [{'source': 'tweet'}]\n",
321+
"* LangGraph is the best framework for building stateful, agentic applications! [{'source': 'tweet'}]\n"
322+
]
323+
}
324+
],
325+
"source": [
326+
"results = vector_store.similarity_search(\n",
327+
" \"LangChain provides abstractions to make working with LLMs easy\",\n",
328+
" k=2,\n",
329+
" filter={\"source\": {\"$eq\": \"tweet\"}},\n",
330+
")\n",
331+
"for res in results:\n",
332+
" print(f\"* {res.page_content} [{res.metadata}]\")"
333+
]
334+
},
289335
{
290336
"cell_type": "markdown",
291337
"id": "5ae35069",

docs/docs/integrations/vectorstores/faiss_async.ipynb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,49 @@
397397
" print(f\"Content: {doc.page_content}, Metadata: {doc.metadata}\")"
398398
]
399399
},
400+
{
401+
"cell_type": "markdown",
402+
"id": "8dead085",
403+
"metadata": {},
404+
"source": [
405+
"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",
406+
"- `$eq` (equals)\n",
407+
"- `$neq` (not equals)\n",
408+
"- `$gt` (greater than)\n",
409+
"- `$lt` (less than)\n",
410+
"- `$gte` (greater than or equal)\n",
411+
"- `$lte` (less than or equal)\n",
412+
"- `$in` (membership in list)\n",
413+
"- `$nin` (not in list)\n",
414+
"- `$and` (all conditions must match)\n",
415+
"- `$or` (any condition must match)\n",
416+
"- `$not` (negation of condition)\n",
417+
"\n",
418+
"Performing the same above similarity search with advanced metadata filtering can be done as follows:"
419+
]
420+
},
421+
{
422+
"cell_type": "code",
423+
"execution_count": null,
424+
"id": "af47c6f9",
425+
"metadata": {},
426+
"outputs": [
427+
{
428+
"name": "stdout",
429+
"output_type": "stream",
430+
"text": [
431+
"Content: foo, Metadata: {'page': 1}\n"
432+
]
433+
}
434+
],
435+
"source": [
436+
"results = await db.asimilarity_search(\n",
437+
" \"foo\", filter={\"page\": {\"$eq\": 1}}, k=1, fetch_k=4\n",
438+
")\n",
439+
"for doc in results:\n",
440+
" print(f\"Content: {doc.page_content}, Metadata: {doc.metadata}\")"
441+
]
442+
},
400443
{
401444
"cell_type": "markdown",
402445
"id": "1becca53",

0 commit comments

Comments
 (0)