vector

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func InitEmbedder() error

InitEmbedder initializes the local Ollama embedding backend.

func InitEmbeddingCaches

func InitEmbeddingCaches() error

func InitOllamaClient

func InitOllamaClient() error

func IsEmbeddingUnavailable

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

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

ActivityInspect holds one weighted activity row for admin display.

func InspectSiteActivities

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

func InspectUserActivities

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