Go SDK

Official Go SDK for Memoid. Install, configure, and integrate AI memory, semantic search, and knowledge graphs into Go applications.

Installation

go get github.com/memoid/memoid-go

Quick Start

package main

import (
    "fmt"
    "github.com/memoid/memoid-go"
)

func main() {
    client := memoid.NewClient("your-api-key")

    // Add a memory
    client.Add([]memoid.Message{
        {Role: "user", Content: "I love hiking and Italian food"},
    }, &memoid.AddOptions{UserID: "user_123"})

    // Search memories
    results, _ := client.Search("What food?", &memoid.SearchOptions{
        UserID: "user_123",
        Limit:  5,
    })

    for _, r := range results {
        fmt.Printf("%s (score: %.2f)\n", r.Memory, r.Score)
    }

    // Recall context
    context, _ := client.Recall("Tell me about the user", &memoid.RecallOptions{
        UserID:       "user_123",
        IncludeGraph: true,
    })
    fmt.Println(context.Memories)
    fmt.Println(context.Entities)
}

Configuration

client := memoid.NewClient("your-api-key", memoid.WithBaseURL("https://api.memoid.dev"))

Memories

// Add
memories, _ := client.Add(messages, &memoid.AddOptions{
    UserID:       "user_123",
    ExtractGraph: true,
})

// Get
memory, _ := client.Get("memory_id")

// List
memories, _ := client.GetAll(&memoid.GetAllOptions{UserID: "user_123"})

// Update
client.Update("memory_id", "Updated text", nil)

// Delete
client.Delete("memory_id")
client.DeleteAll(&memoid.DeleteAllOptions{UserID: "user_123"})

// History
history, _ := client.History("memory_id")

Search

results, _ := client.Search("food preferences", &memoid.SearchOptions{
    UserID:    "user_123",
    Limit:     5,
    Threshold: 0.7,
})

Recall

context, _ := client.Recall("What do I know about John?", &memoid.RecallOptions{
    UserID:       "user_123",
    IncludeGraph: true,
    MemoryLimit:  10,
})

// context.Memories       - relevant memories
// context.Entities       - related graph entities
// context.Relationships  - entity relationships

User Context

Get all memories and graph data for a user — ideal for UI visualization.

context, _ := client.GetUserContext(&memoid.UserContextOptions{
    UserID: "user_123",
})

fmt.Println(context.Memories)
fmt.Println(context.Entities)
fmt.Println(context.Relationships)
fmt.Println(context.Stats) // TotalMemories, TotalEntities, TotalRelationships

Knowledge Graph

// Extract knowledge
result, _ := client.ExtractKnowledge("Sarah is the CEO of TechCorp.", nil)

// Add entity & relationship
client.AddEntity("Acme Corp", "organization", "")
client.AddRelationship("John", "person", "works_at", "Acme Corp", "organization", "")

// Query & search
related, _ := client.GraphQuery("John", 2)
found, _ := client.GraphSearch("tech companies", 20)

// Delete entity
client.DeleteEntity("John")

REST API

All SDK methods map to REST endpoints. You can also use net/http directly:

req, _ := http.NewRequest("POST", "https://api.memoid.dev/v1/recall", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")