# Built-In Functions

Complete reference for all Couchbase module BIFs.

## 🔌 Provider & Connection Functions

Functions to access Couchbase components and manage connections:

* [**couchbaseGetProvider**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetprovider.md) - Get cache provider instance
* [**couchbaseGetCluster**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetcluster.md) - Get cluster connection
* [**couchbaseGetBucket**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetbucket.md) - Get bucket instance
* [**couchbaseGetScope**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetscope.md) - Get scope instance
* [**couchbaseGetCollection**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasegetcollection.md) - Get collection instance

## 🤖 Vector Search Functions

AI/ML vector operations for semantic search and RAG applications:

* [**couchbaseVectorSearch**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasevectorsearch.md) - Search by vector similarity
* [**couchbaseVectorAdd**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasevectoradd.md) - Store vector documents
* [**couchbaseVectorGet**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasevectorget.md) - Retrieve vector document
* [**couchbaseVectorDelete**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasevectordelete.md) - Delete vector document
* [**couchbaseVectorList**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasevectorlist.md) - List vector documents

## 📝 Query Functions

Execute N1QL/SQL++ queries:

* [**couchbaseQuery**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbasequery.md) - Execute raw N1QL queries

## 🔒 Distributed Locking Functions

Coordinate operations across multiple servers with distributed locks:

* [**couchbaseLock**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbaselock.md) - Acquire distributed lock with optional callback
* [**couchbaseUnlock**](/boxlang-+-++/modules/bx-couchbase/built-in-functions/couchbaseunlock.md) - Release distributed lock manually

## 📖 Usage Patterns

### Basic Provider Access

```js
// Get provider
provider = couchbaseGetProvider("default");

// Get cluster
cluster = couchbaseGetCluster("default");

// Get bucket
bucket = couchbaseGetBucket("default");

// Get collection
collection = couchbaseGetCollection(
    cacheName = "default",
    scope = "_default",
    collection = "_default"
);
```

### Vector Operations Workflow

```js
// 1. Store vector
id = couchbaseVectorAdd(
    cacheName = "default",
    text = "Document content",
    embedding = getEmbedding(text),
    metadata = { category: "docs" }
);

// 2. Search vectors
results = couchbaseVectorSearch(
    cacheName = "default",
    collection = "mybucket._default._default",
    embedding = getEmbedding(query),
    limit = 5
);

// 3. Retrieve specific vector
doc = couchbaseVectorGet(cacheName = "default", id = id);

// 4. Delete vector
deleted = couchbaseVectorDelete(cacheName = "default", id = id);
```

### Query Patterns

```js
// Simple query
results = couchbaseQuery(
    cacheName = "default",
    query = "SELECT * FROM `mybucket` WHERE type = 'user'"
);

// Parameterized query
results = couchbaseQuery(
    cacheName = "default",
    query = "SELECT * FROM `mybucket` WHERE type = $type AND status = $status",
    parameters = {
        type: "user",
        status: "active"
    }
);
```

### Distributed Locking Patterns

```js
// Callback mode (automatic lock/unlock)
result = couchbaseLock(
    cacheName = "default",
    name = "user-#userId#-update",
    timeout = 5,
    expires = 30,
    callback = function() {
        // Critical section - automatically locked
        user = getUser(userId);
        user.balance += amount;
        saveUser(user);
        return { success: true };
    }
);

// Manual mode (you control unlock)
lockInfo = couchbaseLock(
    cacheName = "default",
    name = "inventory-#productId#",
    timeout = 5,
    expires = 30
);

if (lockInfo.locked) {
    try {
        // Critical section
        updateInventory(productId);
    } finally {
        couchbaseUnlock("default", "inventory-#productId#", lockInfo.cas);
    }
}
```

## 🔗 Related Documentation

* [API Usage Guide](/boxlang-+-++/modules/bx-couchbase/api-usage.md) - Detailed examples
* [AI Memory Guide](/boxlang-+-++/modules/bx-couchbase/aimemory.md) - Vector search patterns
* [Distributed Locking Guide](/boxlang-+-++/modules/bx-couchbase/distributed-locking.md) - Lock patterns and best practices
* [Reference Overview](/boxlang-+-++/modules/bx-couchbase/reference.md) - Configuration and settings
* [Troubleshooting](/boxlang-+-++/modules/bx-couchbase/troubleshooting.md) - Common issues


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-couchbase/built-in-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
