vector

package
v0.0.97 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoUserActivity = errors.New("no user activity to aggregate")
	ErrNoEmbeddedAds  = errors.New("no embedded ads")
)

Functions

func AggregateEmbeddings

func AggregateEmbeddings(vectors [][]float32, weights []float32) []float32

func BackfillAllAdsSync

func BackfillAllAdsSync() (remaining int, err error)

func BuildAdEmbedding

func BuildAdEmbedding(input ad.EmbeddingInput) error

func BuildAdEmbeddings

func BuildAdEmbeddings(inputs []ad.EmbeddingInput) error

func ClearAllEmbeddingCaches

func ClearAllEmbeddingCaches()

func ClearQueryEmbeddingCache

func ClearQueryEmbeddingCache()

func ClearSiteEmbeddingCache

func ClearSiteEmbeddingCache()

func ClearUserEmbeddingCache

func ClearUserEmbeddingCache()

func DeleteAdEmbedding

func DeleteAdEmbedding(adID int) error

func EmbedderInfo added in v0.0.29

func EmbedderInfo() (provider, model string)

EmbedderInfo returns the Ollama provider identifier and model name.

func GetAdEmbeddings

func GetAdEmbeddings(adIDs []int) ([][]float32, error)

func GetEmbeddingCacheStats

func GetEmbeddingCacheStats() map[string]map[string]interface{}

func GetQueryEmbedding

func GetQueryEmbedding(userQuery string) ([]float32, error)

func GetSiteEmbedding

func GetSiteEmbedding(categoryID int, campaignKey string) ([]float32, error)

func GetUserPersonalizedEmbedding

func GetUserPersonalizedEmbedding(userID, categoryID int) ([]float32, error)

func InitEmbedder added in v0.0.29

func InitEmbedder() error

InitEmbedder initializes the local Ollama embedding backend.

func InitEmbeddingCaches

func InitEmbeddingCaches() error

func InitOllamaClient added in v0.0.29

func InitOllamaClient() error

func IsEmbeddingUnavailable added in v0.0.27

func IsEmbeddingUnavailable(err error) bool

IsEmbeddingUnavailable reports whether search should degrade gracefully instead of returning HTTP 500 (e.g. backfill still in progress).

func ProcessAdsWithoutVectors

func ProcessAdsWithoutVectors()

func QuerySimilarAdIDs

func QuerySimilarAdIDs(embedding []float32, whereClause string, whereArgs []any,
	limit, offset int, threshold float64) ([]int, error)

QuerySimilarAdIDs returns nearest ad IDs under threshold matching whereClause. whereClause placeholders start at $1 and are remapped after the embedding and threshold args.

func QueueAd

func QueueAd(adID int)

func QueueDepth

func QueueDepth() int

func ResolveSearchEmbedding

func ResolveSearchEmbedding(userID, categoryID int, query string) ([]float32, error)

func SetEmbedder

func SetEmbedder(e Embedder)

func StartBackgroundProcessor

func StartBackgroundProcessor()

func TriggerBackfill

func TriggerBackfill()

func UpsertAdEmbeddings

func UpsertAdEmbeddings(adIDs []int, embeddings [][]float32,
	metadatas []map[string]any) error

Types

type ActivityInspect added in v0.0.25

type ActivityInspect struct {
	AdID         int
	AdTitle      string
	ActivityType string
	Weight       float32
	Timestamp    string
}

ActivityInspect holds one weighted activity row for admin display.

func InspectSiteActivities added in v0.0.25

func InspectSiteActivities(categoryID int) ([]ActivityInspect, error)

func InspectUserActivities added in v0.0.25

func InspectUserActivities(userID, categoryID int) ([]ActivityInspect, error)

type AdActivity

type AdActivity struct {
	AdID         int       `json:"ad_id"`
	Timestamp    string    `json:"timestamp"`
	Embedding    []float32 `json:"embedding"`
	ActivityType string    `json:"activity_type"`
	Weight       float32   `json:"weight"`
}

type Embedder

type Embedder interface {
	EmbedText(text string) ([]float32, error)
	EmbedTexts(texts []string) ([][]float32, error)
	EmbedQuery(text string) ([]float32, error)
	EmbedDocuments(texts []string) ([][]float32, error)
}

func NewFakeEmbedder

func NewFakeEmbedder() Embedder

Jump to

Keyboard shortcuts

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