Awesome Go

dakera-go

CategoryArtificial Intelligence
SubcategoryArtificial Intelligence
Stars7

Official Go client SDK for the Dakera self-hosted agent memory server, providing typed interfaces for memory store/recall, session management, namespace operations, and decay configuration

About dakera-go

This large README is shown as a plain-text preview. Read the full README at the source

<p align="center">
  <img src="https://github.com/dakera-ai.png" alt="Dakera AI" width="80" />
</p>

<h1 align="center">dakera-go</h1>

<p align="center">
  Go client for <a href="https://dakera.ai">Dakera AI</a> — the memory engine for AI agents
</p>

<p align="center">
  <a href="https://github.com/Dakera-AI/dakera-go/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/Dakera-AI/dakera-go/actions/workflows/ci.yml/badge.svg" /></a>
  <a href="https://pkg.go.dev/github.com/Dakera-AI/dakera-go"><img alt="Go Reference" src="https://pkg.go.dev/badge/github.com/Dakera-AI/dakera-go.svg" /></a>
  <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/github/license/Dakera-AI/dakera-go" /></a>
  <a href="https://dakera.ai/docs"><img alt="Docs" src="https://img.shields.io/badge/docs-dakera.ai%2Fdocs-3b82f6?style=flat-square" /></a>
  <a href="https://dakera.ai/benchmark"><img alt="LoCoMo 88.2%" src="https://img.shields.io/badge/LoCoMo-88.2%25-22c55e?style=flat-square" /></a>
  <a href="https://dakera.ai/playground"><img alt="Playground" src="https://img.shields.io/badge/playground-try_it-ff6b35?style=flat-square" /></a>
</p>

---

## Why Dakera?

| | Dakera | Others |
|---|---|---|
| **LoCoMo Recall@20** | **88.2%** (1,536 Q, LLM-judged retrieval recall) | not directly comparable |
| **Deployment** | Single binary, Docker one-liner | External vector DB + embedding service required |
| **Embeddings** | Built-in — no OpenAI key needed | Requires external embedding API |
| **Search modes** | Vector · BM25 · Hybrid · Knowledge Graph | Usually one or two |
| **Dependencies** | stdlib `net/http` only | Often pulls in gRPC or third-party HTTP clients |

