models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package models defines data structures for the storage system.

Package models defines data structures for the storage system.

Package models defines data structures for the storage system. This package contains domain models for knowledge chunks, experiences, tools, conversations, task results, and secrets.

Package models defines data structures for the storage system.

Package models defines data structures for the storage system.

Package models defines data structures for the storage system.

Index

Constants

View Source
const (
	RoleSystem    = "system"
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleTool      = "tool"
)

ConversationRole constants.

View Source
const (
	// ExperienceTypeSuccess represents a successful experience.
	ExperienceTypeSuccess = "success"

	// ExperienceTypeFailure represents a failed experience.
	ExperienceTypeFailure = "failure"

	// ExperienceTypeQuery represents a query-based experience (for backward compatibility).
	ExperienceTypeQuery = "query"

	// ExperienceTypeSolution represents a solution-based experience (for backward compatibility).
	ExperienceTypeSolution = "solution"

	// ExperienceTypePattern represents a pattern-based experience (for backward compatibility).
	ExperienceTypePattern = "pattern"

	// ExperienceTypeDistilled represents a distilled experience (for backward compatibility).
	ExperienceTypeDistilled = "distilled"
)

ExperienceType constants.

View Source
const (
	EmbeddingStatusPending    = "pending"
	EmbeddingStatusProcessing = "processing"
	EmbeddingStatusCompleted  = "completed"
	EmbeddingStatusFailed     = "failed"
)

EmbeddingStatus constants.

View Source
const (
	TaskStatusPending   = "pending"
	TaskStatusRunning   = "running"
	TaskStatusCompleted = "completed"
	TaskStatusFailed    = "failed"
)

TaskStatus constants.

View Source
const (
	AlgorithmAESGCM = "aes-gcm"
)

EncryptionAlgorithm constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conversation

type Conversation struct {
	ID        string    `json:"id"`
	SessionID string    `json:"session_id"`
	TenantID  string    `json:"tenant_id"`
	UserID    string    `json:"user_id"`
	AgentID   string    `json:"agent_id"`
	Role      string    `json:"role"`
	Content   string    `json:"content"`
	ExpiresAt time.Time `json:"expires_at"`
	CreatedAt time.Time `json:"created_at"`
}

Conversation represents a chat message in a conversation session. This stores short-term conversation context without vector embedding.

func (*Conversation) IsExpired

func (c *Conversation) IsExpired() bool

IsExpired checks if the conversation has expired based on TTL.

func (*Conversation) TableName

func (c *Conversation) TableName() string

TableName returns the table name for this model.

type Experience

type Experience struct {
	// ID is the unique identifier of the experience.
	ID string `json:"id"`

	// TenantID is the tenant identifier for multi-tenancy isolation.
	TenantID string `json:"tenant_id"`

	// Type is the type of experience.
	// Valid values: "success" or "failure".
	Type string `json:"type"`

	// Problem is the abstract problem statement.
	// This is the target for embedding generation.
	// NOTE: This field is stored in the 'input' column for backward compatibility.
	Problem string `json:"problem"`

	// Solution is the concise solution approach.
	// NOTE: This field is stored in the 'output' column for backward compatibility.
	Solution string `json:"solution"`

	// Input is the raw input text (stored in database 'input' column).
	// This is for backward compatibility with the database schema.
	Input string `json:"-"`

	// Output is the raw output text (stored in database 'output' column).
	// This is for backward compatibility with the database schema.
	Output string `json:"-"`

	// Constraints are important constraints or context for the solution.
	// NOTE: This field is stored in metadata['constraints'] for backward compatibility.
	Constraints string `json:"constraints"`

	// Embedding is the vector embedding of the problem.
	// This is used for semantic similarity search.
	Embedding []float64 `json:"embedding"`

	// EmbeddingModel is the name of the embedding model used.
	EmbeddingModel string `json:"embedding_model"`

	// EmbeddingVersion is the version of the embedding model.
	EmbeddingVersion int `json:"embedding_version"`

	// Score is the overall score of the experience.
	Score float64 `json:"score"`

	// Success indicates whether the original task was successful.
	Success bool `json:"success"`

	// AgentID is the identifier of the agent that generated this experience.
	AgentID string `json:"agent_id"`

	// UsageCount is the number of times this experience was successfully used.
	// This is used as a reinforcement signal.
	// NOTE: This field is stored in metadata['usage_count'] for backward compatibility.
	UsageCount int `json:"usage_count"`

	// Metadata is additional metadata for the experience.
	// NOTE: For backward compatibility, constraints and usage_count are also stored here.
	Metadata map[string]interface{} `json:"metadata"`

	// DecayAt is the time when this experience should be considered expired.
	// If zero, the experience never expires.
	DecayAt time.Time `json:"decay_at"`

	// CreatedAt is the time when this experience was created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is the time when this experience was last updated.
	UpdatedAt time.Time `json:"updated_at"`
}

Experience represents a distilled task experience. This is the core data structure for experience storage and retrieval. The structure follows the principle: Experience = Distilled Knowledge.

func (*Experience) GetConstraints

func (e *Experience) GetConstraints() string

GetConstraints retrieves constraints from metadata. This provides backward compatibility for the new structure.

