KosmoKrator

data

Chroma Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Chroma KosmoKrator integration.

7 functions 5 read 2 write API key auth

Lua Namespace

Agents call this integration through app.integrations.chroma.*. Use lua_read_doc("integrations.chroma") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Chroma — Lua API Reference

list_collections

List all vector collections in Chroma.

Parameters

NameTypeRequiredDescription
limitintegernoMax collections to return (default: 100)
afterstringnoPagination cursor from a previous response

Example

local result = app.integrations.chroma.list_collections({
  limit = 50
})

for _, col in ipairs(result) do
  print(col.name .. " (id: " .. col.id .. ")")
end

get_collection

Get details of a specific collection by name or UUID.

Parameters

NameTypeRequiredDescription
collection_idstringyesCollection name or UUID

Example

local result = app.integrations.chroma.get_collection({
  collection_id = "my_collection"
})

print("Name: " .. result.name)
print("Documents: " .. tostring(result.count))

create_collection

Create a new vector collection.

Parameters

NameTypeRequiredDescription
namestringyesName of the collection
descriptionstringnoOptional description
metadataobjectnoOptional metadata (string key-value pairs)

Example

local result = app.integrations.chroma.create_collection({
  name = "knowledge_base",
  description = "Product documentation embeddings",
  metadata = { category = "docs", version = "1.0" }
})

print("Created collection: " .. result.id)

add_documents

Add documents with embeddings to a collection.

Parameters

NameTypeRequiredDescription
collection_idstringyesCollection name or UUID
idsarrayyesArray of unique document IDs
embeddingsarraynoArray of embedding vectors (float arrays)
documentsarraynoArray of text documents (auto-embedded)
metadatasarraynoArray of metadata objects per document

Either embeddings or documents must be provided.

Example

-- Add documents with auto-generated embeddings
local result = app.integrations.chroma.add_documents({
  collection_id = "knowledge_base",
  ids = { "doc1", "doc2", "doc3" },
  documents = {
    "Chroma is an open-source vector database.",
    "It supports similarity search with embeddings.",
    "You can store metadata alongside documents."
  },
  metadatas = {
    { source = "readme" },
    { source = "docs" },
    { source = "tutorial" }
  }
})

Example with pre-computed embeddings

local result = app.integrations.chroma.add_documents({
  collection_id = "knowledge_base",
  ids = { "vec1" },
  embeddings = {
    { 0.1, 0.2, 0.3, 0.4, 0.5 }
  },
  documents = { "A document with a pre-computed embedding" }
})

query_documents

Search for similar documents using query embeddings or text.

Parameters

NameTypeRequiredDescription
collection_idstringyesCollection name or UUID
query_embeddingsarraynoArray of query embedding vectors
query_textsarraynoArray of query text strings (auto-embedded)
n_resultsintegernoNumber of results per query (default: 10)
wherestringnoJSON metadata filter, e.g. {"category": "tech"}
where_documentstringnoJSON document content filter, e.g. {"$contains": "term"}
includearraynoFields to include: documents, embeddings, metadatas, distances

Either query_embeddings or query_texts must be provided.

Example

-- Query by text (auto-embedded)
local result = app.integrations.chroma.query_documents({
  collection_id = "knowledge_base",
  query_texts = { "What is Chroma?" },
  n_results = 5
})

for i, doc in ipairs(result.documents[1]) do
  print(i .. ": " .. doc .. " (distance: " .. tostring(result.distances[1][i]) .. ")")
end

Example with metadata filter

local result = app.integrations.chroma.query_documents({
  collection_id = "knowledge_base",
  query_texts = { "vector search" },
  n_results = 3,
  where = '{"source": "docs"}',
  include = { "documents", "metadatas", "distances" }
})

get_document

Retrieve specific documents by ID from a collection.

Parameters

NameTypeRequiredDescription
collection_idstringyesCollection name or UUID
idsarraynoArray of document IDs to retrieve
wherestringnoJSON metadata filter
where_documentstringnoJSON document content filter
includearraynoFields: documents, embeddings, metadatas
limitintegernoMax documents to return (default: 100)
offsetintegernoNumber to skip for pagination

Example

local result = app.integrations.chroma.get_document({
  collection_id = "knowledge_base",
  ids = { "doc1", "doc2" }
})

for i, id in ipairs(result.ids) do
  print(id .. ": " .. result.documents[i])
end

Example with filter and pagination