→ [Try the playground](https://dakera.ai/playground) · [Full benchmark results](https://dakera.ai/benchmark) · [dakera.ai](https://dakera.ai)

---

## Run Dakera

```bash
docker run -d \
  --name dakera \
  -p 3000:3000 \
  -e DAKERA_ROOT_API_KEY=dk-mykey \
  ghcr.io/dakera-ai/dakera:latest

curl http://localhost:3000/health  # → {"status":"ok"}
```

For persistent storage with Docker Compose:

```bash
curl -sSfL https://raw.githubusercontent.com/Dakera-AI/dakera-deploy/main/docker/docker-compose.yml \
  -o docker-compose.yml
DAKERA_API_KEY=dk-mykey docker compose up -d
```

Full deployment guide (Docker Compose, Kubernetes, Helm): [dakera-deploy](https://github.com/Dakera-AI/dakera-deploy)

---

## Install

```bash
go get github.com/dakera-ai/dakera-go@latest
```

Requires Go 1.21+. Uses only the standard library — no external runtime dependencies.

---

## Quick Start

```go
client := dakera.NewClientWithOptions(dakera.ClientOptions{BaseURL: "http://localhost:3000", APIKey: "dk-mykey"})
imp := float32(0.9)
client.StoreMemory(context.Background(), "my-agent", dakera.StoreMemoryRequest{Content: "User prefers brevity", Importance: &imp})
```

Full example — store, recall, upsert, and hybrid search:

```go
package main

import (
    "context"
    "fmt"
    dakera "github.com/dakera-ai/dakera-go"
)

func main() {
    client := dakera.NewClientWithOptions(dakera.ClientOptions{
        BaseURL: "http://localhost:3000",
        APIKey:  "dk-mykey",
    })
    ctx := context.Background()

    // Store an agent memory
    imp := float32(0.9)
    mem, _ := client.StoreMemory(ctx, "my-agent", dakera.StoreMemoryRequest{
        Content:    "User prefers concise responses with code examples",
        Importance: &imp,
    })
    fmt.Println("Stored:", mem.Memory.ID)

    // Recall memories (semantic search)
    resp, _ := client.Recall(ctx, "my-agent", dakera.RecallRequest{
        Query: "what does the user prefer?",
        TopK:  5,
    })
    for _, m := range resp.Memories {
        fmt.Printf("[%.2f] %s\n", m.Score, m.Content)
    }

    // Upsert vectors
    client.Upsert(ctx, "my-namespace", []dakera.VectorInput{
        {ID: "vec1", Values: []float32{0.1, 0.2, 0.3}},
    })

    // Hybrid search (vector + BM25)
    results, _ := client.HybridSearch(ctx, "my-namespace", nil, "completed task", &dakera.HybridSearchOptions{
        TopK:         5,
        VectorWeight: 0.7,
    })
    for _, r := range results {
        fmt.Println(r.ID, r.Score)
    }
}
```

### Context-based cancellation

All methods accept a `context.Context` — use it for timeouts, deadlines, or cancellation:

```go
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

resp, err := client.Recall(ctx, "my-agent", dakera.RecallRequest{Query: "preferences", TopK: 3})
```

## What's new in v0.12.3

SDK v0.12.3 targets **Dakera server v0.12.3** (Dakera-AI/dakera#917, #920, #921, #923, #926, #930,
#932, #933, #938, #940) and stays **compatible with v0.12.0 – v0.12.2 servers**: new request fields are
omitted unless you set them and new response fields are optional (zero on an older server). The
neighbourhood modes, `IncludeSummaries`, `MatchedText` / `MatchedIDs`, `Retrieval`, `ContextOf`,
`ContextMemories`, `RankScore`, `EventTime`, the truncation report, `Warnings`, the deduplicated-memory
routes and `GetMemory` without an agent id need **server >= 0.12.3** (an older server ignores the new
request fields and answers inline). The `super_admin` requirement of `OpsShutdown` and the `422` on
unknown admin-request fields are server 0.12.3 behaviour.

Also server 0.12.3 behaviour: recall, search and batch recall for an agent that has stored nothing
answer **`200` with no memories** (older servers answered `404 NAMESPACE_NOT_FOUND`), and session ids
may contain `:` (`Capabilities(ctx)` reports `Naming.SessionIDPattern`).

### Event time: memories that happened earlier

A client that writes history (an import, a backfill, a replayed conversation) can say when each
memory's event happened. The server records it as metadata `_dakera_event_time` and uses it, not the
ingest time, for recency, `Since` / `Until`, the temporal windows and graph ordering (`CreatedAt`
stays the ingest time; TTL and decay count from it):

```go
_, err := client.StoreMemory(ctx, "my-agent", dakera.StoreMemoryRequest{
    Content:   "Alice moved to Paris.",
    EventTime: dakera.EventTimeAt(time.Date(2023, 5, 20, 2, 21, 0, 0, time.UTC)), // or EventTimeUnix(1684549260)
})
batch, err := client.StoreMemoriesBatch(ctx, dakera.BatchStoreMemoryRequest{
    AgentID:  "my-agent",
    Memories: []dakera.BatchStoreMemoryItem{{Content: "Bob joined.", EventTime: dakera.EventTimeRFC3339("2023-06-02T10:00:00Z")}},
})
```

More than 24 hours ahead or before 1970 is a `*ValidationError` naming `event_time`.
`StoreMemoryRequest.ValidFrom` is now sent as metadata `valid_from`, where the server reads it.

### Truncation report and ignored-field warnings

Content longer than the embedding model reads is stored whole, but its vector covers only the first
`EmbeddedTokens`. `StoreMemory` and `UpdateMemory` then return `resp.Truncation`
(`ContentTokens`, `EmbeddedTokens`, `MaxTokens`, `Windows`), and `StoreMemoriesBatch` lists such
memories in `resp.Truncated`. Store, batch store, recall and batch recall answers carry `Warnings`
naming request fields the server ignored (`"unknown field 'created_at' ignored"`); every field the SDK
sends is one the server knows, so `Warnings` stays nil unless the server is older than the SDK.

### Deduplicated memories

With AutoPilot deduplication in `merge` mode (`AutopilotUpdateConfig` with `DedupMode:
dakera.DedupModeMerge`; `DedupModeReport` only counts duplicates), a memory folded into a duplicate,
or merged by consolidation, stays restorable for `TrashRetentionHours`:

```go
list, err := client.ListDeduplicated(ctx, "my-agent")
for _, m := range list.Memories {
    fmt.Println(m.ID, m.Kind, "->", m.SurvivorID, "restorable until", m.RestorableUntil)
}
mem, err := client.RestoreDeduplicated(ctx, "my-agent", list.Memories[0].ID) // 404: no copy, 409: id taken again
```

The audit log records `deduplicated` and `restored` events with a `Reason`. `GetMemory(ctx, "", id)`
finds a memory without its agent id when exactly one agent your key can read holds it.

### Recall: at most `TopK` results, context apart

A recall also returns *neighbourhood context*: memories written in the same session within a few
minutes of the top results. By default (server `DAKERA_NEIGHBORHOOD_MODE=inline`) they follow the
ranked results in `Memories`, so `len(resp.Memories)` can exceed `TopK`; each one has
`IsNeighborhood()` true and a `Score` that is not comparable with the ranked results'. Ask for
`NeighborhoodModeSeparate` to keep `Memories` to at most `TopK` ranked results and get the context
in `ContextMemories` (each with `ContextOf`, the id of the ranked memory it belongs to):

```go
resp, err := client.Recall(ctx, "my-agent", dakera.RecallRequest{
    Query:            "where does Alice live?",
    TopK:             3,
    NeighborhoodMode: dakera.NeighborhoodModeSeparate, // or NeighborhoodModeInline / NeighborhoodModeOff
})
for _, m := range resp.Memories { // at most 3
    fmt.Println(m.ID, m.Score, m.MatchedText) // MatchedText / MatchedIDs: see below
}
for _, c := range resp.ContextMemories {
    fmt.Println("context of", c.ContextOf, ":", c.Content)
}
```

`IncludeSummaries` (`*bool`) says whether session summaries may be recalled (unset: the server's
choice). When the server collapses derived sentence sub-memories into their source
(`DAKERA_RECALL_COLLAPSE_DERIVED`), a result is the source memory with `MatchedIDs` (the sentences
that matched, best first) and `MatchedText` (the best sentence, when it outranked the source's own
text); search results carry the same fields (`SearchMemoriesDetailed` also returns `TotalCount`,
`RerankReport` and `EffectiveTopK`). Every new field is omitted from requests unless set and is
optional in answers, so older servers keep working (they ignore `NeighborhoodMode` and answer
inline).

### Document import (server v0.12.3+)

A PDF, DOCX, HTML, Markdown or text document becomes a set of *chunk memories* of an agent:
ordinary memories, each sized for the embedding model, carrying its heading breadcrumb and its
provenance (`_dakera_document`: document id, title, pages, heading path). Recall, search and
filters treat them as memories; a result can cite the document, page and section.

```go
// Text, Markdown or HTML given inline
acc, err := client.ImportDocument(ctx, dakera.ImportDocumentRequest{
    AgentID:   "docs-bot",
    Content:   markdown,
    MediaType: dakera.MediaTypeMarkdown,
    DocumentImportOptions: dakera.DocumentImportOptions{
        Tags:     []string{"manual"},
        Chunking: &dakera.ChunkingOptions{Strategy: dakera.ChunkStrategyStructure},
    },
})
// A PDF / DOCX: upload it as an attachment, then import it
up, _ := client.UploadAttachment(ctx, "library", pdfBytes, dakera.MediaTypePDF)
acc, err = client.ImportAttachmentDocument(ctx, "library", up.AttachmentRef,
    dakera.ImportAttachmentDocumentRequest{AgentID: "docs-bot", DocumentID: "manual-v3"})

// The import is a job
job, err := client.WaitForDocumentJob(ctx, "docs-bot", acc.JobID, dakera.JobWaitOptions{Timeout: 5 * time.Minute})

// Cite where a recalled chunk comes from
for _, m := range resp.Memories {
    if doc := m.DocumentChunk(); doc != nil {
        fmt.Println(doc.Title, doc.HeadingPath, doc.PageStart)
    }
}
```

`ListDocuments` (cursor paging), `GetDocument` (a document and its chunks) and `DeleteDocument`
complete the surface. `Capabilities(ctx)` reports `Documents` (`SupportsDocuments()`, limits,
media types). A server with `DAKERA_DOCUMENTS` off answers `501` (`*FeatureDisabledError`); a
server older than v0.12.3 answers `404` (`*NotFoundError`, whose message says so). A failed job
(`*JobFailedError`) carries the status and code: `413` (too big / too many chunks), `422`
(`UNPROCESSABLE_CONTENT`), `504` (`EXTRACTION_TIMEOUT`).

### Text auto-embedding

Send raw text without pre-computing embeddings — Dakera embeds server-side:

```go
client.UpsertText(ctx, "my-namespace", []dakera.TextInput{
    {ID: "doc1", Text: "Agent completed onboarding flow successfully"},
})
```

---

## Features

- **Agent Memory** — store, recall, search, and forget memories with importance scoring
- **Sessions** — group memories by conversation with auto-consolidation on session end
- **Knowledge Graph** — traverse memory relationships, find paths, export graphs
- **Vector Search** — ANN queries with metadata filters and batch operations
- **Full-Text Search** — BM25 ranking with stemming and stop-word filtering
- **Hybrid Search** — combine vector similarity with keyword matching
- **Text Auto-Embedding** — server-side embedding generation (no local model needed)
- **Namespaces** — isolated vector stores per project, tenant, or use case
- **Feedback Loop** — upvote/downvote/flag memories to improve recall quality
- **T-I-F Reliability** — `TifScore` struct and `EvaluateTif()` for Truth-Indeterminacy-Falsity scoring of memory reliability
- **Entity Extraction** — GLiNER NER for automatic entity detection
- **SSE Streaming** — Server-sent event subscriptions for real-time memory updates
- **Typed Filters** — `Eq()`, `Gt()`, `Contains()`, `ArrayContains()` and more
- **Context-Based** — all methods accept `context.Context` for cancellation and timeouts
- **Retry & Rate Limiting** — built-in exponential backoff and rate-limit header tracking
- **Zero Dependencies** — standard library `net/http` client, no external runtime deps

---

## Connect to Dakera

```go
// Self-hosted
client := dakera.NewClientWithOptions(dakera.ClientOptions{
    BaseURL: "http://your-server:3000",
    APIKey:  "your-key",
})

// Cloud (early access)
client := dakera.NewClientWithOptions(dakera.ClientOptions{
    BaseURL: "http://<your-server-ip>:3000",
    APIKey:  "your-key",
})

// With custom retry config
client := dakera.NewClientWithOptions(dakera.ClientOptions{
    BaseURL:     "http://localhost:3000",
    APIKey:      "your-key",
    RetryBackoff: &dakera.RetryConfig{MaxRetries: 5, BaseDelay: 200 * time.Millisecond, MaxDelay: 30 * time.Second, Jitter: true},
})
```

Defaults: a 30 s request timeout (`Timeout`, also the connect and response-header timeout unless
`ConnectTimeout` is set) and Go's TLS defaults (TLS 1.2+, system roots, verification on). Event
streams have no overall timeout (cancel their `ctx`).

**Proxies (since v0.12.3)**: the default transport is a clone of `http.DefaultTransport`, so the
client honours the `HTTPS_PROXY`, `HTTP_PROXY` and `NO_PROXY` environment variables like any Go HTTP
client (before v0.12.3 it ignored them). To opt out, set `NO_PROXY` for the Dakera host, or pass your
own transport with `Proxy: nil`:

```go
t := http.DefaultTransport.(*http.Transport).Clone()
t.Proxy = nil // never use a proxy
client := dakera.NewClientWithOptions(dakera.ClientOptions{BaseURL: "http://localhost:3000", Transport: t})
```

Retries: `MaxRetries` is the number of attempts. `429` and `503` (honouring
`Retry-After`) and connection failures before the request was sent are retried for every request;
other `5xx` answers and dropped connections are retried only for requests that cannot apply a write
twice (`GET`, `PUT`, `DELETE`, recall, search and the query routes), never for a write `POST` such
as `StoreMemory`. The API key is never printed: `Client` and `ClientOptions` redact it in `%v`,
`%+v` and `%#v`. `OdeExtractEntities` requests to the ODE sidecar (`OdeURL`) currently carry the
Dakera API key; tracked in [Dakera-AI/dakera#924](https://github.com/Dakera-AI/dakera/issues/924).

`OpsShutdown` (`POST /ops/shutdown`) needs a global **`super_admin`** key; an `admin` key gets a
`403` (`*AuthorizationError`) from servers v0.12.3 and later.

---

## What's new in v0.12.2

SDK v0.12.2 targets **Dakera server v0.12.2** and stays **compatible with v0.12.0 and v0.12.1
servers**: new request fields are omitted unless you set them, new response fields are optional
(`nil` / empty on an older server), and the new routes answer `404` there. Check
`caps.Auth`, `caps.Sessions` (or `SupportsKeyUpdate()`, `SupportsSessionTouch()`) to see what the
connected server has.

| Feature | API |
|---|---|
| Create an agent before its first memory | `CreateAgent(ctx, "mlx-dev")` (`Created` is false for an existing agent) |
| Edit a key's name or namespaces | `UpdateKey`, `UpdateNamespaceKey` with `UpdateKeyRequest{Namespaces: dakera.GrantNamespaces("team-*")}` (`nil` = unchanged, `GrantAllNamespaces()` = `null`, `GrantNamespaces()` = `[]`) |
| Rotate with a grace period | `RotateKeyWithOptions(ctx, id, &dakera.RotateKeyOptions{GraceSecs: &grace})` → `OldKeyID`, `OldKeyExpiresAt` |
| Who am I | `Whoami(ctx)` — scope, grants, `Unrestricted`, `GrantsVersion`, `InertNamespaces` |
| Namespace kinds | `ListNamespacesWithKinds`, `NamespaceInfo.Kind` |
| Session idle lifecycle | `StartSessionRequest.IdleTimeoutSecs`, `TouchSession`, `Session.EndedReason` / `LastActivityAt` / `IdleSince`, `StoreMemoryResponse.SessionState`, `BatchStoreMemoryResponse.EndedSessions`, `SetSessionIdleTimeout` |
| Derived records | `IncludeDerived` on `AgentMemoriesOptions` and `WakeUpOptions`; `AdminDerivationStatus`, `AdminDrainDerivations` |
| Content previews | `ContentPreviewChars` on `AgentMemoriesOptions`, `SessionMemoriesOptions`, `FullKnowledgeGraphRequest`, `CrossAgentNetworkRequest` → `ContentLen`, `ContentTruncated` |

```go
// A developer key that may create and use its own agents (prefix grant).
key, _ := client.CreateKey(ctx, dakera.CreateKeyRequest{
    Name: "dev", Scope: dakera.KeyScopeWrite,
    Namespaces: dakera.GrantNamespaces("_dakera_agent_mlx-*"),
})
_ = key // key.Key is shown once: store it in your secret manager, never in code

// A session the server never ends for inactivity.
zero := 0
sess, _ := client.StartSession(ctx, dakera.StartSessionRequest{AgentID: "mlx-dev", IdleTimeoutSecs: &zero})

// A list view: 200-character previews, full text only when needed.
preview := 200
mems, _ := client.AgentMemories(ctx, "mlx-dev", &dakera.AgentMemoriesOptions{ContentPreviewChars: &preview})
for _, m := range mems {
    if m.ContentTruncated != nil && *m.ContentTruncated {
        full, _ := client.GetMemory(ctx, "mlx-dev", m.ID)
        _ = full
    }
}
_ = sess
```

Behaviour changes in server v0.12.2 that clients can hit:

- **Sessions end after 4 hours without activity** by default (`DAKERA_SESSION_IDLE_TIMEOUT_SECS`).
  Activity is a memory stored, batch-stored, imported or updated with the session, a
  session-scoped recall or search, or `TouchSession`. Storing into an ended session still
  succeeds: check `StoreMemoryResponse.SessionState` / `BatchStoreMemoryResponse.EndedSessions`
  and start a new session when it says `ended`.
- **Sessions are authorized by their agent**: keys no longer need a `_dakera_sessions` grant (it
  is accepted and inert), a key without grants lists no sessions, and `EndSession` with a Read key
  gets `403`.
- **Stricter validation (400, the field named in the message)**: invalid key grants (`a**b`,
  blank entries, internal namespaces), a client-set `dakera-curated` tag, `_dakera_*` metadata
  keys other than `_dakera_content_date` / `_dakera_lang`, ids of the form `mem_s` + 24 hex, agent
  ids over 241 bytes, TTLs over 100 years.
- **The content limit is in bytes** (UTF-8, `DAKERA_MAX_MEMORY_CONTENT_BYTES`, 100000 by default)
  and `UpdateMemory` enforces it too.
- **Listings exclude derived records**: `AgentMemories` and `GetWakeUpContext` leave CE-31
  sentence sub-memories out unless `IncludeDerived` is set.
- **Legacy `foo*` grants stay inert** on keys created before v0.12.2 (`GrantsVersion` 0,
  `InertNamespaces`) until the key's namespaces are saved again with `UpdateKey`.

---

## What's new in v0.12.0

SDK v0.12.0 targets **Dakera server v0.12.0** and is **compatible with both v0.11.108 and
v0.12.0 servers**: every new request field is omitted from the wire unless you set it, and the
new routes only exist on a v0.12 server (see the table below). Operator guide for the server

Frequently Asked Questions

What is dakera-go?

dakera-go is a Artificial Intelligence library for the Go programming language. Official Go client SDK for the Dakera self-hosted agent memory server, providing typed interfaces for memory store/recall, session management, namespace operations, and decay configuration

How do I install dakera-go?

Install dakera-go with the Go module system using `go get dakera-ai/dakera-go`. Check the repository for the current installation instructions.

What category does dakera-go belong to?

dakera-go is listed under Artificial Intelligence, specifically Artificial Intelligence.

← Back to Artificial Intelligence