Query Couchbase Data for LlamaIndex
Load documents into LlamaIndex from a Couchbase cluster using a SQL++ query.
Why it matters
Integrate your Couchbase data into LlamaIndex for advanced AI applications. This asset allows you to query your Couchbase cluster using SQL++ and load the results directly into LlamaIndex for further processing.
Outcomes
What it gets done
Connect to a Couchbase cluster using provided credentials or an existing client.
Execute custom SQL++ queries to retrieve specific data.
Load queried data into LlamaIndex documents, specifying text and metadata fields.
Prepare Couchbase data for use in LlamaIndex-powered AI workflows.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-reader-readers-couchbase | bash Overview
LlamaIndex Readers Integration: Couchbase
A LlamaIndex reader that loads documents from a Couchbase cluster via a SQL++ query, mapping selected fields to document text and metadata. Use when you need a specific, query-defined subset of Couchbase data loaded into a LlamaIndex pipeline.
What it does
The Couchbase Reader loads documents from a Couchbase cluster into LlamaIndex, fetching only the records that match a SQL++ query the user provides. Rather than pulling an entire bucket, the reader is scoped by whatever query is passed in, so retrieval is targeted from the start.
The reader can be initialized two ways: with connection credentials (a connection string, database username, and password), or with an already-initialized Couchbase client object passed directly to the loader. Once initialized, load_data takes the SQL++ query along with a list of text_fields (which fields from each matched document become the document's text) and metadata_fields (which fields are carried over as document metadata).
When to use - and when NOT to
Use it when you need to bring a specific, queryable subset of data already stored in Couchbase into a LlamaIndex index or query engine - for example, records filtered by country or category rather than an entire collection. Do not use it as a general Couchbase administration tool; it is read-only for the purpose of loading documents, and the query itself must be valid SQL++ against the target bucket, scope, and collection.
Capabilities
load_data runs a SQL++ query against the Couchbase cluster and returns matched records as LlamaIndex Document objects, with text_fields controlling which fields populate the document text and metadata_fields controlling which fields are attached as metadata.
How to install
pip install llama-index-readers-couchbase
Requires either a Couchbase connection string with database credentials, or a pre-initialized Couchbase client (using PasswordAuthenticator and Cluster from the Couchbase SDK) passed to the reader.
Who it's for
Developers who already store data in Couchbase and want to pull a specific, query-defined subset of it into a LlamaIndex pipeline for indexing and retrieval, without writing separate extraction code.
Source README
LlamaIndex Readers Integration: Couchbase
pip install llama-index-readers-couchbase
This loader loads documents from Couchbase cluster.
The user specifies a Couchbase client or credentials to initialize the reader. They can specify the SQL++ query to
fetch the relevant docs.
Usage
Here's an example usage of the CouchbaseReader.
import os
from llama_index.readers.couchbase import CouchbaseReader
connection_string = (
"couchbase://localhost" # valid Couchbase connection string
)
db_username = "<valid_database_user_with_read_access_to_bucket_with_data>"
db_[REDACTED]
### query is a valid SQL++ query that is passed to client.query()
query = """
SELECT h.* FROM `travel-sample`.inventory.hotel h
WHERE h.country = 'United States'
LIMIT 5
"""
reader = CouchbaseLoader(
connection_string=connection_string,
db_username=db_username,
db_password=db_password,
)
### It is also possible to pass an initialized Couchbase client to the document loader
### from couchbase.auth import PasswordAuthenticator # noqa: E402
### from couchbase.cluster import Cluster # noqa: E402
### from couchbase.options import ClusterOptions # noqa: E402
### auth = PasswordAuthenticator(
### db_username,
### db_password,
### )
### couchbase_client = Cluster(connection_string, ClusterOptions(auth))
### reader = CouchbaseLoader(client=couchbase_client)
### fields to be written to the document
text_fields = ["name", "title", "address", "reviews"]
### metadata fields to be written to the document's metadata
metadata_fields = (["country", "city"],)
documents = reader.load_data(
query=query, text_fields=text_fields, metadata_fields=metadata_fields
)
This loader is designed to be used as a way to load data into LlamaIndex. See here for examples.
Usage Data
This product automatically collects usage and performance data (such as product name and version) and browser information (such as IP address) (collectively, "Usage Data"). Couchbase uses Usage Data, along with other data you may provide to Couchbase (such as your user name or email address), to develop and improve our products as well as inform our sales and marketing programs. We do not access or collect any data you store in Couchbase products. We use Usage Data to understand aggregate usage patterns and make our products more useful to you. For more information on how Couchbase collects, protects, and processes information, please refer to the Couchbase Privacy Policy viewable at https://www.couchbase.com/privacy-policy.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.