Skip to content

Commit

Permalink
community[minor]: Add Baidu VectorDB as vector store (langchain-ai#17997
Browse files Browse the repository at this point in the history
)

Co-authored-by: fengjialin <fengjialin@MacBook-Pro.local>
  • Loading branch information
2 people authored and Dave Bechberger committed Mar 29, 2024
1 parent 1c1544c commit dde17eb
Show file tree
Hide file tree
Showing 4 changed files with 559 additions and 0 deletions.
121 changes: 121 additions & 0 deletions docs/docs/integrations/vectorstores/baiduvectordb.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"source": [
"# Baidu VectorDB\n",
"\n",
">[Baidu VectorDB](https://cloud.baidu.com/product/vdb.html) is a robust, enterprise-level distributed database service, meticulously developed and fully managed by Baidu Intelligent Cloud. It stands out for its exceptional ability to store, retrieve, and analyze multi-dimensional vector data. At its core, VectorDB operates on Baidu's proprietary \"Mochow\" vector database kernel, which ensures high performance, availability, and security, alongside remarkable scalability and user-friendliness.\n",
"\n",
">This database service supports a diverse range of index types and similarity calculation methods, catering to various use cases. A standout feature of VectorDB is its capacity to manage an immense vector scale of up to 10 billion, while maintaining impressive query performance, supporting millions of queries per second (QPS) with millisecond-level query latency.\n",
"\n",
"This notebook shows how to use functionality related to the Baidu VectorDB. \n",
"\n",
"To run, you should have a [Database instance.](https://cloud.baidu.com/doc/VDB/s/hlrsoazuf)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip3 install pymochow"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain_community.document_loaders import TextLoader\n",
"from langchain_community.embeddings.fake import FakeEmbeddings\n",
"from langchain_community.vectorstores import BaiduVectorDB\n",
"from langchain_community.vectorstores.baiduvectordb import ConnectionParams"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loader = TextLoader(\"../../modules/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",
"embeddings = FakeEmbeddings(size=128)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"conn_params = ConnectionParams(\n",
" endpoint=\"http://192.168.xx.xx:xxxx\", account=\"root\", api_key=\"****\"\n",
")\n",
"\n",
"vector_db = BaiduVectorDB.from_documents(\n",
" docs, embeddings, connection_params=conn_params, drop=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"query = \"What did the president say about Ketanji Brown Jackson\"\n",
"docs = vector_db.similarity_search(query)\n",
"docs[0].page_content"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vector_db = BaiduVectorDB(embeddings, conn_params)\n",
"vector_db.add_texts([\"Ankush went to Princeton\"])\n",
"query = \"Where did Ankush go to college?\"\n",
"docs = vector_db.max_marginal_relevance_search(query)\n",
"docs[0].page_content"
]
}
],
"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.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"AwaDB": "langchain_community.vectorstores.awadb",
"AzureCosmosDBVectorSearch": "langchain_community.vectorstores.azure_cosmos_db",
"AzureSearch": "langchain_community.vectorstores.azuresearch",
"BaiduVectorDB": "langchain_community.vectorstores.baiduvectordb",
"BESVectorStore": "langchain_community.vectorstores.baiducloud_vector_search",
"Bagel": "langchain_community.vectorstores.bageldb",
"BigQueryVectorSearch": "langchain_community.vectorstores.bigquery_vector_search",
Expand Down

0 comments on commit dde17eb

Please sign in to comment.