go-client

command
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

README

Using Cortex as a Go Library

This example demonstrates how to use Cortex programmatically in your own Go applications.

Overview

While Cortex is primarily designed as an MCP server, you can also use its engines directly in Go applications for:

  • Building custom memory-enabled applications
  • Integrating with existing Go services
  • Creating specialized AI agent backends

Installation

go get github.com/petal-labs/cortex

Example: Simple Knowledge Store

See main.go for a complete example that demonstrates:

  1. Initializing the SQLite storage backend
  2. Creating a knowledge engine
  3. Ingesting documents with chunking
  4. Searching with hybrid search

Running the Example

cd examples/go-client
go run main.go

Key Concepts

Storage Backend

Cortex supports two storage backends:

import "github.com/petal-labs/cortex/internal/storage/sqlite"

// SQLite (local, zero-config)
store, err := sqlite.New(sqlite.Config{
    Path: "./cortex.db",
})
Embedding Provider

For semantic search, you need an embedding provider:

import "github.com/petal-labs/cortex/internal/embedding"

// Using Iris embedding service
provider := embedding.NewIrisProvider(embedding.IrisConfig{
    Endpoint:   "http://localhost:8000",
    Dimensions: 1536,
})
Engines

Each memory primitive has its own engine:

import (
    "github.com/petal-labs/cortex/internal/knowledge"
    "github.com/petal-labs/cortex/internal/conversation"
    "github.com/petal-labs/cortex/internal/context"
    "github.com/petal-labs/cortex/internal/entity"
)

Architecture

Your Application
       │
       ▼
┌──────────────────┐
│  Cortex Engines  │
│  - Knowledge     │
│  - Conversation  │
│  - Context       │
│  - Entity        │
└────────┬─────────┘
         │
         ▼
┌──────────────────┐
│ Storage Backend  │
│ (SQLite/pgvector)│
└──────────────────┘

Notes

  • The internal/ packages are not guaranteed to have a stable API
  • For production use, consider using the MCP interface instead
  • CGO is required for SQLite support

Documentation

Overview

Example: Using Cortex as a Go library

This example demonstrates how to use Cortex's knowledge store programmatically in your own Go applications.

Run with: go run main.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL