Skip to content

Commit 97392d9

Browse files
updated screenshots
1 parent e48691b commit 97392d9

File tree

5 files changed

+51
-45
lines changed

5 files changed

+51
-45
lines changed

autovec-tutorial/autovec_langchain.ipynb

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
},
1919
"source": [
2020
"# 1. Create and Deploy Operational Cluster on Capella\n",
21-
" To get started with Couchbase Capella, create an account and use it to deploy a cluster. To know more, please follow the [instructions](https://docs.couchbase.com/cloud/get-started/create-account.html).\n",
21+
"To get started with Couchbase Capella, create an account and use it to deploy a cluster. \n",
22+
"\n",
23+
"Make sure that you deploy a `Multi-node` cluster with `data`, `index`, `query` and `eventing` services enabled. To know more, please follow the [instructions](https://docs.couchbase.com/cloud/get-started/create-account.html).\n",
2224
" ### Couchbase Capella Configuration\n",
2325
" When running Couchbase using [Capella](https://cloud.couchbase.com/sign-in), the following prerequisites need to be met:\n",
2426
" * Create the [database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html) to access the travel-sample bucket (Read and Write) used in the application.\n",
@@ -104,16 +106,16 @@
104106
" \n",
105107
"5. After choosing the type of mapping, it is required to either create an index on the new vector_embedding field or the creation of a vector index can be skipped, which is not recommended as the functionality of vector searching will be lost.\n",
106108
"\n",
107-
" <img src=\"./img/vector_index.png\" width=\"1200px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
109+
" <img src=\"./img/vector_index.png\" width=\"1000px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
108110
"\n",
109111
"6. Below screenshot highlights the whole process which were mentioned above, and click next afterwards as shown below.\n",
110112
"\n",
111-
" <img src=\"./img/vector_index_page.png\" width=\"1200px\" height=\"1200px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
113+
" <img src=\"./img/vector_index_page.png\" width=\"900px\" height=\"1200px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
112114
"\n",
113115
"\n",
114116
"7. Select the model which will be used to create the embeddings. There are two options to create the embeddings, `capella based` and `external model`.\n",
115117
" \n",
116-
" <img src=\"./img/Select_embedding_model.png\" width=\"650px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
118+
" <img src=\"./img/Select_embedding_model.png\" width=\"500px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
117119
"\n",
118120
" - For this tutorial, capella based embedding model is used as can be seen in the image above. API credentials can be uploaded using the file downloaded in `step 2.2` or it can be entered manually as well.\n",
119121
" - Choices between private and insecure networking is available to choose.\n",
@@ -123,7 +125,7 @@
123125
"\n",
124126
"8. <B>`Workflow Summary`</B> will display all the necessary details of the workflow including `Data Source`, `Model Service` and `Billing Overview` as shown in image below.\n",
125127
"\n",
126-
" <img src=\"./img/workflow_summary.png\" width=\"800px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
128+
" <img src=\"./img/workflow_summary.png\" width=\"500px\" height=\"500px\" style=\"padding: 5px; border-radius: 10px 20px 30px 40px; border: 2px solid #555;\">\n",
127129
"\n",
128130
"\n",
129131
"\n",
@@ -142,7 +144,9 @@
142144
"source": [
143145
"# 5. Vector Search\n",
144146
"\n",
145-
"The following code cells implement semantic vector search against the embeddings generated by the AutoVectorization workflow. "
147+
"The following code cells implement semantic vector search against the embeddings generated by the AutoVectorization workflow. These searches are powered by **Couchbase's Search service**.\n",
148+
"\n",
149+
"Before you proceed, make sure the following packages are installed by running:"
146150
]
147151
},
148152
{
@@ -156,15 +160,14 @@
156160
},
157161
"outputs": [],
158162
"source": [
159-
"!pip install couchbase langchain-couchbase langchain-openai"
163+
"!pip install langchain-couchbase langchain-openai"
160164
]
161165
},
162166
{
163167
"cell_type": "markdown",
164168
"id": "a1854af3",
165169
"metadata": {},
166170
"source": [
167-
"`couchbase - Version: 4.4.0` \\\n",
168171
"`langchain-couchbase - Version: 0.4.0` \\\n",
169172
"`pip install langchain-openai - Version: 0.3.34`\n",
170173
"\n",
@@ -175,7 +178,7 @@
175178
},
176179
{
177180
"cell_type": "code",
178-
"execution_count": null,
181+
"execution_count": 6,
179182
"id": "30955126-0053-4cec-9dec-e4c05a8de7c3",
180183
"metadata": {},
181184
"outputs": [],
@@ -185,7 +188,9 @@
185188
"from couchbase.options import ClusterOptions\n",
186189
"\n",
187190
"from langchain_openai import OpenAIEmbeddings\n",
188-
"from langchain_couchbase.vectorstores import CouchbaseSearchVectorStore"
191+
"from langchain_couchbase.vectorstores import CouchbaseSearchVectorStore\n",
192+
"\n",
193+
"from datetime import timedelta"
189194
]
190195
},
191196
{
@@ -194,23 +199,22 @@
194199
"metadata": {},
195200
"source": [
196201
"# Cluster Connection Setup\n",
197-
" - Defines the secure connection string, user credentials, and creates a `Cluster` object.\n",
198-
" - Disables TLS verification by `options = ClusterOptions(auth, tls_verify='none')` ONLY for quick local testing (not recommended in production) and applies the `wan_development` profile to tune timeouts for higher-latency networks."
202+
" - Defines the secure connection string, user credentials, and creates a `Cluster` object."
199203
]
200204
},
201205
{
202206
"cell_type": "code",
203-
"execution_count": null,
207+
"execution_count": 7,
204208
"id": "7e4c9e8d",
205209
"metadata": {},
206210
"outputs": [],
207211
"source": [
208-
"endpoint = \"CLUSTER_CONNECTION_STRING\" # Replace this with Connection String\n",
209-
"username = \"YOUR_USERNAME\" # Replace this with your username\n",
210-
"password = \"YOUR_PASSWORD\" # Replace this with your password\n",
212+
"endpoint = \"couchbases://cb.f-znsfdbilcp-ja4.sandbox.nonprod-project-avengers.com\" # Replace this with Connection String\n",
213+
"username = \"testing\" # Replace this with your username\n",
214+
"password = \"Testing@1\" # Replace this with your password\n",
211215
"auth = PasswordAuthenticator(username, password)\n",
212216
"\n",
213-
"options = ClusterOptions(auth)\n",
217+
"options = ClusterOptions(auth, tls_verify='none')\n",
214218
"cluster = Cluster(endpoint, options)\n",
215219
"\n",
216220
"cluster.wait_until_ready(timedelta(seconds=5))"
@@ -223,10 +227,11 @@
223227
"source": [
224228
"# Selection of Buckets / Scope / Collection / Index / Embedder\n",
225229
" - Sets the bucket, scope, and collection where the documents (with vector fields) live.\n",
226-
" - Specifies the Capella Search index name created (or selected) in Step 4.5.\n",
230+
" - `index_name` specifies the **Capella Search index name**. This is the Search index created automatically during the workflow setup (step 4.5) or manually as described in the same step. You can find this index name in the **Search** tab of your Capella cluster.\n",
227231
" - `embedder` instantiates the NVIDIA embedding model that will transform the user's natural language query into a vector at search time.\n",
228232
" - `open_api_key` is the api key token created in `step 3.2 -3`.\n",
229233
" - `open_api_base` is the Capella model services endpoint found in the models section.\n",
234+
" - for more details visit [openAIEmbeddings](https://docs.langchain.com/oss/python/integrations/text_embedding/openai).\n",
230235
"\n",
231236
"`Note that the Capella AI Endpoint also requires an additional /v1 from the endpoint if not shown on the UI`"
232237
]
@@ -241,8 +246,8 @@
241246
"bucket_name = \"travel-sample\"\n",
242247
"scope_name = \"inventory\"\n",
243248
"collection_name = \"hotel\"\n",
244-
"index_name = \"hybrid_autovec_workflow_vec_addr_descr_id\" # This is the name of the search index that was created in step 4.5 and can also be seen in the search tab of the cluster.\n",
245-
" # It should be noted that hybrid_workflow_name_index_fieldname is the naming convention for the index created by AutoVectorization workflow where\n",
249+
"index_name = \"hyperscale_autovec_workflow_vec_addr_descr_id\" # This is the name of the search index that was created in step 4.5 and can also be seen in the search tab of the cluster.\n",
250+
" # It should be noted that hyperscale_workflow_name_index_fieldname is the naming convention for the index created by AutoVectorization workflow where\n",
246251
" # fieldname is the name of the field being indexed.\n",
247252
"\n",
248253
"# Using the OpenAI SDK for the embeddings with the capella model services and they are compatible with the OpenAIEmbeddings class in Langchain\n",
@@ -261,20 +266,37 @@
261266
"metadata": {},
262267
"source": [
263268
"# VectorStore Construction\n",
264-
" - Creates a `CouchbaseSearchVectorStore` instance that:\n",
269+
" - Creates a [CouchbaseSearchVectorStore](https://couchbase-ecosystem.github.io/langchain-couchbase/langchain_couchbase.html#couchbase-search-vector-store) instance that interfaces with **Couchbase's Search service** to perform vector similarity searches.\n",
270+
" - The vector store:\n",
265271
" * Knows where to read documents (`bucket/scope/collection`).\n",
266-
" * Knows the embedding field (the vector produced by the AutoVectorization workflow).\n",
267-
" * Uses the provided embedder to embed queries on-demand.\n",
272+
" * References the Search index (`index_name`) that contains vector field mappings.\n",
273+
" * Knows the embedding field (the vector produced by the Auto-Vectorization workflow).\n",
274+
" * Uses the provided embedder to embed queries on-demand for similarity search.\n",
268275
" - If your AutoVectorization workflow produced a different vector field name, update `embedding_key` accordingly.\n",
269276
" - If you mapped multiple fields into a single vector, you can choose any representative field for `text_key`, or modify the VectorStore wrapper to concatenate fields."
270277
]
271278
},
272279
{
273280
"cell_type": "code",
274-
"execution_count": null,
281+
"execution_count": 21,
275282
"id": "50b85f78",
276283
"metadata": {},
277-
"outputs": [],
284+
"outputs": [
285+
{
286+
"ename": "ValueError",
287+
"evalue": "Index hyperscale_autovec_workflow_vec_addr_descr_id does not exist. Please create the index before searching.",
288+
"output_type": "error",
289+
"traceback": [
290+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
291+
"\u001b[31mValueError\u001b[39m Traceback (most recent call last)",
292+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[21]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m vector_store = \u001b[43mCouchbaseSearchVectorStore\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 2\u001b[39m \u001b[43m \u001b[49m\u001b[43mcluster\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcluster\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[43m \u001b[49m\u001b[43mbucket_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mbucket_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 4\u001b[39m \u001b[43m \u001b[49m\u001b[43mscope_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mscope_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43membedding\u001b[49m\u001b[43m=\u001b[49m\u001b[43membedder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 7\u001b[39m \u001b[43m \u001b[49m\u001b[43mindex_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mindex_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 8\u001b[39m \u001b[43m \u001b[49m\u001b[43mtext_key\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43maddress\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Your document's text field\u001b[39;49;00m\n\u001b[32m 9\u001b[39m \u001b[43m \u001b[49m\u001b[43membedding_key\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mvec_addr_descr_id\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# This is the field in which your vector (embedding) is stored in the cluster.\u001b[39;49;00m\n\u001b[32m 10\u001b[39m \u001b[43m)\u001b[49m\n",
293+
"\u001b[36mFile \u001b[39m\u001b[32m~/vector-search-cookbook/.venv/lib/python3.14/site-packages/langchain_couchbase/vectorstores/search_vector_store.py:267\u001b[39m, in \u001b[36mCouchbaseSearchVectorStore.__init__\u001b[39m\u001b[34m(self, cluster, bucket_name, scope_name, collection_name, embedding, index_name, text_key, embedding_key, scoped_index)\u001b[39m\n\u001b[32m 265\u001b[39m \u001b[38;5;28mself\u001b[39m._check_index_exists()\n\u001b[32m 266\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m--> \u001b[39m\u001b[32m267\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
294+
"\u001b[36mFile \u001b[39m\u001b[32m~/vector-search-cookbook/.venv/lib/python3.14/site-packages/langchain_couchbase/vectorstores/search_vector_store.py:265\u001b[39m, in \u001b[36mCouchbaseSearchVectorStore.__init__\u001b[39m\u001b[34m(self, cluster, bucket_name, scope_name, collection_name, embedding, index_name, text_key, embedding_key, scoped_index)\u001b[39m\n\u001b[32m 263\u001b[39m \u001b[38;5;66;03m# Check if the index exists. Throws ValueError if it doesn't\u001b[39;00m\n\u001b[32m 264\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m265\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_check_index_exists\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 266\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m 267\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m e\n",
295+
"\u001b[36mFile \u001b[39m\u001b[32m~/vector-search-cookbook/.venv/lib/python3.14/site-packages/langchain_couchbase/vectorstores/search_vector_store.py:192\u001b[39m, in \u001b[36mCouchbaseSearchVectorStore._check_index_exists\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 188\u001b[39m all_indexes = [\n\u001b[32m 189\u001b[39m index.name \u001b[38;5;28;01mfor\u001b[39;00m index \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._scope.search_indexes().get_all_indexes()\n\u001b[32m 190\u001b[39m ]\n\u001b[32m 191\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m._index_name \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m all_indexes:\n\u001b[32m--> \u001b[39m\u001b[32m192\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 193\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mIndex \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m._index_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m does not exist. \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 194\u001b[39m \u001b[33m\"\u001b[39m\u001b[33m Please create the index before searching.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 195\u001b[39m )\n\u001b[32m 196\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 197\u001b[39m all_indexes = [\n\u001b[32m 198\u001b[39m index.name \u001b[38;5;28;01mfor\u001b[39;00m index \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._cluster.search_indexes().get_all_indexes()\n\u001b[32m 199\u001b[39m ]\n",
296+
"\u001b[31mValueError\u001b[39m: Index hyperscale_autovec_workflow_vec_addr_descr_id does not exist. Please create the index before searching."
297+
]
298+
}
299+
],
278300
"source": [
279301
"vector_store = CouchbaseSearchVectorStore(\n",
280302
" cluster=cluster,\n",
@@ -306,19 +328,9 @@
306328
"execution_count": null,
307329
"id": "177fd6d5",
308330
"metadata": {},
309-
"outputs": [
310-
{
311-
"name": "stdout",
312-
"output_type": "stream",
313-
"text": [
314-
"1. Glossop — Address: Woodhead Road\n",
315-
"2. Glossop — Address: 28 Woodhead Road\n",
316-
"3. Hadrian's Wall — Address: Greenhead, Brampton, Cumbria, CA8 7HB\n"
317-
]
318-
}
319-
],
331+
"outputs": [],
320332
"source": [
321-
"query = \"Woodhead Road\"\n",
333+
"query = \"What hotels are there in USA?\"\n",
322334
"results = vector_store.similarity_search(query, k=3)\n",
323335
"\n",
324336
"# Print out the top-k results\n",
@@ -350,17 +362,11 @@
350362
"\n",
351363
"> Your vector search pipeline is working if the returned documents feel meaningfully related to your natural language query—even when exact keywords do not match. Feel free to experiment with increasingly descriptive queries to observe the semantic power of the embeddings."
352364
]
353-
},
354-
{
355-
"cell_type": "markdown",
356-
"id": "54b9ee43",
357-
"metadata": {},
358-
"source": []
359365
}
360366
],
361367
"metadata": {
362368
"kernelspec": {
363-
"display_name": "autovec",
369+
"display_name": "Python 3 (ipykernel)",
364370
"language": "python",
365371
"name": "python3"
366372
},
@@ -374,7 +380,7 @@
374380
"name": "python",
375381
"nbconvert_exporter": "python",
376382
"pygments_lexer": "ipython3",
377-
"version": "3.13.7"
383+
"version": "3.14.0"
378384
}
379385
},
380386
"nbformat": 4,
1.85 KB
Loading
5.77 KB
Loading
55 KB
Loading
-120 KB
Loading

0 commit comments

Comments
 (0)