The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docs: Add FAISS Filter with Advanced Query Operators Documentation & Demonstration (#28938)
RuofanChen035c32307a7aaf
diff --git a/docs/docs/integrations/vectorstores/faiss.ipynb b/docs/docs/integrations/vectorstores/faiss.ipynbindex 0f95759906..26520baa6a 100644--- a/docs/docs/integrations/vectorstores/faiss.ipynb+++ b/docs/docs/integrations/vectorstores/faiss.ipynb@@ -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",diff --git a/docs/docs/integrations/vectorstores/faiss_async.ipynb b/docs/docs/integrations/vectorstores/faiss_async.ipynbindex e3bd1c9030..ec16f9e4d1 100644--- a/docs/docs/integrations/vectorstores/faiss_async.ipynb+++ b/docs/docs/integrations/vectorstores/faiss_async.ipynb@@ -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",