local result = app.integrations.chroma.get_document({
  collection_id = "knowledge_base",
  where = '{"source": "readme"}',
  limit = 10,
  offset = 0,
  include = { "documents", "metadatas" }
})

get_health

Check the health status of the Chroma server.

Parameters

None.

Example

local result = app.integrations.chroma.get_health({})

print("Status: " .. (result.status or "unknown"))

Multi-Account Usage

If you have multiple Chroma instances configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.chroma.function_name({...})

-- Explicit default (portable across setups)
app.integrations.chroma.default.function_name({...})

-- Named accounts
app.integrations.chroma.production.function_name({...})
app.integrations.chroma.staging.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Chroma — Lua API Reference

## list_collections

List all vector collections in Chroma.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max collections to return (default: 100) |
| `after` | string | no | Pagination cursor from a previous response |

### Example

```lua
local result = app.integrations.chroma.list_collections({
  limit = 50
})

for _, col in ipairs(result) do
  print(col.name .. " (id: " .. col.id .. ")")
end
```

---

## get_collection

Get details of a specific collection by name or UUID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `collection_id` | string | yes | Collection name or UUID |

### Example

```lua
local result = app.integrations.chroma.get_collection({
  collection_id = "my_collection"
})

print("Name: " .. result.name)
print("Documents: " .. tostring(result.count))
```

---

## create_collection

Create a new vector collection.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | Name of the collection |
| `description` | string | no | Optional description |
| `metadata` | object | no | Optional metadata (string key-value pairs) |

### Example

```lua
local result = app.integrations.chroma.create_collection({
  name = "knowledge_base",
  description = "Product documentation embeddings",
  metadata = { category = "docs", version = "1.0" }
})

print("Created collection: " .. result.id)
```

---

## add_documents

Add documents with embeddings to a collection.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `collection_id` | string | yes | Collection name or UUID |
| `ids` | array | yes | Array of unique document IDs |
| `embeddings` | array | no | Array of embedding vectors (float arrays) |
| `documents` | array | no | Array of text documents (auto-embedded) |
| `metadatas` | array | no | Array of metadata objects per document |

Either `embeddings` or `documents` must be provided.

### Example

```lua
-- Add documents with auto-generated embeddings
local result = app.integrations.chroma.add_documents({
  collection_id = "knowledge_base",
  ids = { "doc1", "doc2", "doc3" },
  documents = {
    "Chroma is an open-source vector database.",
    "It supports similarity search with embeddings.",
    "You can store metadata alongside documents."
  },
  metadatas = {
    { source = "readme" },
    { source = "docs" },
    { source = "tutorial" }
  }
})
```

### Example with pre-computed embeddings

```lua
local result = app.integrations.chroma.add_documents({
  collection_id = "knowledge_base",
  ids = { "vec1" },
  embeddings = {
    { 0.1, 0.2, 0.3, 0.4, 0.5 }
  },
  documents = { "A document with a pre-computed embedding" }
})
```

---

## query_documents

Search for similar documents using query embeddings or text.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `collection_id` | string | yes | Collection name or UUID |
| `query_embeddings` | array | no | Array of query embedding vectors |
| `query_texts` | array | no | Array of query text strings (auto-embedded) |
| `n_results` | integer | no | Number of results per query (default: 10) |
| `where` | string | no | JSON metadata filter, e.g. `{"category": "tech"}` |
| `where_document` | string | no | JSON document content filter, e.g. `{"$contains": "term"}` |
| `include` | array | no | Fields to include: `documents`, `embeddings`, `metadatas`, `distances` |

Either `query_embeddings` or `query_texts` must be provided.

### Example

```lua
-- Query by text (auto-embedded)
local result = app.integrations.chroma.query_documents({
  collection_id = "knowledge_base",
  query_texts = { "What is Chroma?" },
  n_results = 5
})

for i, doc in ipairs(result.documents[1]) do
  print(i .. ": " .. doc .. " (distance: " .. tostring(result.distances[1][i]) .. ")")
end
```

### Example with metadata filter

```lua
local result = app.integrations.chroma.query_documents({
  collection_id = "knowledge_base",
  query_texts = { "vector search" },
  n_results = 3,
  where = '{"source": "docs"}',
  include = { "documents", "metadatas", "distances" }
})
```

---

## get_document

Retrieve specific documents by ID from a collection.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `collection_id` | string | yes | Collection name or UUID |
| `ids` | array | no | Array of document IDs to retrieve |
| `where` | string | no | JSON metadata filter |
| `where_document` | string | no | JSON document content filter |
| `include` | array | no | Fields: `documents`, `embeddings`, `metadatas` |
| `limit` | integer | no | Max documents to return (default: 100) |
| `offset` | integer | no | Number to skip for pagination |

