storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SurrealDB *surrealdb.DB
	Redis     *redis.Client
	// contains filtered or unexported fields
}

Client represents the storage client that manages connections to SurrealDB and Redis

func NewClient

func NewClient(cfg *config.Config) (*Client, error)

NewClient creates a new storage client with connections to SurrealDB and Redis

func (*Client) Close

func (c *Client) Close() error

Close gracefully closes all database connections

func (*Client) ExecuteRedisCommand

func (c *Client) ExecuteRedisCommand(ctx context.Context, cmd string, args ...interface{}) *redis.Cmd

ExecuteRedisCommand executes a Redis command

func (*Client) ExecuteSurrealQL

func (c *Client) ExecuteSurrealQL(query string, vars map[string]interface{}) (interface{}, error)

ExecuteSurrealQL executes a SurrealQL query

func (*Client) GetConfig

func (c *Client) GetConfig() *config.Config

GetConfig returns the configuration

func (*Client) GetRedis

func (c *Client) GetRedis() *redis.Client

GetRedis returns the Redis connection

func (*Client) GetSurrealDB

func (c *Client) GetSurrealDB() *surrealdb.DB

GetSurrealDB returns the SurrealDB connection

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks the health of all storage connections

func (*Client) IsRedisConnected

func (c *Client) IsRedisConnected() bool

IsRedisConnected checks if Redis is connected

func (*Client) IsSurrealDBConnected

func (c *Client) IsSurrealDBConnected() bool

IsSurrealDBConnected checks if SurrealDB is connected

func (*Client) Reconnect

func (c *Client) Reconnect() error

Reconnect attempts to reconnect to all storage systems

type CountFilters

type CountFilters struct {
	SessionID types.SessionID   `json:"session_id,omitempty"`
	TimeRange *models.TimeRange `json:"time_range,omitempty"`
	Processed *bool             `json:"processed,omitempty"`
}

CountFilters represents filters for counting episodes

type EpisodeStats

type EpisodeStats struct {
	TotalEpisodes          int       `json:"total_episodes"`
	ProcessedEpisodes      int       `json:"processed_episodes"`
	UnprocessedEpisodes    int       `json:"unprocessed_episodes"`
	EpisodesWithEmbeddings int       `json:"episodes_with_embeddings"`
	UniqueSessions         int       `json:"unique_sessions"`
	LastUpdated            time.Time `json:"last_updated"`
}

EpisodeStats represents statistics about episodes

type EpisodeStore

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

EpisodeStore provides CRUD operations for episodes

func NewEpisodeStore

func NewEpisodeStore(client *Client) *EpisodeStore

NewEpisodeStore creates a new episode store

func (*EpisodeStore) BatchCreate

func (s *EpisodeStore) BatchCreate(ctx context.Context, episodes []*models.Episode) error

BatchCreate creates multiple episodes in a single transaction

func (*EpisodeStore) Count

func (s *EpisodeStore) Count(ctx context.Context, tenantID types.TenantID, filters *CountFilters) (int, error)

Count returns the total number of episodes for a tenant

func (*EpisodeStore) Create

func (s *EpisodeStore) Create(ctx context.Context, episode *models.Episode) error

Create creates a new episode in the database

func (*EpisodeStore) Delete

func (s *EpisodeStore) Delete(ctx context.Context, tenantID types.TenantID, episodeID string) error

Delete deletes an episode by its ID

func (*EpisodeStore) GetByID

func (s *EpisodeStore) GetByID(ctx context.Context, tenantID types.TenantID, episodeID string) (*models.Episode, error)

GetByID retrieves an episode by its ID

func (*EpisodeStore) GetBySessionID

func (s *EpisodeStore) GetBySessionID(ctx context.Context, tenantID types.TenantID, sessionID types.SessionID, limit, offset int) ([]*models.Episode, error)

GetBySessionID retrieves episodes for a specific session

func (*EpisodeStore) GetStats

func (s *EpisodeStore) GetStats(ctx context.Context, tenantID types.TenantID) (*EpisodeStats, error)

GetStats returns statistics about episodes for a tenant

func (*EpisodeStore) GetUnprocessed

func (s *EpisodeStore) GetUnprocessed(ctx context.Context, tenantID types.TenantID, limit int) ([]*models.Episode, error)

GetUnprocessed retrieves episodes that haven't been processed for entity extraction

func (*EpisodeStore) List

func (s *EpisodeStore) List(ctx context.Context, tenantID types.TenantID, options *ListOptions) ([]*models.Episode, int, error)

List retrieves episodes with pagination and filtering

func (*EpisodeStore) MarkAsProcessed

func (s *EpisodeStore) MarkAsProcessed(ctx context.Context, tenantID types.TenantID, episodeID string) error

MarkAsProcessed marks an episode as processed for entity extraction

func (*EpisodeStore) Update

