memory

package
v0.59.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Memory storage security limits
	DefaultMaxStorageSize          = int64(500 * 1024 * 1024) // 500MB default storage limit
	DefaultDataRetentionDays       = 180                      // 180 days default retention
	MemoryMaxStorageSizeEnvVar     = "MEMORY_MAX_STORAGE_SIZE"
	MemoryDataRetentionDaysEnvVar  = "MEMORY_DATA_RETENTION_DAYS"
	MemoryEncryptionPasswordEnvVar = "MEMORY_ENCRYPTION_PASSWORD"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddObservationsRequest

type AddObservationsRequest struct {
	Observations []ObservationInput `json:"observations"`
}

AddObservationsRequest represents the input for adding observations

type AddObservationsResponse

type AddObservationsResponse struct {
	Results   []ObservationResult `json:"results"`
	Timestamp time.Time           `json:"timestamp"`
}

AddObservationsResponse represents the output of adding observations

type CreateEntitiesRequest

type CreateEntitiesRequest struct {
	Entities []Entity `json:"entities"`
}

CreateEntitiesRequest represents the input for creating entities

type CreateEntitiesResponse

type CreateEntitiesResponse struct {
	CreatedEntities []Entity  `json:"createdEntities"`
	Timestamp       time.Time `json:"timestamp"`
}

CreateEntitiesResponse represents the output of creating entities

type CreateRelationsRequest

type CreateRelationsRequest struct {
	Relations []Relation `json:"relations"`
}

CreateRelationsRequest represents the input for creating relations

type CreateRelationsResponse

type CreateRelationsResponse struct {
	CreatedRelations []Relation `json:"createdRelations"`
	Timestamp        time.Time  `json:"timestamp"`
}

CreateRelationsResponse represents the output of creating relations

type DeleteEntitiesRequest

type DeleteEntitiesRequest struct {
	EntityNames []string `json:"entityNames"`
}

DeleteEntitiesRequest represents the input for deleting entities

type DeleteObservationsRequest

type DeleteObservationsRequest struct {
	Deletions []ObservationDeletion `json:"deletions"`
}

DeleteObservationsRequest represents the input for deleting observations

type DeleteRelationsRequest

type DeleteRelationsRequest struct {
	Relations []Relation `json:"relations"`
}

DeleteRelationsRequest represents the input for deleting relations

type Entity

type Entity struct {
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
}

Entity represents a node in the knowledge graph with a name, type, and observations

type GraphManager

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

GraphManager handles knowledge graph operations

func NewGraphManager

func NewGraphManager(logger *logrus.Logger) (*GraphManager, error)

NewGraphManager creates a new graph manager instance with default namespace

func NewGraphManagerWithNamespace

func NewGraphManagerWithNamespace(logger *logrus.Logger, namespace string) (*GraphManager, error)

NewGraphManagerWithNamespace creates a new graph manager instance with specified namespace

func (*GraphManager) AddObservations

func (gm *GraphManager) AddObservations(observations []ObservationInput) ([]ObservationResult, error)

AddObservations adds new observations to existing entities

func (*GraphManager) CreateEntities

func (gm *GraphManager) CreateEntities(entities []Entity) ([]Entity, error)

CreateEntities creates new entities, ignoring duplicates

func (*GraphManager) CreateRelations

func (gm *GraphManager) CreateRelations(relations []Relation) ([]Relation, error)

CreateRelations creates new relations, skipping duplicates

func (*GraphManager) DeleteEntities

func (gm *GraphManager) DeleteEntities(entityNames []string) error

DeleteEntities deletes entities and cascades to remove related relations

func (*GraphManager) DeleteObservations

func (gm *GraphManager) DeleteObservations(deletions []ObservationDeletion) error

DeleteObservations deletes specific observations from entities

func (*GraphManager) DeleteRelations

func (gm *GraphManager) DeleteRelations(relations []Relation) error

DeleteRelations deletes specific relations

func (*GraphManager) GetStorageInfo

func (gm *GraphManager) GetStorageInfo() (string, bool, error)

GetStorageInfo returns information about the storage

func (*GraphManager) OpenNodes

func (gm *GraphManager) OpenNodes(names []string) (*KnowledgeGraph, error)

OpenNodes retrieves specific entities by name

func (*GraphManager) ReadGraph

func (gm *GraphManager) ReadGraph() (*KnowledgeGraph, error)

ReadGraph returns the complete knowledge graph

func (*GraphManager) SearchNodes

func (gm *GraphManager) SearchNodes(query string) (*KnowledgeGraph, []SearchResult, error)