### Example

```lua
local result = app.integrations.chroma.get_document({
  collection_id = "knowledge_base",
  ids = { "doc1", "doc2" }
})

for i, id in ipairs(result.ids) do
  print(id .. ": " .. result.documents[i])
end
```

### Example with filter and pagination

```lua
local result = app.integrations.chroma.get_document({
  collection_id = "knowledge_base",
  where = '{"source": "readme"}',
  limit = 10,
  offset = 0,
  include = { "documents", "metadatas" }
})
```

---

## get_health

Check the health status of the Chroma server.

### Parameters

None.

### Example

```lua
local result = app.integrations.chroma.get_health({})

print("Status: " .. (result.status or "unknown"))
```

---

## Multi-Account Usage

If you have multiple Chroma instances configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.chroma.function_name({...})

-- Explicit default (portable across setups)
app.integrations.chroma.default.function_name({...})

-- Named accounts
app.integrations.chroma.production.function_name({...})
app.integrations.chroma.staging.function_name({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.chroma.chroma_list_collections({
  limit = 1,
  after = "example_after"
})
print(result)

Functions

chroma_list_collections

List all vector collections in Chroma. Returns collection names and IDs that can be used for further operations.

Operation
Read read
Full name
chroma.chroma_list_collections
ParameterTypeRequiredDescription
limit integer no Maximum number of collections to return (default: 100).
after string no Cursor for pagination — pass the value from a previous response to get the next page.

chroma_get_collection

Get details of a specific Chroma collection by its name or UUID, including metadata and document count.

Operation
Read read
Full name
chroma.chroma_get_collection
ParameterTypeRequiredDescription
collection_id string yes The collection name or UUID.

chroma_create_collection

Create a new vector collection in Chroma. Collections are used to store and query document embeddings.

Operation
Write write
Full name
chroma.chroma_create_collection
ParameterTypeRequiredDescription
name string yes The name of the collection to create.
description string no An optional description of the collection.
metadata object no Optional metadata to attach to the collection (JSON object with string values).

chroma_add_documents

Add documents with embeddings to a Chroma collection. Each document requires an ID and either embeddings or text content.

Operation
Write write
Full name
chroma.chroma_add_documents
ParameterTypeRequiredDescription
collection_id string yes The collection name or UUID to add documents to.
ids array yes Array of unique document IDs (strings).
embeddings array no Array of embedding vectors. Each embedding is an array of floats. Required if no documents text provided.
documents array no Array of text documents. Chroma will generate embeddings if no embeddings are provided.
metadatas array no Array of metadata objects (one per document) with string values.

chroma_query_documents

Search for similar documents in a Chroma collection using query embeddings or text. Returns the most similar documents ranked by distance.

Operation
Read read
Full name
chroma.chroma_query_documents
ParameterTypeRequiredDescription
collection_id string yes The collection name or UUID to query.
query_embeddings array no Array of query embedding vectors. Each embedding is an array of floats.
query_texts array no Array of query text strings. Chroma will generate embeddings automatically.
n_results integer no Number of results to return per query (default: 10).
where string no JSON-encoded filter expression for metadata filtering, e.g. {"category": "tech"}.
where_document string no JSON-encoded filter on document content, e.g. {"$contains": "search term"}.
include array no Fields to include in response: documents, embeddings, metadatas, distances. Default: ["documents", "metadatas", "distances"].

chroma_get_document

Retrieve specific documents from a Chroma collection by their IDs. Returns the full documents including text, embeddings, and metadata.

Operation
Read read
Full name
chroma.chroma_get_document
ParameterTypeRequiredDescription
collection_id string yes The collection name or UUID.
ids array no Array of document IDs to retrieve.
where string no JSON-encoded metadata filter, e.g. {"category": "tech"}.
where_document string no JSON-encoded document content filter, e.g. {"$contains": "search term"}.
include array no Fields to include: documents, embeddings, metadatas. Default: ["documents", "metadatas"].
limit integer no Maximum number of documents to return (default: 100).
offset integer no Number of documents to skip for pagination.

chroma_get_health

Check the health status of the Chroma vector database server. Returns heartbeat and version information.

Operation
Read read
Full name
chroma.chroma_get_health
ParameterTypeRequiredDescription
No parameters.