func (*Experience) GetUsageCount

func (e *Experience) GetUsageCount() int

GetUsageCount retrieves usage count from metadata. This provides backward compatibility for the new structure.

func (*Experience) IsExpired

func (e *Experience) IsExpired() bool

IsExpired checks if the experience has decayed and should be excluded from search.

func (*Experience) TableName

func (e *Experience) TableName() string

TableName returns the table name for this model.

type KnowledgeChunk

type KnowledgeChunk struct {
	ID               string                 `json:"id"`
	TenantID         string                 `json:"tenant_id"`
	Content          string                 `json:"content"`
	Embedding        []float64              `json:"embedding"`
	EmbeddingModel   string                 `json:"embedding_model"`
	EmbeddingVersion int                    `json:"embedding_version"`
	EmbeddingStatus  string                 `json:"embedding_status"`
	ChunkIndex       int                    `json:"chunk_index"`
	DocumentID       string                 `json:"document_id"`
	SourceType       string                 `json:"source_type"`
	Source           string                 `json:"source"`
	Metadata         map[string]interface{} `json:"metadata"`
	ContentHash      string                 `json:"content_hash"`
	AccessCount      int                    `json:"access_count"`
	CreatedAt        time.Time              `json:"created_at"`
	UpdatedAt        time.Time              `json:"updated_at"`
}

KnowledgeChunk represents a RAG knowledge base entry with vector embedding. This is the core data structure for semantic search and retrieval.

func (*KnowledgeChunk) TableName

func (k *KnowledgeChunk) TableName() string

TableName returns the table name for this model. Different dimensions use different tables to avoid mixing vector spaces.

type Secret

type Secret struct {
	ID         string                 `json:"id"`
	TenantID   string                 `json:"tenant_id"`
	Key        string                 `json:"key"`
	Value      []byte                 `json:"value"`
	KeyVersion int                    `json:"key_version"`
	Algorithm  string                 `json:"algorithm"`
	ExpiresAt  time.Time              `json:"expires_at"`
	Metadata   map[string]interface{} `json:"metadata"`
	CreatedAt  time.Time              `json:"created_at"`
}

Secret represents sensitive data with encryption. This stores API keys, passwords, and other sensitive information with AES-GCM encryption.

func (*Secret) IsExpired

func (s *Secret) IsExpired() bool

IsExpired checks if the secret has expired.

func (*Secret) IsValid

func (s *Secret) IsValid() bool

IsValid checks if the secret is valid and not expired.

func (*Secret) TableName

func (s *Secret) TableName() string

TableName returns the table name for this model.

type TaskResult

type TaskResult struct {
	ID               string                 `json:"id"`
	TenantID         string                 `json:"tenant_id"`
	SessionID        string                 `json:"session_id"`
	TaskType         string                 `json:"task_type"`
	AgentID          string                 `json:"agent_id"`
	Input            map[string]interface{} `json:"input"`
	Output           map[string]interface{} `json:"output"`
	Embedding        []float64              `json:"embedding"`
	EmbeddingModel   string                 `json:"embedding_model"`
	EmbeddingVersion int                    `json:"embedding_version"`
	Status           string                 `json:"status"`
	Error            string                 `json:"error"`
	LatencyMs        int                    `json:"latency_ms"`
	Metadata         map[string]interface{} `json:"metadata"`
	CreatedAt        time.Time              `json:"created_at"`
}

TaskResult represents the execution result of an agent task. This stores task outputs with vector embedding for future reference and learning.

func (*TaskResult) IsFailed

func (t *TaskResult) IsFailed() bool

IsFailed checks if the task execution failed.

func (*TaskResult) IsSuccessful

func (t *TaskResult) IsSuccessful() bool

IsSuccessful checks if the task execution was successful.

func (*TaskResult) TableName

func (t *TaskResult) TableName() string

TableName returns the table name for this model.

type Tool

type Tool struct {
	ID               string                 `json:"id"`
	TenantID         string                 `json:"tenant_id"`
	Name             string                 `json:"name"`
	Description      string                 `json:"description"`
	Embedding        []float64              `json:"embedding"`
	EmbeddingModel   string                 `json:"embedding_model"`
	EmbeddingVersion int                    `json:"embedding_version"`
	AgentType        string                 `json:"agent_type"`
	Tags             []string               `json:"tags"`
	UsageCount       int                    `json:"usage_count"`
	SuccessRate      float64                `json:"success_rate"`
	LastUsedAt       time.Time              `json:"last_used_at"`
	Metadata         map[string]interface{} `json:"metadata"`
	CreatedAt        time.Time              `json:"created_at"`
}

Tool represents an agent tool with semantic embedding for intelligent selection. Tools are stored with embedding to enable semantic matching beyond keyword search.

func (*Tool) IsAvailable

func (t *Tool) IsAvailable() bool

IsAvailable checks if the tool is available for use based on success rate.

func (*Tool) TableName

func (t *Tool) TableName() string

TableName returns the table name for this model.

func (*Tool) UpdateUsage

func (t *Tool) UpdateUsage(success bool)

UpdateUsage updates the usage statistics after tool execution.

Jump to

Keyboard shortcuts

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