SearchNodes searches for nodes based on a query string

func (*GraphManager) SetNamespace

func (gm *GraphManager) SetNamespace(namespace string) error

SetNamespace changes the namespace for this graph manager

type KnowledgeGraph

type KnowledgeGraph struct {
	Entities  []Entity   `json:"entities"`
	Relations []Relation `json:"relations"`
}

KnowledgeGraph represents the complete graph structure

type MemoryOperationResponse

type MemoryOperationResponse struct {
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
}

MemoryOperationResponse represents a generic response for operations that don't return specific data

type MemoryTool

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

MemoryTool implements the MCP memory tool for knowledge graph operations

func (*MemoryTool) Definition

func (m *MemoryTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*MemoryTool) Execute

func (m *MemoryTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)

Execute executes the memory tool operations

func (*MemoryTool) ProvideExtendedInfo added in v0.22.0

func (m *MemoryTool) ProvideExtendedInfo() *tools.ExtendedHelp

ProvideExtendedInfo provides detailed usage information for the memory tool

type ObservationDeletion

type ObservationDeletion struct {
	EntityName   string   `json:"entityName"`
	Observations []string `json:"observations"`
}

ObservationDeletion represents observations to delete from a specific entity

type ObservationInput

type ObservationInput struct {
	EntityName string   `json:"entityName"`
	Contents   []string `json:"contents"`
}

ObservationInput represents observations to add to a specific entity

type ObservationResult

type ObservationResult struct {
	EntityName        string   `json:"entityName"`
	AddedObservations []string `json:"addedObservations"`
}

ObservationResult represents the result of adding observations to an entity

type OpenNodesRequest

type OpenNodesRequest struct {
	Names []string `json:"names"`
}

OpenNodesRequest represents the input for opening specific nodes

type Relation

type Relation struct {
	From         string `json:"from"`
	To           string `json:"to"`
	RelationType string `json:"relationType"`
}

Relation represents a directed connection between two entities

type SearchNodesRequest

type SearchNodesRequest struct {
	Query string `json:"query"`
}

SearchNodesRequest represents the input for searching nodes

type SearchNodesResponse

type SearchNodesResponse struct {
	Graph     KnowledgeGraph `json:"graph"`
	Results   []SearchResult `json:"results,omitempty"`
	Query     string         `json:"query"`
	Timestamp time.Time      `json:"timestamp"`
}

SearchNodesResponse represents the output of searching nodes

type SearchResult

type SearchResult struct {
	Entity    Entity  `json:"entity"`
	Score     float64 `json:"score,omitempty"`
	MatchType string  `json:"matchType,omitempty"` // "exact", "fuzzy", "partial"
}

SearchResult represents search results with relevance scoring

type Storage

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

Storage handles file I/O operations for the knowledge graph

func NewStorage

func NewStorage(logger *logrus.Logger) (*Storage, error)

NewStorage creates a new storage instance with the configured file path and default namespace

func NewStorageWithNamespace

func NewStorageWithNamespace(logger *logrus.Logger, namespace string) (*Storage, error)

NewStorageWithNamespace creates a new storage instance with the specified namespace

func (*Storage) BackupFile

func (s *Storage) BackupFile() error

BackupFile creates a backup of the current memory file

func (*Storage) FileExists

func (s *Storage) FileExists() bool

FileExists checks if the memory file exists

func (*Storage) GetFileInfo

func (s *Storage) GetFileInfo() (os.FileInfo, error)

GetFileInfo returns information about the memory file

func (*Storage) GetFilePath

func (s *Storage) GetFilePath() string

GetFilePath returns the configured file path

func (*Storage) LoadGraph

func (s *Storage) LoadGraph() (*KnowledgeGraph, error)

LoadGraph loads the complete knowledge graph from storage

func (*Storage) SaveGraph

func (s *Storage) SaveGraph(graph *KnowledgeGraph) error

SaveGraph saves the complete knowledge graph to storage using atomic operations

func (*Storage) SetNamespace

func (s *Storage) SetNamespace(namespace string) error

SetNamespace changes the namespace for this storage instance

type StoredEntity

type StoredEntity struct {
	Type         string   `json:"type"`
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
}

StoredEntity represents an entity as stored in JSONL format

type StoredRelation

type StoredRelation struct {
	Type         string `json:"type"`
	From         string `json:"from"`
	To           string `json:"to"`
	RelationType string `json:"relationType"`
}

StoredRelation represents a relation as stored in JSONL format

Jump to

Keyboard shortcuts

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