Documentation
¶
Index ¶
- func InitVectorDB(dsn string) error
- func VectorToString(vec []float32) string
- type SearchResult
- type SemanticCacheEntry
- type VectorDB
- func (v *VectorDB) DeleteExpired(ctx context.Context) (int64, error)
- func (v *VectorDB) DeleteOldest(ctx context.Context, maxEntries int64) (int64, error)
- func (v *VectorDB) Search(ctx context.Context, model string, embedding []float32, threshold float32, ...) ([]*SearchResult, error)
- func (v *VectorDB) Store(ctx context.Context, entry *SemanticCacheEntry) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitVectorDB ¶
InitVectorDB initializes the vector database
func VectorToString ¶
VectorToString converts []float32 to pgvector string format
Types ¶
type SearchResult ¶
type SearchResult struct {
Entry *SemanticCacheEntry
Similarity float32
}
SearchResult represents a search result
type SemanticCacheEntry ¶
type SemanticCacheEntry struct {
ID uint `gorm:"primaryKey" json:"id"`
ModelName string `gorm:"index:idx_model_created,priority:1" json:"model_name"`
Prompt string `gorm:"type:text;not null" json:"prompt"`
PromptVector string `gorm:"type:text;not null" json:"prompt_vector"` // stored as string for simplicity
RequestBody json.RawMessage `gorm:"type:jsonb;not null" json:"request_body"`
ResponseBody json.RawMessage `gorm:"type:jsonb;not null" json:"response_body"`
CreatedAt int64 `gorm:"index:idx_model_created,priority:2" json:"created_at"`
ExpiresAt int64 `json:"expires_at"` // 0 means never expires
UserGroup string `gorm:"type:varchar(50);default:''" json:"user_group"`
TTL int64 `json:"ttl"` // seconds
}
SemanticCacheEntry represents a semantic cache entry
type VectorDB ¶
type VectorDB struct {
// contains filtered or unexported fields
}
VectorDB provides vector similarity search capabilities
func GetVectorDB ¶
func GetVectorDB() *VectorDB
GetVectorDB returns the default vector database instance
func (*VectorDB) DeleteExpired ¶
DeleteExpired deletes expired cache entries
func (*VectorDB) DeleteOldest ¶
DeleteOldest prunes entries exceeding maxEntries, keeping newest first. Returns the number of deleted rows.
Click to show internal directories.
Click to hide internal directories.