Help us shape the future of Go! Take the 2026 Go Developer Survey

mem0

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MemorySystemPrefix = "[mem0-memory-context]"

Variables

This section is empty.

Functions

func FormatMemoryContext

func FormatMemoryContext(items []SearchItem, limit int) string

FormatMemoryContext turns search results into a dynamic context payload.

Types

type AddRequest

type AddRequest struct {
	Messages  []ClientMessage
	UserID    string
	RunID     string
	AgentID   string
	AppID     string
	OrgID     string
	ProjectID string
	Metadata  map[string]any
}

AddRequest is the normalized input for storing one memory turn.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a small HTTP client for mem0-compatible APIs.

func NewClient

func NewClient(config *ProviderConfig) *Client

NewClient creates a client from a normalized provider config.

func (*Client) Add

func (c *Client) Add(ctx context.Context, req AddRequest) error

Add stores one memory turn in the configured backend.

func (*Client) Search

func (c *Client) Search(ctx context.Context, req SearchRequest) ([]SearchItem, error)

Search retrieves relevant memories from the configured backend.

type ClientMessage

type ClientMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

ClientMessage is the message format accepted by mem0-compatible APIs.

type Mode

type Mode string

Mode identifies which mem0-compatible API surface the provider should target.

const (
	ModeHosted Mode = "hosted"
	ModeOSS    Mode = "oss"
)

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements memory.MemoryProvider backed by a mem0-compatible API.

func NewProvider

func NewProvider(config *ProviderConfig) (*Provider, error)

NewProvider creates a mem0 provider with normalized config defaults.

func (*Provider) Close

func (p *Provider) Close() error

Close releases resources held by the provider. Currently a no-op.

func (*Provider) Memorize

func (p *Provider) Memorize(ctx context.Context, req *memory.MemorizeRequest) error

Memorize persists the latest user + assistant turn into mem0.

func (*Provider) Retrieve

Retrieve fetches relevant mem0 context before a model call.

type ProviderConfig

type ProviderConfig struct {
	BaseURL string

	Mode       Mode
	APIKey     string
	AuthHeader string
	AuthScheme string

	AddPath    string
	SearchPath string
	Version    string

	HTTPClient *http.Client
	Timeout    time.Duration

	SearchMsgLimit    int
	SearchResultLimit int
	OutputMemoryLimit int
	QueryCharLimit    int

	UseSessionAsRunID  bool
	SearchBySession    bool
	SessionMetadataKey string

	AgentID   string
	AppID     string
	OrgID     string
	ProjectID string

	ExtraHeaders map[string]string
	Metadata     map[string]any
}

ProviderConfig configures the mem0 provider and client behavior.

type SearchItem

type SearchItem struct {
	ID         string
	Memory     string
	Score      float64
	Categories []string
	Metadata   map[string]any
	CreatedAt  string
	UpdatedAt  string
}

SearchItem is the normalized memory item returned from hosted or OSS APIs.

type SearchRequest

type SearchRequest struct {
	Query     string
	UserID    string
	RunID     string
	AgentID   string
	AppID     string
	OrgID     string
	ProjectID string
	Limit     int
	Filters   map[string]any
}

SearchRequest is the normalized input for memory retrieval.

Jump to

Keyboard shortcuts

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