vector_db

package
v0.0.0-...-30b4b00 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitVectorDB

func InitVectorDB(dsn string) error

InitVectorDB initializes the vector database

func VectorToString

func VectorToString(vec []float32) string

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

func (v *VectorDB) DeleteExpired(ctx context.Context) (int64, error)

DeleteExpired deletes expired cache entries

func (*VectorDB) DeleteOldest

func (v *VectorDB) DeleteOldest(ctx context.Context, maxEntries int64) (int64, error)

DeleteOldest prunes entries exceeding maxEntries, keeping newest first. Returns the number of deleted rows.

func (*VectorDB) Search

func (v *VectorDB) Search(ctx context.Context, model string, embedding []float32, threshold float32, topK int, userGroup string) ([]*SearchResult, error)

Search performs similarity search for cached responses

func (*VectorDB) Store

func (v *VectorDB) Store(ctx context.Context, entry *SemanticCacheEntry) error

Store stores a cache entry

Jump to

Keyboard shortcuts

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