- Learn how to use Couchbase Capella’s AI Data Plane (formerly AI Services) Auto-Vectorization feature to automatically process unstructured data from S3 buckets.
- Configure workflows to chunk and vectorize documents (PDFs, images, etc.) and import them into Capella collections.
- Perform semantic vector search using LangChain and the generated embeddings.
To get started with Couchbase Capella, create an account and use it to deploy a cluster.
Make sure that you deploy a Multi-node cluster with data, index, query and eventing services enabled. To know more, please follow the instructions.
Couchbase Capella Configuration
When running Couchbase using Capella, the following prerequisites need to be met.
- Create the database credentials to access the bucket you will be using for this tutorial (e.g.,
Unstructured_data_bucket) with Read and Write permissions. - Allow access to the Cluster from the IP on which the application is running.
Now, before we actually create embeddings for the documents, we need to deploy a model that will create the embeddings for us. Make sure the model is deployed in the same region as that of database for workflows to work. To know more about model services click here.
Selecting the Model
-
To select the model, you first need to navigate to the “AI Data Plane (formerly AI Services)” tab, then select “Models” and click on “Deploy New Model“.
-
Enter the model name, and choose the model that you want to deploy. After selecting your model, choose the model infrastructure and region where the model will be deployed.
Access Control to the Model
-
After deploying the model, go to the “Models” tab in the AI Data Plane (formerly AI Services) and click on “Setup Access“.
-
Enter your API key name, expiration time and the IP address from which you will be accessing the model.
-
Download your API key
In order to import unstructured data from the S3 bucket, you need to create a workflow that connects to your S3 bucket and chunks your unstructured data before importing it into the collections. To do so, please follow the steps mentioned below:
-
Let’s start by creating a new workflow. This can be done by clicking on the
AI Data Plane (formerly AI Services)tab, then click onWorkflows, and then click onCreate New Workflow.
-
Start your workflow deployment by giving it a name and selecting where your data will be provided to the Auto-Vectorization service. There are currently three options:
pre-processed data (JSON format) from Capella,pre-processed data (JSON format) from external sources (S3 buckets)andunstructured data from external sources (S3 buckets). For this tutorial, we will choose the third option, which is unstructured data from external sources (S3 buckets). After selecting the workflow enter the workflow name and click onStart Workflow.
-
To proceed, Capella needs to connect to your S3 bucket which will be the source of the data, and to do so click on the
+ Add New S3 Bucket.
-
Upon clicking
+ Add New S3 Bucketa new sidebar will appear that asks for the credentials of your S3 bucket.
- Enter
Integration Name, which will be later used to select your S3 Bucket. - Select the AWS Region where the bucket is deployed.
- Enter the name of the S3 bucket deployed in AWS.
- Enter the path where your unstructured-data is present.
- Enter your S3 bucket credentials.
- Click on ADD Credentials.
- Enter
-
If the steps mentioned above are followed correctly then you should see a success pop-up as shown below and then the S3 bucket can be selected from the drop-down menu.
-
On selection of the S3 bucket, various options will be displayed as described below.
Index Configurationallows the workflow to automatically create a Hyperscale Vector Search index on the generated embeddings. This Vector Search index is essential for performing vector similarity searches.- If you enable this option (recommended), the workflow will create a properly configured Search index that includes vector field mappings for your embeddings.
- If you skip this step, you’ll need to manually create a Vector Search index later to perform optimised vector searches. See the Vector Search Index Creation Guide below for manual setup instructions.
Destination Clusterhelps choose the cluster, bucket, scope and collection in which the data needs to be imported.Estimated Costdialogue box in blue color(on the right) will show you the cost of operation per document.- Click on
Next.
-
Configure Data Preprocessingallows you to perform various operations on the data being imported from the S3 buckets and are described below.
Page Range selectionallows you to select a custom page range when working with PDFs. (Optional)Layout Exclusionsallows you to skip various unnecessary objects in your unstructured data. (Optional)Object Character Recognition (OCR)allows you to detect text from images/pdfs. (Optional)Chunking Strategyis an important step for importing data and creating embeddings(vectors) in Capella, the step will be further described below.Strategydropdown menu helps to select the strategy that will be used to chunk the data present in S3 bucket and might be useful depending upon the data present in the S3 bucket.Max Token in Chunkdecides the number of tokens that will be present in a chunk.Chunk Overlapdecides the number of tokens that will overlap, this helps create context between chunks.
- Click
Nextafter the options above specified are modified according to the requirement.
-
Select the model which will be used to create the embeddings. There are two options to create the embeddings,
Capella-basedandexternal model.
- 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 model deployment section or it can be entered manually as well.
- Choices between private and insecure networking is available to choose.
- A click on
Nextwill land you at the final page of the workflow.
-
Workflow Summarywill display all the necessary details of the workflow includingData Source,Model Service,Unstructured Data ServiceandBilling Overviewas shown in image below.
-
Workflow DeployedNow in theworkflowtab we can see our workflow deployed and can check the status of our workflow. The status of the workflow run will be shown over here.
After this step, your vector embeddings for the selected fields should be ready, and you can check them out in the Capella UI. In the next step, we will demonstrate how we can use the generated vectors to perform vector search.
The following code cells implement semantic vector search against the embeddings generated by the Auto-Vectorization workflow. These searches are powered by Couchbase’s Search service.
Before you proceed, make sure the following packages are installed by running:
!pip install langchain-couchbase==1.0.1 langchain-openai
langchain-couchbase >= Version: 1.0.1
langchain-openai - Version: 0.3.34
Now, please proceed to execute the cells in order to run the vector similarity search.
from couchbase.cluster import Cluster
from couchbase.auth import PasswordAuthenticator
from couchbase.options import ClusterOptions
from langchain_openai import OpenAIEmbeddings
from langchain_couchbase.vectorstores import CouchbaseQueryVectorStore
from langchain_couchbase.vectorstores import DistanceStrategy
from datetime import timedelta
- Defines the secure connection string, user credentials, and creates a
Clusterobject.
endpoint = "COUCHBASE_CAPELLA_ENDPOINT" # Replace this with Connection String
username = "COUCHBASE_CAPELLA_USERNAME"
password = "COUCHBASE_CAPELLA_PASSWORD"
auth = PasswordAuthenticator(username, password)
options = ClusterOptions(auth)
cluster = Cluster(endpoint, options)
cluster.wait_until_ready(timedelta(seconds=10))
print("Connected!")
Connected!
- Sets the bucket, scope, and collection where the documents (with vector fields) live.
index_namespecifies the Capella Search index name. This is the Search index created automatically in the workflow setup section or manually as described in the same step. You can find this index name in the Search tab of your Capella cluster.embedderinstantiates the NVIDIA embedding model that will transform the user’s natural language query into a vector at search time.open_api_keyis the api key token created in model deployment section.open_api_baseis the Capella model services endpoint found in the models section.- for more details visit openAIEmbeddings.
Note that the Capella AI Endpoint also requires an additional /v1 from the endpoint if not shown on the UI
bucket_name = "Unstructured_data_bucket"
scope_name = "_default"
collection_name = "_default"
index_name = "hyperscale_autovec_workflow_text-embedding" # This is the name of the search index that was created in step 3.6 and can also be seen in the search tab of the cluster.
# Using the OpenAI SDK for the embeddings with the capella model services and they are compatible with the OpenAIEmbeddings class in Langchain
embedder = OpenAIEmbeddings(
model="nvidia/llama-3.2-nv-embedqa-1b-v2", # This is the model that will be used to create the embedding of the query.
openai_api_key="COUCHBASE_CAPELLA_MODEL_API_KEY",
openai_api_base="COUCHBASE_CAPELLA_MODEL_ENDPOINT/v1",
check_embedding_ctx_length=False,
tiktoken_enabled=False,
)
- Creates a CouchbaseQueryVectorStore instance that interfaces with Couchbase’s Query service to perform vector similarity searches using Hyperscale/Composite indexes.
- The vector store:
- Knows where to read documents (
bucket/scope/collection). - Knows the embedding field (the vector produced by the Auto-Vectorization workflow).
- Uses the provided embedder to embed queries on-demand for similarity search.
- Knows where to read documents (
- If your AutoVectorization workflow produced a different vector field name, update
embedding_keyaccordingly. - 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.
vector_store = CouchbaseQueryVectorStore(
cluster=cluster,
bucket_name=bucket_name,
scope_name=scope_name,
collection_name=collection_name,
embedding=embedder,
text_key="text-to-embed", # Your document's text field
embedding_key="text-embedding",
distance_metric=DistanceStrategy.COSINE # This is the field in which your vector (embedding) is stored in the cluster.
)
- Defines a natural language query (e.g., “What are the pre-requisite for java SDK?”).
- Calls
similarity_search(query, k=3)to retrieve the top 3 most semantically similar documents using Couchbase’s Hyperscale Vector Search service. - The Search service performs efficient vector similarity search using the index created earlier.
- Prints ranked results, extracting the chosen
text_key(heretext-to-embed). - Change
queryto any descriptive phrase (e.g., “beach resort”, “airport hotel near NYC”). - Adjust
kfor more or fewer results.
query = "What are the pre-requisite for java SDK?"
results = vector_store.similarity_search(query, k=3)
for i, doc in enumerate(results, 1):
print(f"n--- Result {i} ---")
print(doc.page_content)
--- Result 1 ---
Section Title: Prerequisites
Content: You have installed the Java Software Development Kit (version 8, 11, 17, or 21). The recommended version is the latest Java LTS release. Make sure to install the highest available patch for the LTS version.
--- Result 2 ---
Section Title: Connect the SDK to Your Cluster
Content: Important: directory whenever you
--- Result 3 ---
Section Title: Set Up the Java SDK
Content: To set up the Java SDK: Create the following directory structure on your computer: In the student directory, create a new file called pom.xml . Paste the following code block into your pom.xml file: Open a terminal window and navigate to your student directory. Run the command mvn install to pull in all the dependencies and finish your SDK setup. Next, connect the Java SDK to your cluster.
How the Ranking Works with Search Service
- Your natural language query (e.g.,
query = "How to setup java SDK?") is embedded using the NVIDIA model (nvidia/llama-3.2-nv-embedqa-1b-v2). - The query embedding is compared against the
embedding_key. - Results are sorted by vector similarity. Higher similarity = closer semantic meaning.
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 powered by Couchbase’s Search service.