docs: Update couchbase vector store docs (#30710)

-  **Update LangChain-Couchbase documentation**
- Rename `CouchbaseVectorStore` in favor of `CouchbaseSearchVectorStore`

- [x] **Lint and test**
This commit is contained in:
Nithish Raghunandanan
2025-04-08 00:45:14 +02:00
committed by GitHub
parent 3ce0587199
commit 893942651b
5 changed files with 193 additions and 47 deletions

View File

@@ -2669,7 +2669,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"%pip install -qU langchain_couchbase couchbase" "%pip install -qU langchain_couchbase"
] ]
}, },
{ {

View File

@@ -17,7 +17,7 @@ pip install langchain-couchbase
See a [usage example](/docs/integrations/vectorstores/couchbase). See a [usage example](/docs/integrations/vectorstores/couchbase).
```python ```python
from langchain_couchbase import CouchbaseVectorStore from langchain_couchbase import CouchbaseSearchVectorStore
``` ```
## Document loader ## Document loader

View File

@@ -20,15 +20,26 @@
"source": [ "source": [
"## Setup\n", "## Setup\n",
"\n", "\n",
"To access the `CouchbaseVectorStore` you first need to install the `langchain-couchbase` partner package:" "To access the `CouchbaseSearchVectorStore` you first need to install the `langchain-couchbase` partner package:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"id": "bec8d532-fec7-4dc7-9be3-020aa7bdb01f", "id": "bec8d532-fec7-4dc7-9be3-020aa7bdb01f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\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;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0.1\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"
]
}
],
"source": [ "source": [
"pip install -qU langchain-couchbase" "pip install -qU langchain-couchbase"
] ]
@@ -45,10 +56,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"id": "d98e3baa", "id": "d98e3baa",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the connection string for the Couchbase cluster: ········\n",
"Enter the username for the Couchbase cluster: ········\n",
"Enter the password for the Couchbase cluster: ········\n"
]
}
],
"source": [ "source": [
"import getpass\n", "import getpass\n",
"\n", "\n",
@@ -104,7 +125,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"id": "9986c6b9", "id": "9986c6b9",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -135,14 +156,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"id": "1b1d0a26-e9d4-4823-9800-9549d24d3d16", "id": "1b1d0a26-e9d4-4823-9800-9549d24d3d16",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"BUCKET_NAME = \"langchain_bucket\"\n", "BUCKET_NAME = \"langchain_bucket\"\n",
"SCOPE_NAME = \"_default\"\n", "SCOPE_NAME = \"_default\"\n",
"COLLECTION_NAME = \"default\"\n", "COLLECTION_NAME = \"_default\"\n",
"SEARCH_INDEX_NAME = \"langchain-test-index\"" "SEARCH_INDEX_NAME = \"langchain-test-index\""
] ]
}, },
@@ -174,7 +195,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"id": "6706efdd", "id": "6706efdd",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@@ -188,14 +209,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"id": "33db4670-76c5-49ba-94d6-a8fa35583058", "id": "33db4670-76c5-49ba-94d6-a8fa35583058",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_couchbase.vectorstores import CouchbaseVectorStore\n", "from langchain_couchbase.vectorstores import CouchbaseSearchVectorStore\n",
"\n", "\n",
"vector_store = CouchbaseVectorStore(\n", "vector_store = CouchbaseSearchVectorStore(\n",
" cluster=cluster,\n", " cluster=cluster,\n",
" bucket_name=BUCKET_NAME,\n", " bucket_name=BUCKET_NAME,\n",
" scope_name=SCOPE_NAME,\n", " scope_name=SCOPE_NAME,\n",
@@ -217,12 +238,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 7,
"id": "49c38634", "id": "49c38634",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"vector_store_specific = CouchbaseVectorStore(\n", "vector_store_specific = CouchbaseSearchVectorStore(\n",
" cluster=cluster,\n", " cluster=cluster,\n",
" bucket_name=BUCKET_NAME,\n", " bucket_name=BUCKET_NAME,\n",
" scope_name=SCOPE_NAME,\n", " scope_name=SCOPE_NAME,\n",
@@ -250,10 +271,30 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 8,
"id": "65a35f00", "id": "65a35f00",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"['4a6b5252-24ca-4e48-97a9-c33211fc7736',\n",
" '594a413d-761a-44f1-8f0c-6418700b198d',\n",
" 'fdd8461c-f4e3-4c85-af8e-7782ce4d2311',\n",
" '3f6a82b2-7464-4eee-b209-cbca5a236a8a',\n",
" 'df8b87ad-464e-4f83-a007-ccf5a8fa4ff5',\n",
" 'aa18502e-6fb4-4578-9c63-b9a299259b01',\n",
" '8c55a17d-5fa7-4c30-a55d-7ded0d39bf46',\n",
" '41b68c5a-ebf5-4d7a-a079-5e32926ca484',\n",
" '146ac3e0-474a-422a-b0ac-c9fee718396b',\n",
" 'e44941e9-fb3a-4090-88a0-9ffecee3e80e']"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"from uuid import uuid4\n", "from uuid import uuid4\n",
"\n", "\n",
@@ -336,10 +377,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 9,
"id": "3a05f294", "id": "3a05f294",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"vector_store.delete(ids=[uuids[-1]])" "vector_store.delete(ids=[uuids[-1]])"
] ]
@@ -362,10 +414,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 10,
"id": "8e00bb23", "id": "8e00bb23",
"metadata": {}, "metadata": {},
"outputs": [], "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": [ "source": [
"results = vector_store.similarity_search(\n", "results = vector_store.similarity_search(\n",
" \"LangChain provides abstractions to make working with LLMs easy\",\n", " \"LangChain provides abstractions to make working with LLMs easy\",\n",
@@ -387,10 +448,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"id": "24b146b2-55a2-4fe8-8659-3649032f5dc7", "id": "24b146b2-55a2-4fe8-8659-3649032f5dc7",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* [SIM=0.553145] The weather forecast for tomorrow is cloudy and overcast, with a high of 62 degrees. [{'source': 'news'}]\n"
]
}
],
"source": [ "source": [
"results = vector_store.similarity_search_with_score(\"Will it be hot tomorrow?\", k=1)\n", "results = vector_store.similarity_search_with_score(\"Will it be hot tomorrow?\", k=1)\n",
"for res, score in results:\n", "for res, score in results:\n",
@@ -415,10 +484,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 12,
"id": "ffa743dc-4e89-405b-ad71-7390338889e6", "id": "ffa743dc-4e89-405b-ad71-7390338889e6",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"page_content='I had chocalate chip pancakes and scrambled eggs for breakfast this morning.' metadata={'source': 'tweet'}\n"
]
}
],
"source": [ "source": [
"query = \"What did I eat for breakfast today?\"\n", "query = \"What did I eat for breakfast today?\"\n",
"results = vector_store.similarity_search(query, fields=[\"metadata.source\"])\n", "results = vector_store.similarity_search(query, fields=[\"metadata.source\"])\n",
@@ -452,10 +529,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 13,
"id": "7d2e607d-6bbc-4cef-83e3-b6a28bb269ea", "id": "7d2e607d-6bbc-4cef-83e3-b6a28bb269ea",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'author': 'John Doe', 'date': '2016-01-01', 'rating': 2, 'source': '../../how_to/state_of_the_union.txt'}\n"
]
}
],
"source": [ "source": [
"from langchain_community.document_loaders import TextLoader\n", "from langchain_community.document_loaders import TextLoader\n",
"from langchain_text_splitters import CharacterTextSplitter\n", "from langchain_text_splitters import CharacterTextSplitter\n",
@@ -489,10 +574,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 14,
"id": "dc06ba4a-8a6b-4c55-bb69-95cd92db273f", "id": "dc06ba4a-8a6b-4c55-bb69-95cd92db273f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"page_content='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 nations top legal minds, who will continue Justice Breyers legacy of excellence.' metadata={'author': 'John Doe'}\n"
]
}
],
"source": [ "source": [
"query = \"What did the president say about Ketanji Brown Jackson\"\n", "query = \"What did the president say about Ketanji Brown Jackson\"\n",
"results = vector_store.similarity_search(\n", "results = vector_store.similarity_search(\n",
@@ -516,10 +611,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 15,
"id": "fd4749e6-ef4f-4cb5-95ff-37c4fa8283d8", "id": "fd4749e6-ef4f-4cb5-95ff-37c4fa8283d8",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since shes been nominated, shes received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n",
"\n",
"And if we are to advance liberty and justice, we need to secure the Border and fix the immigration system.' metadata={'author': 'Jane Doe'}\n"
]
}
],
"source": [ "source": [
"query = \"What did the president say about Ketanji Brown Jackson\"\n", "query = \"What did the president say about Ketanji Brown Jackson\"\n",
"results = vector_store.similarity_search(\n", "results = vector_store.similarity_search(\n",
@@ -543,10 +648,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 16,
"id": "b7b47e7d-c32f-4999-bce9-3c3c3cebffd0", "id": "b7b47e7d-c32f-4999-bce9-3c3c3cebffd0",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"page_content='We are cutting off Russias largest banks from the international financial system. \n",
"\n",
"Preventing Russias central bank from defending the Russian Ruble making Putins $630 Billion “war fund” worthless. \n",
"\n",
"We are choking off Russias access to technology that will sap its economic strength and weaken its military for years to come. \n",
"\n",
"Tonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more.' metadata={'author': 'Jane Doe', 'date': '2017-01-01', 'rating': 3, 'source': '../../how_to/state_of_the_union.txt'}\n"
]
}
],
"source": [ "source": [
"query = \"Any mention about independence?\"\n", "query = \"Any mention about independence?\"\n",
"results = vector_store.similarity_search(\n", "results = vector_store.similarity_search(\n",
@@ -575,10 +694,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 17,
"id": "7e8bf7c5-07d1-4c3f-86d7-1fa3a454dc7f", "id": "7e8bf7c5-07d1-4c3f-86d7-1fa3a454dc7f",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(Document(id='8616f24425b94a52af3d32d20e6ffb4b', metadata={'author': 'John Doe', 'date': '2014-01-01', 'rating': 5, 'source': '../../how_to/state_of_the_union.txt'}, page_content='In this Capitol, generation after generation, Americans have debated great questions amid great strife, and have done great things. \\n\\nWe have fought for freedom, expanded liberty, defeated totalitarianism and terror. \\n\\nAnd built the strongest, freest, and most prosperous nation the world has ever known. \\n\\nNow is the hour. \\n\\nOur moment of responsibility. \\n\\nOur test of resolve and conscience, of history itself.'), 0.361933544533826)\n"
]
}
],
"source": [ "source": [
"query = \"Any mention about independence?\"\n", "query = \"Any mention about independence?\"\n",
"results = vector_store.similarity_search_with_score(\n", "results = vector_store.similarity_search_with_score(\n",
@@ -609,10 +736,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 18,
"id": "dd0fe7f1-aa40-4c6f-889b-99ad5efcd88b", "id": "dd0fe7f1-aa40-4c6f-889b-99ad5efcd88b",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(Document(id='d9b36ef70b8942dda4db63563f51cf0f', metadata={'author': 'Jane Doe', 'date': '2017-01-01', 'rating': 3, 'source': '../../how_to/state_of_the_union.txt'}, page_content='We are cutting off Russias largest banks from the international financial system. \\n\\nPreventing Russias central bank from defending the Russian Ruble making Putins $630 Billion “war fund” worthless. \\n\\nWe are choking off Russias access to technology that will sap its economic strength and weaken its military for years to come. \\n\\nTonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more.'), 0.7107075545629284)\n"
]
}
],
"source": [ "source": [
"query = \"Any mention about independence?\"\n", "query = \"Any mention about independence?\"\n",
"results = vector_store.similarity_search_with_score(\n", "results = vector_store.similarity_search_with_score(\n",
@@ -655,13 +790,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 19,
"id": "3666265a", "id": "3666265a",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"[Document(id='3f6a82b2-7464-4eee-b209-cbca5a236a8a', metadata={'source': 'news'}, page_content='Robbers broke into the city bank and stole $1 million in cash.')]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"retriever = vector_store.as_retriever(\n", "retriever = vector_store.as_retriever(\n",
" search_type=\"similarity_score_threshold\",\n", " search_type=\"similarity\",\n",
" search_kwargs={\"k\": 1, \"score_threshold\": 0.5},\n", " search_kwargs={\"k\": 1, \"score_threshold\": 0.5},\n",
")\n", ")\n",
"retriever.invoke(\"Stealing from the bank is a crime\", filter={\"source\": \"news\"})" "retriever.invoke(\"Stealing from the bank is a crime\", filter={\"source\": \"news\"})"
@@ -740,7 +886,7 @@
"source": [ "source": [
"## API reference\n", "## API reference\n",
"\n", "\n",
"For detailed documentation of all `CouchbaseVectorStore` features and configurations head to the API reference: https://python.langchain.com/api_reference/couchbase/vectorstores/langchain_couchbase.vectorstores.CouchbaseVectorStore.html" "For detailed documentation of all `CouchbaseSearchVectorStore` features and configurations head to the API reference: https://couchbase-ecosystem.github.io/langchain-couchbase/langchain_couchbase.html "
] ]
} }
], ],
@@ -760,7 +906,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.9" "version": "3.10.13"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@@ -6,7 +6,7 @@ from langchain_astradb import AstraDBVectorStore
from langchain_chroma import Chroma from langchain_chroma import Chroma
from langchain_community import vectorstores from langchain_community import vectorstores
from langchain_core.vectorstores import VectorStore from langchain_core.vectorstores import VectorStore
from langchain_couchbase import CouchbaseVectorStore from langchain_couchbase import CouchbaseSearchVectorStore
from langchain_milvus import Milvus from langchain_milvus import Milvus
from langchain_mongodb import MongoDBAtlasVectorSearch from langchain_mongodb import MongoDBAtlasVectorSearch
from langchain_pinecone import PineconeVectorStore from langchain_pinecone import PineconeVectorStore
@@ -28,7 +28,7 @@ from_partners = [
("PineconeVectorStore", PineconeVectorStore), ("PineconeVectorStore", PineconeVectorStore),
("Milvus", Milvus), ("Milvus", Milvus),
("MongoDBAtlasVectorSearch", MongoDBAtlasVectorSearch), ("MongoDBAtlasVectorSearch", MongoDBAtlasVectorSearch),
("CouchbaseVectorStore", CouchbaseVectorStore), ("CouchbaseSearchVectorStore", CouchbaseSearchVectorStore),
] ]
VECTORSTORE_TEMPLATE = """\ VECTORSTORE_TEMPLATE = """\
@@ -184,7 +184,7 @@ def get_vectorstore_table():
"Local/Cloud": "Local", "Local/Cloud": "Local",
"IDs in add Documents": True, "IDs in add Documents": True,
}, },
"CouchbaseVectorStore": { "CouchbaseSearchVectorStore": {
"Delete by ID": True, "Delete by ID": True,
"Filtering": True, "Filtering": True,
"similarity_search_by_vector": True, "similarity_search_by_vector": True,

View File

@@ -15,7 +15,7 @@ if TYPE_CHECKING:
@deprecated( @deprecated(
since="0.2.4", since="0.2.4",
removal="1.0", removal="1.0",
alternative_import="langchain_couchbase.CouchbaseVectorStore", alternative_import="langchain_couchbase.CouchbaseSearchVectorStore",
) )
class CouchbaseVectorStore(VectorStore): class CouchbaseVectorStore(VectorStore):
"""`Couchbase Vector Store` vector store. """`Couchbase Vector Store` vector store.