From 134fc87e484bf4712a0e6269fabc4474c254bd81 Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Sun, 2 Apr 2023 13:38:20 -0700 Subject: [PATCH] Add Zilliz example (#2288) Add Zilliz example --- .../vectorstores/examples/zilliz.ipynb | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 docs/modules/indexes/vectorstores/examples/zilliz.ipynb diff --git a/docs/modules/indexes/vectorstores/examples/zilliz.ipynb b/docs/modules/indexes/vectorstores/examples/zilliz.ipynb new file mode 100644 index 0000000000..e1d9407a08 --- /dev/null +++ b/docs/modules/indexes/vectorstores/examples/zilliz.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "683953b3", + "metadata": {}, + "source": [ + "# Zilliz\n", + "\n", + "This notebook shows how to use functionality related to the Zilliz Cloud managed vector database.\n", + "\n", + "To run, you should have a Zilliz Cloud instance up and running: https://zilliz.com/cloud" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aac9563e", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.embeddings.openai import OpenAIEmbeddings\n", + "from langchain.text_splitter import CharacterTextSplitter\n", + "from langchain.vectorstores import Milvus\n", + "from langchain.document_loaders import TextLoader" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "19a71422", + "metadata": {}, + "outputs": [], + "source": [ + "# replace \n", + "ZILLIZ_CLOUD_HOSTNAME = \"\" # example: \"in01-17f69c292d4a50a.aws-us-west-2.vectordb.zillizcloud.com\"\n", + "ZILLIZ_CLOUD_PORT = \"\" #example: \"19532\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a3c3999a", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain.document_loaders import TextLoader\n", + "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", + "embeddings = OpenAIEmbeddings()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dcf88bdf", + "metadata": {}, + "outputs": [], + "source": [ + "vector_db = Milvus.from_documents(\n", + " docs,\n", + " embeddings,\n", + " connection_args={\"host\": ZILLIZ_CLOUD_HOSTNAME, \"port\": ZILLIZ_CLOUD_PORT},\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a8c513ab", + "metadata": {}, + "outputs": [], + "source": [ + "docs = vector_db.similarity_search(query)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc516993", + "metadata": {}, + "outputs": [], + "source": [ + "docs[0]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}