func (s *EpisodeStore) Update(ctx context.Context, tenantID types.TenantID, episodeID string, updates *models.EpisodeUpdateRequest) (*models.Episode, error)

Update updates an existing episode

func (*EpisodeStore) UpdateEmbedding

func (s *EpisodeStore) UpdateEmbedding(ctx context.Context, tenantID types.TenantID, episodeID string, embedding []float32) error

UpdateEmbedding updates the embedding for an episode

type GraphStats

type GraphStats struct {
	TotalEntities      int            `json:"total_entities"`
	TotalRelationships int            `json:"total_relationships"`
	EntityTypes        map[string]int `json:"entity_types"`
	RelationshipTypes  map[string]int `json:"relationship_types"`
	LastUpdated        time.Time      `json:"last_updated"`
}

GraphStats represents statistics about the knowledge graph

type GraphStore

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

GraphStore provides operations for managing the knowledge graph

func NewGraphStore

func NewGraphStore(client *Client) *GraphStore

NewGraphStore creates a new graph store

func (*GraphStore) BatchCreateEntities

func (s *GraphStore) BatchCreateEntities(ctx context.Context, entities []*models.Entity) error

BatchCreateEntities creates multiple entities in a single transaction

func (*GraphStore) BatchCreateRelationships

func (s *GraphStore) BatchCreateRelationships(ctx context.Context, relationships []*models.Relationship) error

BatchCreateRelationships creates multiple relationships in a single transaction

func (*GraphStore) CreateEntity

func (s *GraphStore) CreateEntity(ctx context.Context, entity *models.Entity) error

CreateEntity creates a new entity in the knowledge graph

func (*GraphStore) CreateRelationship

func (s *GraphStore) CreateRelationship(ctx context.Context, relationship *models.Relationship) error

CreateRelationship creates a relationship between two entities

func (*GraphStore) DeleteEntity

func (s *GraphStore) DeleteEntity(ctx context.Context, tenantID types.TenantID, entityID string) error

DeleteEntity deletes an entity and all its relationships

func (*GraphStore) DeleteRelationship

func (s *GraphStore) DeleteRelationship(ctx context.Context, tenantID types.TenantID, relationshipID string) error

DeleteRelationship deletes a specific relationship

func (*GraphStore) FindEntityByName

func (s *GraphStore) FindEntityByName(ctx context.Context, tenantID types.TenantID, name, entityType string) (*models.Entity, error)

FindEntityByName finds an entity by name and type

func (*GraphStore) GetEntityRelationships

func (s *GraphStore) GetEntityRelationships(ctx context.Context, tenantID types.TenantID, entityID string, direction RelationshipDirection) ([]*models.Relationship, error)

GetEntityRelationships gets all relationships for an entity

func (*GraphStore) GetGraphStats

func (s *GraphStore) GetGraphStats(ctx context.Context, tenantID types.TenantID) (*GraphStats, error)

GetGraphStats returns statistics about the knowledge graph

func (*GraphStore) GetOrCreateEntity

func (s *GraphStore) GetOrCreateEntity(ctx context.Context, tenantID types.TenantID, name, entityType string) (*models.Entity, error)

GetOrCreateEntity gets an existing entity or creates a new one if it doesn't exist

func (*GraphStore) GetRelatedEntities

func (s *GraphStore) GetRelatedEntities(ctx context.Context, tenantID types.TenantID, entityID string, relationType string, direction RelationshipDirection, limit int) ([]*models.RelatedEntity, error)

GetRelatedEntities gets entities related to a given entity

func (*GraphStore) RelateEntities

func (s *GraphStore) RelateEntities(ctx context.Context, tenantID types.TenantID, fromEntityID, toEntityID, relationType string, properties map[string]interface{}) error

RelateEntities creates a relationship between two entities by their IDs

func (*GraphStore) RelationshipExists

func (s *GraphStore) RelationshipExists(ctx context.Context, tenantID types.TenantID, fromEntityID, toEntityID, relationType string) (bool, error)

RelationshipExists checks if a relationship already exists between two entities

type ListOptions

type ListOptions struct {
	Limit     int               `json:"limit"`
	Offset    int               `json:"offset"`
	SessionID types.SessionID   `json:"session_id,omitempty"`
	TimeRange *models.TimeRange `json:"time_range,omitempty"`
	Processed *bool             `json:"processed,omitempty"`
	OrderBy   string            `json:"order_by,omitempty"` // "event_time", "tx_time", "created_at"
	OrderDesc bool              `json:"order_desc,omitempty"`
}

ListOptions represents options for listing episodes

type RelationshipDirection

type RelationshipDirection string

RelationshipDirection represents the direction of relationships to query

const (
	RelationshipDirectionOutgoing RelationshipDirection = "outgoing"
	RelationshipDirectionIncoming RelationshipDirection = "incoming"
	RelationshipDirectionBoth     RelationshipDirection = "both"
)

Jump to

Keyboard shortcuts

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