API Usage

Explore the powerful Built-In Functions (BIFs) provided by the BoxLang Couchbase Module for advanced caching, session storage, and AI vector search capabilities.

This module provides powerful Built-In Functions (BIFs) for direct interaction with Couchbase, including vector search capabilities for AI applications.

🎯 Core Provider Functions

couchbaseGetProvider()

Get the Couchbase cache provider instance for advanced operations.

provider = couchbaseGetProvider("default");
// Returns: CouchbaseCache instance

Parameters:

  • cacheName (required) - Name of the configured cache

Example:

provider = couchbaseGetProvider("myCache");
collection = provider.getCollection();

couchbaseGetCluster()

Get the Java Cluster instance for advanced Couchbase operations.

cluster = couchbaseGetCluster("default");
// Returns: com.couchbase.client.java.Cluster

Use Cases:

  • Execute raw N1QL queries

  • Access cluster-level operations

  • Manage indexes and buckets

couchbaseGetBucket()

Get the Java Bucket instance.

couchbaseGetScope()

Get the Java Scope instance.

couchbaseGetCollection()

Get the Java Collection instance for direct document operations.

🤖 Vector Search Functions

couchbaseVectorSearch()

Perform semantic vector search using KNN (K-Nearest Neighbors).

Parameters:

  • cacheName (required) - Cache provider name

  • collection (required) - Full collection path: bucket.scope.collection

  • embedding (required) - Vector embedding array (e.g., from OpenAI)

  • limit (optional) - Max results to return (default: 10)

  • filter (optional) - Struct with metadata filters

  • userId (optional) - Filter by user ID

  • conversationId (optional) - Filter by conversation ID

Returns: Array of structs with:

Example:

couchbaseVectorAdd()

Store a vector document with embeddings.

Parameters:

  • cacheName (required) - Cache provider name

  • text (required) - Text content

  • embedding (required) - Vector embedding array

  • metadata (optional) - Struct with custom metadata

  • userId (optional) - User ID

  • conversationId (optional) - Conversation ID

  • id (optional) - Custom document ID (auto-generated if omitted)

Returns: Document ID (string)

Example:

couchbaseVectorGet()

Retrieve a vector document by ID.

Returns: Struct with document data or empty struct if not found

couchbaseVectorDelete()

Delete a vector document.

couchbaseVectorList()

List vector documents with optional filters.

Parameters:

  • cacheName (required) - Cache provider name

  • collection (required) - Full collection path

  • userId (optional) - Filter by user ID

  • conversationId (optional) - Filter by conversation ID

  • filter (optional) - Struct with metadata filters

  • limit (optional) - Max results (default: 100)

Returns: Array of document structs

📝 Query Functions

couchbaseQuery()

Execute raw N1QL/SQL++ queries.

Parameters:

  • cacheName (required) - Cache provider name

  • query (required) - N1QL query string

  • parameters (optional) - Struct with query parameters

Returns: Array of result rows (structs)

Examples:

🎯 Complete Example: AI Chatbot

🎨 Helper Function: Get OpenAI Embedding

🔗 Next Steps

Last updated

Was this helpful?