Documentation
¶
Overview ¶
Package vector provides common interfaces for vector storage implementations.
Package vector provides common interfaces and types for vector storage implementations.
Index ¶
- func CopyMetadata(base map[string]any, key string, value any) map[string]any
- func CopyMetadataMulti(base map[string]any, extra map[string]any) map[string]any
- func DistanceToSimilarity(distance float64) float64
- func ExtractObservationIDs(results []QueryResult, project string) []int64
- func ExtractPromptIDs(results []QueryResult, project string) []int64
- func ExtractRowID(metadata map[string]any) int64
- func ExtractSummaryIDs(results []QueryResult, project string) []int64
- func JoinStrings(strs []string, sep string) string
- type CacheStatsSnapshot
- type Client
- type DocType
- type Document
- type HealthStats
- type QueryResult
- type StaleVectorInfo
- type VectorMetricsSnapshot
- type WhereClause
- type WhereFilter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyMetadata ¶
CopyMetadata creates a new metadata map with an additional key-value pair.
func CopyMetadataMulti ¶
CopyMetadataMulti creates a new metadata map merging base and extra.
func DistanceToSimilarity ¶
DistanceToSimilarity converts cosine distance to similarity score. Cosine distance: 0 = identical, 2 = opposite. Similarity: 1.0 = identical, 0.0 = opposite.
func ExtractObservationIDs ¶
func ExtractObservationIDs(results []QueryResult, project string) []int64
ExtractObservationIDs extracts observation database IDs from query results, optionally filtering by project (including global scope).
func ExtractPromptIDs ¶
func ExtractPromptIDs(results []QueryResult, project string) []int64
ExtractPromptIDs extracts user prompt database IDs from query results.
func ExtractRowID ¶ added in v0.4.0
ExtractRowID safely extracts a database row ID from vector result metadata. The metadata key is "sqlite_id" for historical reasons (pgvector inherited the name).
func ExtractSummaryIDs ¶
func ExtractSummaryIDs(results []QueryResult, project string) []int64
ExtractSummaryIDs extracts session summary database IDs from query results.
func JoinStrings ¶
JoinStrings joins strings with a separator.
Types ¶
type CacheStatsSnapshot ¶
type CacheStatsSnapshot struct {
EmbeddingHits int64 `json:"embedding_hits"`
EmbeddingMisses int64 `json:"embedding_misses"`
ResultHits int64 `json:"result_hits"`
ResultMisses int64 `json:"result_misses"`
}
CacheStatsSnapshot is an exported snapshot of cache performance metrics. For backends without a local cache (e.g. pgvector), all counters are zero.
func (CacheStatsSnapshot) HitRate ¶
func (s CacheStatsSnapshot) HitRate() float64
HitRate returns the overall cache hit rate as a percentage (0–100).
type Client ¶
type Client interface {
// AddDocuments adds documents with their embeddings to the vector store.
AddDocuments(ctx context.Context, docs []Document) error
// DeleteDocuments removes documents by their IDs.
DeleteDocuments(ctx context.Context, ids []string) error
// Query performs a vector similarity search.
Query(ctx context.Context, query string, limit int, where WhereFilter) ([]QueryResult, error)
// IsConnected checks if the vector store is available.
IsConnected() bool
// Close releases resources.
Close() error
// Count returns the total number of vectors in the store.
Count(ctx context.Context) (int64, error)
// ModelVersion returns the current embedding model version.
ModelVersion() string
// NeedsRebuild checks if vectors need to be rebuilt due to model version change.
NeedsRebuild(ctx context.Context) (bool, string)
// GetStaleVectors returns info about vectors with mismatched or null model versions.
GetStaleVectors(ctx context.Context) ([]StaleVectorInfo, error)
// GetHealthStats returns comprehensive health statistics about the vector store.
GetHealthStats(ctx context.Context) (*HealthStats, error)
// GetCacheStats returns cache performance statistics.
// Backends without a local cache return a zero-value CacheStatsSnapshot.
GetCacheStats() CacheStatsSnapshot
// GetMetrics returns real query instrumentation metrics (count, latency percentiles, doc count).
GetMetrics(ctx context.Context) VectorMetricsSnapshot
// DeleteByObservationID removes all vectors associated with an observation ID.
DeleteByObservationID(ctx context.Context, obsID int64) error
}
Client defines the interface for vector storage operations. pgvector.Client is the production implementation.
type DocType ¶
type DocType string
DocType represents the type of document stored in the vector table.
type HealthStats ¶
type HealthStats struct {
TotalVectors int64 `json:"total_vectors"`
StaleVectors int64 `json:"stale_vectors"`
CurrentModel string `json:"current_model"`
NeedsRebuild bool `json:"needs_rebuild"`
RebuildReason string `json:"rebuild_reason"`
}
HealthStats contains comprehensive health information about the vector store.
type QueryResult ¶
QueryResult represents a search result from vector search.
func FilterByThreshold ¶
func FilterByThreshold(results []QueryResult, threshold float64, maxResults int) []QueryResult
FilterByThreshold filters results to only include those above the similarity threshold. If maxResults > 0, also caps the number of results.
type StaleVectorInfo ¶
StaleVectorInfo contains information about a vector that needs rebuilding.
type VectorMetricsSnapshot ¶ added in v1.1.0
type VectorMetricsSnapshot struct {
QueryCount int64 `json:"query_count"`
AvgLatencyMs float64 `json:"avg_latency_ms"`
P50LatencyMs float64 `json:"p50_latency_ms"`
P95LatencyMs float64 `json:"p95_latency_ms"`
P99LatencyMs float64 `json:"p99_latency_ms"`
TotalDocs int64 `json:"total_documents"`
}
VectorMetricsSnapshot contains real query instrumentation data.
type WhereClause ¶ added in v0.4.0
type WhereClause struct {
OrGroup []WhereClause
Column string
Value any
}
WhereClause is a single filter condition (equality or OR group).
type WhereFilter ¶ added in v0.4.0
type WhereFilter struct {
Clauses []WhereClause
}
WhereFilter represents a filter for vector queries, supporting OR conditions.
func BuildWhereFilter ¶
func BuildWhereFilter(docType DocType, project string, includeGlobal bool) WhereFilter
BuildWhereFilter creates a filter for vector queries. When includeGlobal is true and project is non-empty, results include both project-specific AND global-scoped observations.