diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7a35904..fd39e48 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,8 @@ "GitHub.copilot-chat", "GitHub.vscode-pull-request-github", "eamodio.gitlens", - "ms-toolsai.jupyter" + "ms-toolsai.jupyter", + "ms-python.black-formatter" ] } }, diff --git a/docs/vectorstores.ipynb b/docs/vectorstores.ipynb index 48d3a1b..ff0300f 100644 --- a/docs/vectorstores.ipynb +++ b/docs/vectorstores.ipynb @@ -39,33 +39,44 @@ "name": "stdout", "output_type": "stream", "text": [ - "Requirement already satisfied: langchain-weaviate in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (0.0.1)\n", - "Requirement already satisfied: langchain-core>=0.0.12 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (0.1.1)\n", - "Requirement already satisfied: numpy<2.0.0,>=1.26.2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (1.26.2)\n", - "Requirement already satisfied: simsimd<4.0.0,>=3.6.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (3.6.1)\n", - "Requirement already satisfied: weaviate-client<4.0.0,>=3.25.3 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (3.25.3)\n", + "Requirement already satisfied: langchain-weaviate in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (0.0.1rc1)\n", + "Requirement already satisfied: langchain-core>=0.0.12 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (0.1.16)\n", + "Requirement already satisfied: numpy<2.0.0,>=1.26.2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (1.26.3)\n", + "Requirement already satisfied: simsimd<4.0.0,>=3.6.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (3.7.2)\n", + "Requirement already satisfied: weaviate-client<5.0.0,>=4.0.0b in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-weaviate) (4.4b9)\n", "Requirement already satisfied: PyYAML>=5.3 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (6.0.1)\n", "Requirement already satisfied: anyio<5,>=3 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (4.2.0)\n", "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (1.33)\n", - "Requirement already satisfied: langsmith<0.1.0,>=0.0.63 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (0.0.72)\n", + "Requirement already satisfied: langsmith<0.1,>=0.0.83 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (0.0.84)\n", "Requirement already satisfied: packaging<24.0,>=23.2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (23.2)\n", - "Requirement already satisfied: pydantic<3,>=1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (2.5.2)\n", + "Requirement already satisfied: pydantic<3,>=1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (2.5.3)\n", "Requirement already satisfied: requests<3,>=2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (2.31.0)\n", "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from langchain-core>=0.0.12->langchain-weaviate) (8.2.3)\n", - "Requirement already satisfied: validators<1.0.0,>=0.21.2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<4.0.0,>=3.25.3->langchain-weaviate) (0.22.0)\n", - "Requirement already satisfied: authlib<2.0.0,>=1.2.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<4.0.0,>=3.25.3->langchain-weaviate) (1.3.0)\n", - "Requirement already satisfied: idna>=2.8 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-weaviate) (3.6)\n", - "Requirement already satisfied: sniffio>=1.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from anyio<5,>=3->langchain-core>=0.0.12->langchain-weaviate) (1.3.0)\n", - "Requirement already satisfied: cryptography in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from authlib<2.0.0,>=1.2.1->weaviate-client<4.0.0,>=3.25.3->langchain-weaviate) (41.0.7)\n", + "Requirement already satisfied: httpx==0.26.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (0.26.0)\n", + "Requirement already satisfied: validators==0.22.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (0.22.0)\n", + "Requirement already satisfied: authlib<2.0.0,>=1.2.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.3.0)\n", + "Requirement already satisfied: grpcio<2.0.0,>=1.57.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.60.0)\n", + "Requirement already satisfied: grpcio-tools<2.0.0,>=1.57.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.60.0)\n", + "Requirement already satisfied: grpcio-health-checking<2.0.0,>=1.57.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.60.0)\n", + "Requirement already satisfied: certifi in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from httpx==0.26.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (2023.11.17)\n", + "Requirement already satisfied: httpcore==1.* in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from httpx==0.26.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.0.2)\n", + "Requirement already satisfied: idna in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from httpx==0.26.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (3.6)\n", + "Requirement already satisfied: sniffio in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from httpx==0.26.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.3.0)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from httpcore==1.*->httpx==0.26.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (0.14.0)\n", + "Requirement already satisfied: cryptography in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from authlib<2.0.0,>=1.2.1->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (42.0.1)\n", + "Requirement already satisfied: protobuf>=4.21.6 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from grpcio-health-checking<2.0.0,>=1.57.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (4.25.2)\n", + "Requirement already satisfied: setuptools in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from grpcio-tools<2.0.0,>=1.57.0->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (69.0.3)\n", "Requirement already satisfied: jsonpointer>=1.9 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from jsonpatch<2.0,>=1.33->langchain-core>=0.0.12->langchain-weaviate) (2.4)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-weaviate) (0.6.0)\n", - "Requirement already satisfied: pydantic-core==2.14.5 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-weaviate) (2.14.5)\n", + "Requirement already satisfied: pydantic-core==2.14.6 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-weaviate) (2.14.6)\n", "Requirement already satisfied: typing-extensions>=4.6.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from pydantic<3,>=1->langchain-core>=0.0.12->langchain-weaviate) (4.9.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from requests<3,>=2->langchain-core>=0.0.12->langchain-weaviate) (3.3.2)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from requests<3,>=2->langchain-core>=0.0.12->langchain-weaviate) (2.1.0)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from requests<3,>=2->langchain-core>=0.0.12->langchain-weaviate) (2023.11.17)\n", - "Requirement already satisfied: cffi>=1.12 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from cryptography->authlib<2.0.0,>=1.2.1->weaviate-client<4.0.0,>=3.25.3->langchain-weaviate) (1.16.0)\n", - "Requirement already satisfied: pycparser in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from cffi>=1.12->cryptography->authlib<2.0.0,>=1.2.1->weaviate-client<4.0.0,>=3.25.3->langchain-weaviate) (2.21)\n", + "Requirement already satisfied: cffi>=1.12 in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from cryptography->authlib<2.0.0,>=1.2.1->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (1.16.0)\n", + "Requirement already satisfied: pycparser in /workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages (from cffi>=1.12->cryptography->authlib<2.0.0,>=1.2.1->weaviate-client<5.0.0,>=4.0.0b->langchain-weaviate) (2.21)\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } @@ -130,7 +141,8 @@ "from langchain_community.document_loaders import TextLoader\n", "from langchain_community.embeddings.openai import OpenAIEmbeddings\n", "from langchain.text_splitter import CharacterTextSplitter\n", - "from langchain_weaviate.vectorstores import WeaviateVectorStore" + "from langchain_weaviate.vectorstores import WeaviateVectorStore\n", + "import weaviate" ] }, { @@ -138,9 +150,17 @@ "execution_count": 3, "id": "4618779d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The class `langchain_community.embeddings.openai.OpenAIEmbeddings` was deprecated in langchain-community 0.1.0 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAIEmbeddings`.\n", + " warn_deprecated(\n" + ] + } + ], "source": [ - "\n", "loader = TextLoader(\"state_of_the_union.txt\")\n", "documents = loader.load()\n", "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", @@ -159,15 +179,18 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", - " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n" + " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/weaviate/warnings.py:215: DeprecationWarning: Dep015: You are creating a batch using client.batch or collection.batch, which is deprecated. Use X.batch._batch_mode_().\n", + " warnings.warn(\n" ] } ], "source": [ - "db = WeaviateVectorStore.from_documents(docs, embeddings, weaviate_url=\"http://localhost:8080\", by_text=False)" + "weaviate_client = weaviate.connect_to_local()\n", + "db = WeaviateVectorStore.from_documents(docs, embeddings, client=weaviate_client)" ] }, { @@ -181,28 +204,38 @@ "docs = db.similarity_search(query)" ] }, + { + "cell_type": "markdown", + "id": "ca1134ef", + "metadata": {}, + "source": [ + "To do a search with filters:" + ] + }, { "cell_type": "code", "execution_count": 6, - "id": "e0f10e8a", + "id": "d1210f90", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n", - "\n", - "Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n", - "\n", - "One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n", - "\n", - "And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.\n" - ] - } - ], + "outputs": [], + "source": [ + "search_filter = weaviate.classes.Filter.by_property(\"source\").equal(\"blah.txt\")\n", + "filtered_search_results = db.similarity_search(query, filters=search_filter)\n", + "assert len(filtered_search_results) == 0" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "6e53d7d5", + "metadata": {}, + "outputs": [], "source": [ - "print(docs[0].page_content)" + "search_filter = weaviate.classes.Filter.by_property(\"source\").equal(\n", + " \"state_of_the_union.txt\"\n", + ")\n", + "filtered_search_results = db.similarity_search(query, filters=search_filter, k=3)\n", + "assert len(filtered_search_results) == 3" ] }, { @@ -222,29 +255,11 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "id": "14e00fcb", "metadata": {}, - "outputs": [], "source": [ - "import weaviate\n", - "\n", - "client = weaviate.Client(\n", - " url=WEAVIATE_URL, auth_client_secret=weaviate.AuthApiKey(WEAVIATE_API_KEY)\n", - ")\n", - "\n", - "# client = weaviate.Client(\n", - "# url=WEAVIATE_URL,\n", - "# auth_client_secret=weaviate.AuthClientPassword(\n", - "# username = \"WCS_USERNAME\", # Replace w/ your WCS username\n", - "# password = \"WCS_PASSWORD\", # Replace w/ your WCS password\n", - "# ),\n", - "# )\n", - "\n", - "vectorstore = Weaviate.from_documents(\n", - " documents, embeddings, client=client, by_text=False\n", - ")" + "Read the client [authentication guide](https://weaviate.io/developers/weaviate/client-libraries/python#authentication) for more information." ] }, { @@ -266,24 +281,83 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "b3b4a2f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'_additional': {'vector': [-0.01528927, -0.011489801, -0.01854036, 0.0027386202, 0.008284408, 0.014114177, 0.008101615, -0.0010069896, -0.02222232, -0.0055033537, 0.018892888, 0.0019715454, -0.0044686184, -0.021634774, -0.013787761, -0.0045959204, 0.025734544, 0.018227002, 0.03172752, -0.031361934, -0.010575839, -0.029977936, 0.011548556, 0.0009882208, 0.014545044, -0.020968888, 0.030239068, -0.031805858, 0.013461347, -0.03394714, 0.0027614692, -0.0027190354, -0.024272205, -0.0062018814, -0.019989643, 0.017678626, -0.00012699576, 0.008303992, 0.03410382, -0.027758315, 0.031518612, -0.0009213058, 0.005402165, -0.0024709601, -0.016555758, 0.0066817114, -0.0049941465, -0.035540044, 0.002952422, 0.029560126, 0.032772046, 0.015615685, -0.019911302, -0.02452028, -0.021830622, -0.006391202, -0.010856557, -0.008454143, 0.0029801673, -0.01034735, 0.008800143, 0.014858402, -0.006456485, 0.012012065, 0.017822249, -0.0070832013, -0.015524289, 0.016255457, -0.016085722, 0.016999682, 0.035644498, 0.0030013842, 0.021556433, -0.006789428, 0.04084102, -0.0108435, -0.033320423, 0.0109087825, -0.014662554, -0.021543378, 0.0025558278, -0.015968211, -0.017730853, -0.0040899776, 0.010660708, 0.005395637, -0.00016177933, 0.008434558, -0.010425689, -0.00498109, 0.0020694698, 0.011666065, 0.0052520144, 0.021582548, -0.010856557, 0.020786095, -0.0067241453, 0.029821258, 0.028176127, -0.04731709, 0.024389714, -0.0010641123, -0.026152356, -0.012325423, -0.031831972, -0.009479086, -0.0090221055, 0.004697109, 0.004628562, 0.0023877244, -0.005846089, 0.007337805, 0.015472062, -0.0077490876, -0.012012065, -0.028881183, -0.03389491, -0.015837645, 0.008565124, -0.029377334, 0.030186841, -0.0032772047, 0.01340912, -0.013565799, 0.01586376, 0.0076315785, -0.03755076, -0.015237044, 0.010660708, -0.01471478, 0.00021053756, 0.011927197, 0.0035840347, -0.021203905, 0.0031025729, 0.0023485546, -0.0033098462, 0.0501112, 0.0032119218, -0.011222141, 0.0047787125, 0.012971724, -0.018683983, -0.029899597, 0.004892958, 0.0068351263, 0.029899597, 0.014597271, 0.0055882214, -0.0017512154, -0.005620863, 0.0126975365, 0.015119534, -0.007559767, -0.019937417, -0.0053891083, -0.008643464, -0.008643464, 0.02754941, 0.0018181305, 0.0018899417, -0.033320423, 0.0036395253, -0.006038674, 0.014336139, 0.019898247, 0.00031784642, 0.0034436763, -0.018866776, 0.011979423, 0.0052095805, 0.020759981, -0.03815136, 0.028254466, -0.013363423, 0.00083113374, 0.014910629, -0.023162395, -0.024468055, 0.0005181835, 0.018866776, 0.012971724, 0.027862769, 0.027601637, -0.0150150815, 0.01865787, 0.03444329, -0.017848361, -0.015837645, -0.012292782, 0.025342846, 0.008134257, -0.0025215545, -0.018945115, -0.6354905, -0.03008239, 0.017704738, -0.010477915, 0.012495159, -0.0010396311, 0.004746071, 0.020942774, -0.006854711, 0.013905271, -0.020002699, 0.029951824, 0.0011848857, -0.0152501, -0.008715275, -0.017743908, 0.008525955, -0.016190173, 0.022548735, -0.022379, -0.032615367, 0.0051116557, -0.02065553, -0.013552743, 0.011561613, 0.0013162676, -0.0052748634, 0.014283912, -0.013200215, 0.01329814, -0.033529326, 0.03057854, -0.011613839, 0.0038516948, 0.049667276, 0.016829947, -0.019898247, 0.010797801, -0.0028104314, 0.03598397, -0.021791453, -0.00877403, 0.02517311, 0.008317049, 0.0003370233, 0.00908086, 0.0075924085, -0.012932555, -0.0015137487, 0.009896897, -0.024206921, -0.0033000538, 0.0062834853, 0.018618701, -0.010739047, -0.008826256, -0.007540182, -0.01639908, 0.018174777, 0.016111834, -0.00071036024, 0.013539687, -0.00664907, -0.017756965, -0.01471478, 0.016503531, -0.008865426, 0.004608977, 0.037498534, -0.022392055, 0.010125387, 0.022444282, 1.0710486e-06, -0.005865674, 0.020720812, -0.026844354, 0.011639952, -0.007468371, 0.00021767788, 0.011822744, 0.016921343, -0.019297643, 0.0054968256, 0.0046383543, 0.018018097, 0.002909988, -0.015067308, -0.015367609, 0.0024807525, 0.02095583, 0.021922018, 0.0037831478, 0.018945115, -0.026700731, 0.005079014, 0.015902929, 0.009798973, -0.0067110886, 0.023893565, -0.015197874, -0.012103461, 0.007514069, 0.010517085, -0.011019764, -0.0032151858, 0.020394398, -0.017783077, -0.0030372897, 0.023123225, -0.03172752, -0.018109493, -0.031466387, -0.03057854, 0.0012020225, 0.0064662774, -0.027105486, 0.009120029, 0.022026472, -0.027810542, 0.005911372, 0.01340912, 0.016686324, 0.010484444, -0.025277562, -0.0043543736, 0.007755616, 0.014688667, -0.009818558, -0.036349554, 0.0005018627, -0.010086218, -0.009139614, 0.015680967, 0.015171761, -0.0011759093, -0.0015961684, 0.014962855, -0.016268514, -0.002867554, -0.011470216, 0.0046709958, 0.0036166762, -0.003394714, 0.011868442, -0.036558457, 0.0072921067, -0.015237044, -0.020368284, -0.03363378, 0.0019780737, -0.011398405, -0.0021216962, -0.01406195, 0.019597946, 0.0019976585, -0.007559767, -0.02137364, 0.0027728938, -0.009531313, -0.023880508, 0.024794469, 0.01475395, -0.019454323, -0.013618026, 0.011058934, -0.0055164103, 0.040684342, 0.0005618415, -0.024376659, -0.041206606, 0.022078699, -0.0041617886, -0.0051769386, 0.015746249, 0.016059607, 0.000117101314, -0.01739138, 0.012442932, 0.024794469, 0.029455673, -0.0045795995, -0.015902929, -0.018435908, -0.010366934, 0.020720812, 0.016177118, -0.020485792, 0.030030163, -0.011124217, 0.0032935254, -0.014767006, 0.0056796176, -0.003306582, 0.0038908646, 0.013324252, 0.024233036, -0.004569807, -0.010138444, 0.009185312, 0.008721803, 0.04232947, 0.010928368, 0.042277247, -0.031936422, -0.013683309, -0.02578677, 0.008401917, -0.008676105, 0.006763315, 0.01820089, -0.014427535, -0.014427535, -0.017613342, -0.02992571, 0.014492818, 0.013748592, -0.013213271, 0.004129147, 0.004798298, -0.026948808, 0.014610327, 0.0055621085, 0.015524289, -0.012194857, 0.007729503, 0.03846472, -0.015772363, 0.00013352405, 0.0108435, -0.0081277285, -0.009896897, 0.018892888, -0.0025215545, 0.030682992, -0.0013986875, -0.04253838, -0.0073051634, -0.013082705, 0.03115303, 0.016177118, 0.006192089, 0.017939758, -0.006427108, -0.005464184, 0.018801492, -0.0032951576, 0.029638465, 0.00639773, 0.0010543198, -0.00030050564, -0.006985277, -0.0027663654, -0.0043511093, 0.0076968614, 0.033999365, -0.00896335, -0.008545539, 0.030395748, -0.00031641836, 0.025146997, 0.04052766, 0.0386214, 0.0013986875, -0.02414164, 0.003900657, -0.009896897, 0.008382332, -0.007383503, 0.006188825, -0.016621042, -0.0081277285, -0.015654854, 0.020577189, 0.00059203483, 0.031518612, 0.010099274, -0.009009048, 0.026583223, -0.01406195, -0.0071876543, 0.009433388, -0.03483499, 0.006632749, 0.013748592, -0.011450632, -0.011914141, -0.0042695054, -0.016333796, -0.014127233, 0.026517939, -0.012580027, -0.00559475, -0.001035551, 0.008016747, 0.003331063, -0.01731304, 0.034652196, -0.011868442, 0.009048218, 0.0005797943, 0.020303002, 0.013023951, -0.015223987, -0.011104632, 0.03232812, 0.0025590921, -0.0030062804, -0.0007536102, 0.030918011, -0.026217638, 0.006440164, -0.018057266, -0.021582548, -0.012860743, 0.008943765, -0.0029246768, -0.014349195, -0.020446623, 0.009766331, -0.0060778437, -0.013578856, -0.03159695, -0.019245416, 0.00090580113, 0.15835035, 0.03371212, 0.00904169, 0.015093421, -0.019140964, 0.008003691, -0.026269864, -0.015902929, 0.01417946, -0.011835801, 0.0077621443, 0.006939579, -0.0140880635, 0.024533337, 0.015080364, -0.0019225832, 0.018971229, -0.004608977, -0.005079014, -0.035566155, -0.016111834, -0.0031907049, 0.009446444, 0.031831972, -7.028119e-05, -0.02509477, 0.020198548, 0.014897572, 0.023110168, -0.011894556, -0.011228669, -0.0042042225, 0.003213554, -0.0025460355, -0.02079915, 0.019624058, -0.0073965597, -0.0030601388, 0.007200711, -0.00015300694, 0.010203727, -0.0007070961, -0.002560724, -0.009661878, 0.03436495, -0.035200574, -0.0029148841, 0.0128738005, 0.00025297145, 0.0066686547, 0.025551751, -0.00062712445, -0.025395073, -0.0044882037, -0.0070179184, 0.015850702, -0.013121875, 0.0072790505, -0.00074871397, 0.007670748, -0.019258473, -0.0024415827, -0.011130745, -0.011835801, 0.0013807346, 0.0009735322, -0.027862769, -0.020577189, -0.0023975167, -0.004057336, 0.014558101, -0.012318895, -0.037602983, 0.0125212725, 0.009048218, -0.0018246588, 0.03713295, -0.002715771, 0.0113396505, -0.011613839, -0.0059570703, -0.025160054, 0.006913466, -0.011000179, -0.0009596596, 0.00025745967, 0.017286928, -0.008068974, -0.018631756, 0.024415828, 0.0030829879, -0.0014745789, 0.011143802, -0.025460355, -0.022979602, -0.0020237716, 0.0069526355, 0.016555758, -0.019336812, -0.0031254217, 0.0013513573, -0.0116268955, -0.0035056951, -0.005056165, -0.012305838, 0.00908086, 0.009368105, 0.027079374, -0.011267839, -0.006211674, -0.0013048432, -0.03198865, 0.011209085, 0.009909953, -0.0073508616, 0.021360585, -0.0055686366, 0.006227995, -0.0108761415, -0.0044490336, 0.017600287, -0.024885865, 0.041076038, -0.0005426646, -0.006110485, 0.013082705, -0.005441335, 0.0059668627, 0.020903604, 0.014701723, 0.03274593, 0.026661562, -0.015615685, -0.036218986, -0.021177793, -0.0055262027, -0.013050064, 0.02705326, 0.01295214, -0.007337805, -0.0153023265, -0.019859077, 0.006322655, -0.03271982, 0.025316732, -0.022822924, -0.002865922, 0.02156949, -0.023201564, 0.0051018633, -0.022248434, 0.011143802, -0.009759802, -0.0003129502, 0.0018817814, 0.0026553844, 0.009753275, -0.0030079125, 0.02107334, 0.01950655, -0.00041679092, -0.00965535, 0.008806671, -0.0037276573, 0.02348881, -0.0021527056, 0.0052748634, 0.013363423, 0.0005667377, 0.023841338, 0.013089234, -0.0032037613, -0.027497184, 0.005069222, 0.008480256, 0.011280896, -0.013683309, -0.01111116, -0.014819233, -0.035305023, -0.025551751, 0.008225653, -0.005888523, -0.008708747, -0.00735739, -0.006603372, 0.038177475, 0.0038157892, 0.02295349, -0.0018458758, 0.031544726, -0.010601953, 0.013839988, -0.006368353, -0.00018564842, -0.017848361, -0.026256807, 0.0017675362, 0.021869792, 0.0029165163, 0.0049060145, -0.012005537, -0.009028633, -0.01199248, 0.02022466, 0.008042861, -0.0068416544, -0.0038059969, 0.01980685, -0.024938092, -0.00074871397, -0.04504524, -0.009113501, -0.016294627, 0.013513573, -0.0018621965, 0.010223311, 0.0062671644, -2.817878e-05, -0.0382297, -0.03846472, -0.03164918, -0.0067828996, 0.009896897, 0.014244743, 0.022744583, -0.0069069373, -0.029716805, 0.03483499, 0.012103461, -0.0036950158, 0.00084215024, 0.008943765, -0.02624375, -0.012638781, 0.014518931, 0.020707754, -0.0120577635, -0.037524644, 0.022091754, 0.015002025, -0.033842687, 0.00015106885, 0.0026309034, -0.0014223525, 0.021739226, -0.008349691, -0.003809261, -0.013396064, -0.009622708, -0.0017055174, -0.02386745, 0.0010828811, 0.0034534687, 0.028071674, -0.039143663, 0.0024758563, -0.010575839, 0.0009514992, 0.00176264, -0.02045968, 0.026322091, -0.020838322, 0.0060288818, -0.014283912, 0.009975237, -0.022666244, -0.017208587, 0.0042956187, 0.022326773, -0.01566791, -0.0138008185, -8.568389e-06, 0.015472062, -0.0027010825, -0.0048407316, -0.012214442, -0.0014052157, 0.013970554, -0.009603123, 0.012638781, -0.012971724, -0.027679976, -0.010784745, 0.0050757504, -0.009648821, -0.008976407, -0.005144297, 0.036088422, 0.003567714, -0.0009302822, -0.01582459, -0.008956823, 0.012482102, 0.016555758, -0.01340912, 0.032275897, 0.032954838, -0.021595603, 0.0037994685, -0.045071356, 0.01566791, -0.033424877, -0.016386023, -0.00961618, -0.031126916, 0.0012705696, -0.011235198, -0.018683983, -0.015197874, 0.014897572, 0.01318063, 0.0063422397, -0.008303992, -0.009009048, -0.00392677, 0.022822924, -0.0044849394, -0.031126916, 0.026100129, -0.018031154, 0.00076993095, -0.0022767433, -0.025186166, -0.01068682, 0.013174102, 0.013892215, -0.0072202957, -0.022170093, -0.002797375, -0.011359235, 0.026034845, -0.0058689383, -0.020159379, -0.01022984, 0.01521093, -0.012560442, 0.013722478, 0.005007203, -0.0022571583, 0.023175452, 0.0020449888, 0.029612351, 0.013905271, -0.015759306, -0.0052879197, -0.022392055, -0.021830622, -0.008356219, -0.020773038, -0.022496508, 0.011522443, 0.0058950516, 0.012162216, -0.020342171, -0.0013538054, -0.027288279, -0.016960513, -0.00094660296, -0.0018915739, 0.016673269, 0.0013921591, 0.029664578, 0.029116202, -0.030787446, 0.025551751, 0.001299131, -0.025160054, 0.020329114, -0.026739901, 0.01835757, 0.0338688, -0.013892215, 0.004843996, 0.033529326, 0.005180203, 0.017600287, 0.014270856, -0.0043837507, -0.009603123, 0.013004366, 0.007873124, -0.010334292, 0.018044211, 0.003988789, -0.04961505, 0.0023648753, 0.005379316, -0.015158704, -0.032249782, -0.010099274, 0.00735739, 0.0056143347, -0.008917652, -0.0142969685, 0.01088267, 0.009753275, -0.027967222, 0.013245913, 0.025512582, -0.0012371121, 0.02452028, 0.012717121, -0.032302007, 0.0029344691, 0.014140289, 0.010262482, 0.005425014, -0.017117193, -0.010419161, 0.034417175, -0.010275538, -0.006038674, -0.018592587, 0.0045273732, -0.011267839, -0.009048218, -0.020942774, 0.022509566, 0.002954054, -0.028959522, -0.010177613, -0.00067200646, -0.029116202, 0.004364166, -0.01226014, 0.0017593758, -0.023397414, 0.02210481, 0.012612668, -0.00816037, -0.010530141, -0.0034436763, 0.011045877, 0.0004675892, 0.015746249, 0.23773444, -0.0018573003, 0.006198617, 0.013709422, -0.029977936, 0.018187832, 0.009263652, 0.004171581, -0.014845346, -0.006329183, -0.016621042, 0.003459997, -0.019140964, 0.003721129, 0.029142315, -0.014597271, -0.049876183, -0.019597946, -0.03483499, -0.015067308, 0.009674935, 0.016216287, 0.0047493353, -0.011267839, 0.011483273, 0.015537345, 0.034338836, 0.014323082, 0.01111116, -0.008369275, -0.037916344, -0.0024970733, -0.013696366, -0.0030226011, -0.016660212, -0.013787761, 0.0012599612, -0.001716942, 0.009798973, 0.00842803, -0.008245238, 0.033007063, -0.0035872988, -0.025434243, 0.016790777, 0.05410652, -0.005970127, -0.011639952, -0.0072202957, 0.013853044, -0.059381384, -0.008578181, 0.021386698, 0.034234386, 0.015524289, -0.020054925, 0.03133582, 0.012638781, -0.01034735, 0.027444957, -0.031779744, 0.014192516, -0.0075728237, 0.038177475, 0.0010069896, 0.038751967, -0.01796587, 0.01360497, 0.045880865, -0.018840663, -0.03159695, 0.01061501, -0.0045795995, -0.011959839, -0.028150013, -0.01854036, 0.029795144, 0.02184368, 0.014336139, 7.986962e-05, -0.006149655, -0.006691504, 0.016803835, -0.012775876, -0.0025182902, -0.032249782, 0.005774278, -0.005725316, -0.009322407, 0.006391202, 0.0139444405, -0.011209085, -0.0013195318, -0.01406195, 8.134869e-05, -0.0051247124, 0.002466064, 0.023619376, -0.021504207, 0.0247553, -0.025564808, 0.04024042, 0.016333796, -0.004037751, -0.011359235, 0.0028789786, -0.015563458, 0.026465712, 0.0067959563, -0.035722837, -0.010458331, -0.014740893, -0.009903425, -0.013983611, -0.014780063, 0.015798476, -0.024624733, -0.0018785172, 0.024389714, 0.0018964701, -0.024206921, -0.02942956, -0.0033131104, 0.00043984395, 0.0011049141, -0.02079915, -0.011816216, 0.008264823, -0.012364593, -0.021334471, 0.0036493177, 0.006325919, 0.00024052692, -0.0036982798, -0.021478094, -0.003972468, -0.0006813909, 0.007429201, -0.02352798, 0.0048766374, -0.008793615, -0.013500516, 0.0026374317, -0.0011938622, -0.0027908466, -0.017078022, 0.027888881, -0.026452657, -0.01176399, 0.01410112, -0.0056535043, -0.006394466, -0.0045991847, -0.012495159, 0.02295349, -0.022679301, -0.031179143, -0.022470396, -0.01735221, 0.021086397, -0.035070006, 0.0027663654, 0.025551751, -0.006479334, -0.009896897, 0.002093951, -0.16409525, 0.009622708, 0.010353877, 0.003349016, 0.011019764, -0.012978253, 0.0014623384, -0.021869792, -0.007605465, -0.0020221397, 0.017783077, 0.017365268, -0.034913328, -0.009224482, -0.0018768852, -0.002536243, -0.022444282, 0.0055392594, 0.0037505063, 0.0034012424, 0.03008239, -0.012155687, 0.0021967716, -0.042825624, 0.021491151, -0.010425689, -0.00524875, 0.016634097, 0.0017038853, -0.00735739, -0.0019911302, -0.0013138195, 0.031492498, 0.0017805928, 0.008787086, -0.007207239, -0.020094095, -0.012449461, -0.0042433925, 0.031100804, 0.043243434, 0.025499525, 0.014257799, -0.010667236, -0.0037374496, -0.0061594476, -0.00670456, 0.011633424, -0.016686324, -0.012821574, -0.0033588083, -0.016425192, -0.011365764, 0.007272522, 0.017561115, -0.0030568747, -0.014244743, 0.01291297, -0.010001349, 0.0051704105, -0.0044392413, -0.008728332, 0.0041193548, 0.0050006746, -0.017783077, 0.025107827, -0.021739226, 0.013631082, -0.018683983, 0.0090221055, -0.00793188, -0.011522443, -0.010889198, -0.0147278365, -0.005160618, 0.02352798, -0.02885507, 0.0104975, -0.007533654, 0.01758723, -0.011999008, 0.042668942, -0.004187902, 0.0013595177, -0.009276709, -0.010889198, -0.004504524, 0.010066632, -0.0026031581, -0.013931384, 0.018579531, -0.040214304, -0.00030336177, 0.003043818, 0.0030780917, 0.011032821, 0.0065707304, 0.0002006431, 0.004612241, -0.007618522, -0.0007311692, -0.016882174, -0.003544865, 0.03828193, -0.0009376266, 0.02448111, 0.01264531, 0.032380346, -0.0030944124, 0.005970127, -0.019963529, -0.00017810008, 0.027732203, 0.0305002, 0.02042051, 0.0019307437, -0.0068808245, -0.0014525459, 0.013324252, -0.0076511633, 0.058754668, -0.0016418665, -0.004494732, -0.003721129, 0.015811533, -0.0016891967, -0.11959839, -0.0007319852, 0.0029671106, 0.012312367, -0.006848183, 0.018566474, 0.015432892, 0.031440273, -0.015576515, 0.047682676, -0.008251766, -0.025969563, 0.005506618, -0.0049876184, 0.004984354, 0.0026978184, -0.009211426, -0.016673269, -0.003306582, 0.004324996, -0.018187832, 0.008715275, 0.004892958, -0.00961618, -0.017783077, -0.01873621, -0.010575839, 0.018670926, 0.007709918, 0.0072594653, -0.012736706, -0.0027255637, -0.012560442, -0.007579352, -0.013866101, -0.00035681218, -0.023514923, -0.020250775, 0.025316732, -0.009916482, -0.004919071, -0.01934987, 0.015354553, -0.0056339195, -0.0035350723, -0.00045371658, 0.008636936, 0.025773713, 0.02233983, -0.02079915, -0.01582459, 0.029090088, -0.0003770091, -0.028750617, 0.01816172, -0.0016279939, -0.022744583, -0.0090547465, -0.033111516, 0.011222141, -0.0019193192, -0.0070701446, 0.0018834135, 0.007076673, 0.0040508076, 0.00542175, -0.014257799, -0.02111251, -0.006763315, -0.038255814, 0.013226328, 0.014257799, -0.017691683, 0.024768356, -0.008943765, -0.0076315785, -0.027001033, -0.0021216962, 0.013147988, -0.01796587, -0.013539687, -0.0016418665, 0.011548556, -0.032275897, 0.023632431, 0.011013236, -0.015171761, 0.025577864, 0.0045665433, -0.009276709, 0.021621717, 0.03789023, 0.007860068, -0.007794786, -0.028306693, 0.011254783, -0.005356467, -0.016294627, 0.0099817645, 0.0045600147, -0.03042186, 0.0027500447, -0.07259465, 0.024415828, -0.020916661, -0.015380666, -0.0032706764, 0.027366618, 0.0014607062, -0.013996667, -0.024180809, 0.026269864, -0.00896335, 0.019571831, 0.0020303, -0.009191841, -0.01570708, -0.0032951576, 0.04862275, -0.004857052, 0.022457339, 0.024180809, 0.000793188, 0.024938092, -4.0387454e-06, 0.0010249425, -0.01800504, 0.0012844423, -0.011098104, 0.008264823, -0.018527305, -0.022862094, 0.012495159, -0.0020923188, 0.010725991, 0.02226149, 0.004896222, -0.032615367, 0.013735536, 0.004997411, 0.02008104, -0.015067308, -0.00568941, -0.036271214, 0.0021265924, 0.021386698, -0.013591913, 0.01068682, 0.007605465, -0.00056143344, -0.0019584887, -0.0043511093, -0.032772046, 0.025473412, -0.0025150261, 0.014479761, -0.008578181, -0.019872133, 0.003988789, -0.0033620726, 0.00038537348, -0.02517311, 0.027914995, 0.0023942527, 0.0051116557, 0.017809192, 0.014832289, 0.0150150815, -0.0058069197, 0.012560442, 0.021739226, -0.02659628, -0.01739138, -0.002516658, 0.0070570884, 0.026648505, 0.015459006, -0.011555084, 0.01907568, -0.003345752, -0.010314708, 0.020916661, 0.028646164, -0.018553417, 0.002490545, 0.01092184, -0.003907185, 0.020877492, 0.008473728, 0.0016843005, -0.0009612916, 0.0062671644, -0.016255457, -0.0007450418, -0.0006581338, 0.018945115, 0.021791453, 0.00392677, -0.015720136, 0.011692178, -0.001986234, -0.01340912, -0.0027451485, 0.0036982798, 0.02038134, -0.00018483239, 0.004151996, 0.025146997, -0.03616676, -0.019428208, -0.023880508, 0.014910629, 0.015367609, 0.01965017, 0.008232181, 0.025264507, -0.032093104, 0.017809192, 0.0020923188, -0.008434558, -0.0059374855, 0.038438607, 0.022653189, -0.006626221, 0.021478094, 0.014936742, 0.02548647, -0.0075205974, 0.0029507899, -0.0013391167, -0.01532844, 0.014518931, 0.007200711, -0.0113396505, -0.04389626, 0.01628157, -0.008290936, -0.013356894, -0.0142969685, 0.01743055, -0.022692358, 0.039509248, 0.0030927802, -0.020773038, 0.008493313, -0.001965017, 0.024050243, 0.009100445, 0.009511727, 0.010693349, 0.0138008185, 0.035957854, -0.015223987, -0.0037766194, -0.012449461, -0.036610685, 0.0013970553, 0.00034926384, 0.007977578, -0.0041813734, 0.00838886, 0.00383211, -0.01475395, 0.022117868, 0.0052977125, -0.010941424, 0.005180203, 0.030787446, -0.041441623, 0.009302822, -0.01911485, 0.02008104, 0.0084149735, -0.01628157, 0.004631826, 0.032850385, -0.008258294, 0.0015463901, 0.01923236, 0.016137948, 0.021360585, 0.0005695938, -0.014688667, -0.02578677, -0.03305929, 0.0034665253, 0.028907295, -0.016033495, 0.005043109, -0.01800504]}, 'source': 'state_of_the_union.txt'}),\n", - " 0.8154673667981145)" + "(Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'state_of_the_union.txt'}),\n", + " 0.016393441706895828)" ] }, - "execution_count": 7, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "docs = db.similarity_search_with_score(query, by_text=False)\n", + "docs = db.similarity_search_with_score(query)\n", + "docs[0]" + ] + }, + { + "cell_type": "markdown", + "id": "8abf9adc", + "metadata": {}, + "source": [ + "## Hybrid Search" + ] + }, + { + "cell_type": "markdown", + "id": "d2d5b24a", + "metadata": {}, + "source": [ + "`similarity_search` does hybrid search by default, following the weaviate client's default settings.\n", + "\n", + "You can override this by passing the relevant params as kwargs. Read the [docs](https://weaviate.io/developers/weaviate/api/graphql/search-operators#hybrid) for more information.\n", + "\n", + "For example, to do a pure keyword search, you can pass `alpha=0`:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "74a7bae0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/tmp/ipykernel_82492/2919976745.py:7: ResourceWarning: unclosed \n", + " db = WeaviateVectorStore.from_documents(docs, embeddings, client = weaviate_client)\n", + "ResourceWarning: Enable tracemalloc to get the object allocation traceback\n" + ] + }, + { + "data": { + "text/plain": [ + "Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'state_of_the_union.txt'})" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "loader = TextLoader(\"state_of_the_union.txt\")\n", + "documents = loader.load()\n", + "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", + "docs = text_splitter.split_documents(documents)\n", + "\n", + "weaviate_client = weaviate.connect_to_local()\n", + "db = WeaviateVectorStore.from_documents(docs, embeddings, client=weaviate_client)\n", + "\n", + "docs = db.similarity_search(query, alpha=0)\n", "docs[0]" ] }, @@ -303,6 +377,66 @@ "Anything uploaded to Weaviate is automatically persistent into the database. You do not need to call any specific method or pass any parameters for this to happen." ] }, + { + "cell_type": "markdown", + "id": "da874a61", + "metadata": {}, + "source": [ + "## Multi-tenancy" + ] + }, + { + "cell_type": "markdown", + "id": "67a0719f", + "metadata": {}, + "source": [ + "Just set the `tenant` parameter whenever you are interacting with the vector store" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "8d365855", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-Jan-30 09:51 AM - langchain_weaviate.vectorstores - INFO - Tenant Foo does not exist in index LangChain_a1b81358def44ba9b0f167698e09ca2c. Creating tenant.\n" + ] + } + ], + "source": [ + "db_with_mt = WeaviateVectorStore.from_documents(\n", + " docs, embeddings, client=weaviate_client, tenant=\"Foo\"\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "49659eb3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'state_of_the_union.txt'}),\n", + " Document(page_content='And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more. \\n\\nI understand. \\n\\nI remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it. \\n\\nThat’s why one of the first things I did as President was fight to pass the American Rescue Plan. \\n\\nBecause people were hurting. We needed to act, and we did. \\n\\nFew pieces of legislation have done more in a critical moment in our history to lift us out of crisis. \\n\\nIt fueled our efforts to vaccinate the nation and combat COVID-19. It delivered immediate economic relief for tens of millions of Americans. \\n\\nHelped put food on their table, keep a roof over their heads, and cut the cost of health insurance. \\n\\nAnd as my Dad used to say, it gave people a little breathing room.', metadata={'source': 'state_of_the_union.txt'}),\n", + " Document(page_content='Putin’s latest attack on Ukraine was premeditated and unprovoked. \\n\\nHe rejected repeated efforts at diplomacy. \\n\\nHe thought the West and NATO wouldn’t respond. And he thought he could divide us at home. Putin was wrong. We were ready. Here is what we did. \\n\\nWe prepared extensively and carefully. \\n\\nWe spent months building a coalition of other freedom-loving nations from Europe and the Americas to Asia and Africa to confront Putin. \\n\\nI spent countless hours unifying our European allies. We shared with the world in advance what we knew Putin was planning and precisely how he would try to falsely justify his aggression. \\n\\nWe countered Russia’s lies with truth. \\n\\nAnd now that he has acted the free world is holding him accountable. \\n\\nAlong with twenty-seven members of the European Union including France, Germany, Italy, as well as countries like the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland.', metadata={'source': 'state_of_the_union.txt'}),\n", + " Document(page_content='He and his Dad both have Type 1 diabetes, which means they need insulin every day. Insulin costs about $10 a vial to make. \\n\\nBut drug companies charge families like Joshua and his Dad up to 30 times more. I spoke with Joshua’s mom. \\n\\nImagine what it’s like to look at your child who needs insulin and have no idea how you’re going to pay for it. \\n\\nWhat it does to your dignity, your ability to look your child in the eye, to be the parent you expect to be. \\n\\nJoshua is here with us tonight. Yesterday was his birthday. Happy birthday, buddy. \\n\\nFor Joshua, and for the 200,000 other young people with Type 1 diabetes, let’s cap the cost of insulin at $35 a month so everyone can afford it. \\n\\nDrug companies will still do very well. And while we’re at it let Medicare negotiate lower prices for prescription drugs, like the VA already does.', metadata={'source': 'state_of_the_union.txt'})]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "db_with_mt.similarity_search(query, tenant=\"Foo\")" + ] + }, { "cell_type": "markdown", "id": "24ecf858", @@ -337,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "id": "cb302651", "metadata": {}, "outputs": [ @@ -345,7 +479,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n" @@ -357,7 +491,7 @@ "Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'state_of_the_union.txt'})" ] }, - "execution_count": 8, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -385,7 +519,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 13, "id": "f74e20d8", "metadata": {}, "outputs": [ @@ -393,7 +527,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/chat_models/openai.py:454: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The class `langchain_community.chat_models.openai.ChatOpenAI` was deprecated in langchain-community 0.0.10 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import ChatOpenAI`.\n", + " warn_deprecated(\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `predict` was deprecated in LangChain 0.1.7 and will be removed in 0.2.0. Use invoke instead.\n", + " warn_deprecated(\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/chat_models/openai.py:458: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n" @@ -402,10 +540,10 @@ { "data": { "text/plain": [ - "\"As an AI language model, I don't have real-time information or the ability to browse the internet. Therefore, I cannot provide you with the most recent statements made by the president about Justice Breyer. However, it's worth noting that the president's opinions on Justice Breyer may vary depending on the specific context and time period. It would be best to refer to reliable news sources or official statements to get the most accurate and up-to-date information on this matter.\"" + "\"As an AI language model, I don't have real-time information or the ability to browse the internet. Therefore, I cannot provide you with the most recent statements made by the president about Justice Breyer. However, it's worth noting that the president's opinions on Justice Breyer may vary depending on the specific context and time period you are referring to.\"" ] }, - "execution_count": 9, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -435,7 +573,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "id": "ad91ded1", "metadata": {}, "outputs": [], @@ -446,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 15, "id": "2438d702", "metadata": {}, "outputs": [], @@ -459,7 +597,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 16, "id": "b0e106ab", "metadata": {}, "outputs": [ @@ -467,8 +605,10 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", - " response = response.dict()\n" + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + " response = response.dict()\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/weaviate/warnings.py:215: DeprecationWarning: Dep015: You are creating a batch using client.batch or collection.batch, which is deprecated. Use X.batch._batch_mode_().\n", + " warnings.warn(\n" ] } ], @@ -476,18 +616,26 @@ "docsearch = WeaviateVectorStore.from_texts(\n", " texts,\n", " embeddings,\n", - " weaviate_url=\"http://localhost:8080\",\n", - " by_text=False,\n", + " client=weaviate_client,\n", " metadatas=[{\"source\": f\"{i}-pl\"} for i in range(len(texts))],\n", ")" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, "id": "86bbb953", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The class `langchain_community.llms.openai.OpenAI` was deprecated in langchain-community 0.0.10 and will be removed in 0.2.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run `pip install -U langchain-openai` and import as `from langchain_openai import OpenAI`.\n", + " warn_deprecated(\n" + ] + } + ], "source": [ "chain = RetrievalQAWithSourcesChain.from_chain_type(\n", " OpenAI(temperature=0), chain_type=\"stuff\", retriever=docsearch.as_retriever()\n", @@ -496,7 +644,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 18, "id": "5c38cc39", "metadata": {}, "outputs": [ @@ -504,11 +652,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n", - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/llms/openai.py:465: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/llms/openai.py:466: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n" @@ -518,10 +666,10 @@ "data": { "text/plain": [ "{'answer': ' The president thanked Justice Stephen Breyer for his service and announced his nomination of Judge Ketanji Brown Jackson to the Supreme Court.\\n',\n", - " 'sources': '31-pl, 32-pl'}" + " 'sources': '31-pl'}" ] }, - "execution_count": 14, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -543,7 +691,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 19, "id": "33b0a9d3", "metadata": {}, "outputs": [], @@ -556,7 +704,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 20, "id": "d2ade6ae", "metadata": {}, "outputs": [ @@ -564,8 +712,10 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", - " response = response.dict()\n" + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + " response = response.dict()\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/weaviate/warnings.py:215: DeprecationWarning: Dep015: You are creating a batch using client.batch or collection.batch, which is deprecated. Use X.batch._batch_mode_().\n", + " warnings.warn(\n" ] } ], @@ -573,8 +723,7 @@ "docsearch = WeaviateVectorStore.from_texts(\n", " texts,\n", " embeddings,\n", - " weaviate_url=\"http://localhost:8080\",\n", - " by_text=False,\n", + " client=weaviate_client,\n", " metadatas=[{\"source\": f\"{i}-pl\"} for i in range(len(texts))],\n", ")\n", "\n", @@ -583,7 +732,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 21, "id": "578570b8", "metadata": {}, "outputs": [ @@ -610,7 +759,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 22, "id": "74982155", "metadata": {}, "outputs": [], @@ -622,7 +771,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 23, "id": "fe129bdd", "metadata": {}, "outputs": [ @@ -630,11 +779,11 @@ "name": "stderr", "output_type": "stream", "text": [ - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:499: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/embeddings/openai.py:500: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n", - "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/chat_models/openai.py:454: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", + "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/langchain_community/chat_models/openai.py:458: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " response = response.dict()\n", "/workspaces/langchain-weaviate/.venv/lib/python3.12/site-packages/pydantic/main.py:979: PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/\n", " warnings.warn('The `dict` method is deprecated; use `model_dump` instead.', DeprecationWarning)\n" @@ -643,10 +792,10 @@ { "data": { "text/plain": [ - "'The president thanked Justice Breyer for his service and dedication to the country.'" + "'The president thanked Justice Breyer for his service and referred to him as an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court.\\n'" ] }, - "execution_count": 19, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" }