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 instanceParameters:
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.ClusterUse 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 namecollection(required) - Full collection path:bucket.scope.collectionembedding(required) - Vector embedding array (e.g., from OpenAI)limit(optional) - Max results to return (default: 10)filter(optional) - Struct with metadata filtersuserId(optional) - Filter by user IDconversationId(optional) - Filter by conversation ID
Returns: Array of structs with:
Example:
couchbaseVectorAdd()
Store a vector document with embeddings.
Parameters:
cacheName(required) - Cache provider nametext(required) - Text contentembedding(required) - Vector embedding arraymetadata(optional) - Struct with custom metadatauserId(optional) - User IDconversationId(optional) - Conversation IDid(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 namecollection(required) - Full collection pathuserId(optional) - Filter by user IDconversationId(optional) - Filter by conversation IDfilter(optional) - Struct with metadata filterslimit(optional) - Max results (default: 100)
Returns: Array of document structs
📝 Query Functions
couchbaseQuery()
Execute raw N1QL/SQL++ queries.
Parameters:
cacheName(required) - Cache provider namequery(required) - N1QL query stringparameters(optional) - Struct with query parameters
Returns: Array of result rows (structs)
Examples:
🎯 Complete Example: AI Chatbot
🎨 Helper Function: Get OpenAI Embedding
🔗 Next Steps
AI Memory Documentation - Deep dive into vector search
BIF Reference - Complete API documentation
Code Usage - Basic cache operations
Last updated
Was this helpful?
