CouchbaseVectorAdd

Store a vector document with text content, embedding, and metadata.

Syntax

couchbaseVectorAdd(
    cacheName,
    text,
    embedding,
    [metadata],
    [userId],
    [conversationId],
    [id]
)

Parameters

Parameter
Type
Required
Default
Description

cacheName

String

Yes

-

Name of the cache configuration

text

String

Yes

-

Text content to store

embedding

Array

Yes

-

Vector embedding array (e.g., 1536 dimensions)

metadata

Struct

No

{}

Custom metadata to store with document

userId

String

No

-

User ID to associate with document

conversationId

String

No

-

Conversation ID to associate with document

id

String

No

Auto-generated

Custom document ID (otherwise generates vec_UUID)

Returns

Returns the document ID (string) of the stored vector document.

Examples

Basic Storage

Store with Metadata

Store with User Context

Store Conversation Memory

Custom Document ID

Batch Storage

Knowledge Base Builder

Document Structure

The stored document contains:

Notes

  • Embedding dimensions - Must be consistent across all documents (e.g., 1536)

  • Text chunking - For large documents, split into smaller chunks (500-1000 words)

  • ID format - Auto-generated IDs are vec_ + UUID

  • Timestamps - createdAt and updatedAt are set automatically

  • Type field - Always set to "vector_document" for vector search

  • Metadata - Can contain any JSON-serializable data

  • Updates - Use same ID to update existing document

Best Practices

  • 📏 Chunk size - Keep chunks 200-1000 words for best results

  • 🔗 Metadata linking - Use metadata to link chunks back to source documents

  • 🏷️ Categorization - Use metadata categories for filtered searches

  • 👤 User isolation - Always set userId for user-specific data

  • 💬 Conversation tracking - Use conversationId for chat history

  • 🔄 Batch processing - Process multiple documents efficiently

See Also

Last updated

Was this helpful?