KosmoKrator

data

Jina AI Lua API for KosmoKrator Agents

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

Lua Namespace

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

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Jina AI workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.jinaai.search({q = "example_q"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("jinaai"))' --json
kosmo integrations:lua --eval 'print(docs.read("jinaai.search"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local jinaai = app.integrations.jinaai
local result = jinaai.search({q = "example_q"})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.jinaai, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.jinaai.default.* or app.integrations.jinaai.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Jina AI, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

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

Jina AI — Lua API Reference

Namespace: app.integrations.jinaai

This integration uses Jina Search Foundation endpoints:

  • Search Reader: https://s.jina.ai/
  • URL Reader: https://r.jina.ai/
  • Grounding: https://g.jina.ai/
  • Embeddings: https://api.jina.ai/v1/embeddings
  • Rerank: https://api.jina.ai/v1/rerank
  • Classify: https://api.jina.ai/v1/classify
  • Segment: https://api.jina.ai/v1/segment

Search the web and return Jina Reader search results.

local result = app.integrations.jinaai.search({
  q = "Laravel queue worker retry strategy"
})

for _, item in ipairs(result.data.result or {}) do
  print(item.title .. " " .. item.url)
end

read

Read a URL and extract LLM-friendly content.

local result = app.integrations.jinaai.read({
  url = "https://example.test/article"
})

print(result.data.content)

ground

Verify a statement with Jina Grounding.

local result = app.integrations.jinaai.ground({
  statement = "Jina Reader can convert URLs to markdown."
})

print(result.data.result)
print(result.data.factuality)

references can be passed to restrict sources. The legacy context field is still forwarded for compatibility, but references is preferred for source control.

embeddings

Generate embeddings.

local result = app.integrations.jinaai.embeddings({
  input = {
    "Laravel is a PHP framework",
    "Vue.js is a JavaScript framework"
  },
  model = "jina-embeddings-v3"
})

print(#(result.data or {}))

rerank

Rerank documents by relevance to a query.

local result = app.integrations.jinaai.rerank({
  query = "How to install Laravel",
  documents = {
    "Laravel uses Composer for installation.",
    "Vue renders browser interfaces."
  },
  top_n = 1
})

print(result.results[1].relevance_score)

classify

Classify text or image inputs.

local result = app.integrations.jinaai.classify({
  input = { "Composer installs Laravel packages." },
  labels = { "php", "javascript", "database" },
  top_k = 1
})

print(result.data[1].label)

For few-shot classification, pass the classifier fields supported by the upstream API, such as classifier_id.

segment

Tokenize or segment long text.

local result = app.integrations.jinaai.segment({
  content = "A long paragraph that should be split before embedding.",
  return_chunks = true,
  max_chunk_length = 256
})

for _, chunk in ipairs(result.chunks or {}) do
  print(chunk)
end

Multi-Account Usage

app.integrations.jinaai.search({...})
app.integrations.jinaai.default.search({...})
app.integrations.jinaai.production.search({...})

All functions are identical across accounts; only credentials differ.

Raw agent markdown
# Jina AI — Lua API Reference

Namespace: `app.integrations.jinaai`

This integration uses Jina Search Foundation endpoints:

- Search Reader: `https://s.jina.ai/`
- URL Reader: `https://r.jina.ai/`
- Grounding: `https://g.jina.ai/`
- Embeddings: `https://api.jina.ai/v1/embeddings`
- Rerank: `https://api.jina.ai/v1/rerank`
- Classify: `https://api.jina.ai/v1/classify`
- Segment: `https://api.jina.ai/v1/segment`

## search

Search the web and return Jina Reader search results.

```lua
local result = app.integrations.jinaai.search({
  q = "Laravel queue worker retry strategy"
})

for _, item in ipairs(result.data.result or {}) do
  print(item.title .. " " .. item.url)
end
```

## read

Read a URL and extract LLM-friendly content.

```lua
local result = app.integrations.jinaai.read({
  url = "https://example.test/article"
})

print(result.data.content)
```

## ground

Verify a statement with Jina Grounding.

```lua
local result = app.integrations.jinaai.ground({
  statement = "Jina Reader can convert URLs to markdown."
})

print(result.data.result)
print(result.data.factuality)
```

`references` can be passed to restrict sources. The legacy `context` field is still forwarded for compatibility, but `references` is preferred for source control.

## embeddings

Generate embeddings.

```lua
local result = app.integrations.jinaai.embeddings({
  input = {
    "Laravel is a PHP framework",
    "Vue.js is a JavaScript framework"
  },
  model = "jina-embeddings-v3"
})

print(#(result.data or {}))
```

## rerank

Rerank documents by relevance to a query.

```lua
local result = app.integrations.jinaai.rerank({
  query = "How to install Laravel",
  documents = {
    "Laravel uses Composer for installation.",
    "Vue renders browser interfaces."
  },
  top_n = 1
})

print(result.results[1].relevance_score)
```

## classify

Classify text or image inputs.

```lua
local result = app.integrations.jinaai.classify({
  input = { "Composer installs Laravel packages." },
  labels = { "php", "javascript", "database" },
  top_k = 1
})

print(result.data[1].label)
```

For few-shot classification, pass the classifier fields supported by the upstream API, such as `classifier_id`.

## segment

Tokenize or segment long text.

```lua
local result = app.integrations.jinaai.segment({
  content = "A long paragraph that should be split before embedding.",
  return_chunks = true,
  max_chunk_length = 256
})

for _, chunk in ipairs(result.chunks or {}) do
  print(chunk)
end
```

## Multi-Account Usage

```lua
app.integrations.jinaai.search({...})
app.integrations.jinaai.default.search({...})
app.integrations.jinaai.production.search({...})
```

All functions are identical across accounts; only credentials differ.
Metadata-derived Lua example
local result = app.integrations.jinaai.search({q = "example_q"})
print(result)

Functions

read Read

Read and extract clean content from a URL using Jina AI Reader. Returns the main text content of a web page, stripping away navigation, ads, and other clutter. Useful for reading articles, documentation, or any web page.

Lua path
app.integrations.jinaai.read
Full name
jinaai.jinaai_read
ParameterTypeRequiredDescription
url string yes The URL to read and extract content from.
ground Read

Ground a statement against provided context using Jina AI. Verifies whether a claim or statement is supported by the given reference text. Returns grounding results indicating which parts of the statement are supported or contradicted.

Lua path
app.integrations.jinaai.ground
Full name
jinaai.jinaai_ground
ParameterTypeRequiredDescription
statement string yes The statement or claim to verify.
references array no Optional references or URLs to restrict grounding sources.
context string no Deprecated compatibility field. Prefer references when restricting sources.
embeddings Read

Generate text embeddings using Jina AI. Converts text into dense vector representations useful for semantic search, similarity comparison, clustering, and retrieval-augmented generation (RAG).

Lua path
app.integrations.jinaai.embeddings
Full name
jinaai.jinaai_embeddings
ParameterTypeRequiredDescription
input array yes An array of strings to generate embeddings for. Each string is embedded independently.
model string no The embedding model to use (e.g., "jina-embeddings-v3"). Defaults to the Jina AI default model.
rerank Read

Rerank documents by relevance to a query using Jina AI. Takes a query and a list of text documents, then returns them sorted by relevance with scores. Useful for improving search results or filtering the most relevant content.

Lua path
app.integrations.jinaai.rerank
Full name
jinaai.jinaai_rerank
ParameterTypeRequiredDescription
query string yes The query to rank documents against.
documents array yes An array of document strings to rank by relevance to the query.
model string no The reranking model to use (e.g., "jina-reranker-v2-base-multilingual"). Defaults to the Jina AI default model.
top_n integer no Maximum number of top results to return. Defaults to all documents.
classify Read

Classify text or image inputs using Jina AI Classifier. Provide labels for zero-shot classification or classifier configuration for few-shot classification.

Lua path
app.integrations.jinaai.classify
Full name
jinaai.jinaai_classify
ParameterTypeRequiredDescription
input array yes Inputs to classify. Text inputs may be strings or objects accepted by Jina.
labels array no Zero-shot classification labels.
model string no Embedding or classifier model id.
classifier_id string no Few-shot classifier id when using a trained classifier.
top_k integer no Maximum labels per input to return.
segment Read

Tokenize or segment long text using Jina AI Segmenter before embedding, reranking, or LLM processing.

Lua path
app.integrations.jinaai.segment
Full name
jinaai.jinaai_segment
ParameterTypeRequiredDescription
content string yes Text content to tokenize or segment.
tokenizer string no Tokenizer or model-compatible tokenizer to use.
return_tokens boolean no Whether to include token text in the response.
return_chunks boolean no Whether to include segmented chunks in the response.
max_chunk_length integer no Maximum chunk length when chunking is enabled.