Help us shape the future of Go! Take the 2026 Go Developer Survey

vectorstore

package
v4.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeInvalidConfig        = "vectorstore.invalid_config"
	ErrorCodeInvalidInput         = "vectorstore.invalid_input"
	ErrorCodeInvalidVector        = "vectorstore.invalid_vector"
	ErrorCodeDimensionMismatch    = "vectorstore.dimension_mismatch"
	ErrorCodeNotFound             = "vectorstore.not_found"
	ErrorCodeUnsupportedOperation = "vectorstore.unsupported_operation"
	ErrorCodeEmbeddingFailed      = "vectorstore.embedding_failed"
)
View Source
const (
	EnvVectorBucketName          = "APPTHEORY_VECTOR_BUCKET_NAME"
	EnvVectorIndexName           = "APPTHEORY_VECTOR_INDEX_NAME"
	EnvVectorIndexARN            = "APPTHEORY_VECTOR_INDEX_ARN"
	EnvVectorDimension           = "APPTHEORY_VECTOR_DIMENSION"
	EnvEmbeddingProvider         = "APPTHEORY_EMBEDDING_PROVIDER"
	EnvEmbeddingModelID          = "APPTHEORY_EMBEDDING_MODEL_ID"
	EnvEmbeddingDimensions       = "APPTHEORY_EMBEDDING_DIMENSIONS"
	EnvEmbeddingNormalize        = "APPTHEORY_EMBEDDING_NORMALIZE"
	DefaultTitanEmbedTextModelID = "amazon.titan-embed-text-v2:0"
)
View Source
const (
	DefaultEmbeddingDimensions = 1024
	DefaultQueryTopK           = 12
	MaxQueryTopK               = 10000
	MaxPutDeleteBatchSize      = 500
)

Variables

View Source
var (
	ErrInvalidConfig        = &Error{Code: ErrorCodeInvalidConfig, Message: "vectorstore: invalid config"}
	ErrInvalidInput         = &Error{Code: ErrorCodeInvalidInput, Message: "vectorstore: invalid input"}
	ErrInvalidVector        = &Error{Code: ErrorCodeInvalidVector, Message: "vectorstore: invalid vector"}
	ErrDimensionMismatch    = &Error{Code: ErrorCodeDimensionMismatch, Message: "vectorstore: vector dimension mismatch"}
	ErrNotFound             = &Error{Code: ErrorCodeNotFound, Message: "vectorstore: vector not found"}
	ErrUnsupportedOperation = &Error{Code: ErrorCodeUnsupportedOperation, Message: "vectorstore: unsupported operation"}
	ErrEmbeddingFailed      = &Error{Code: ErrorCodeEmbeddingFailed, Message: "vectorstore: embedding failed"}
)

Functions

func CloneMetadata

func CloneMetadata(in map[string]any) map[string]any

func CloneVector

func CloneVector(in []float32) []float32

func EmbeddingErrorCode

func EmbeddingErrorCode(err error) string

func NormalizeTopK

func NormalizeTopK(topK int) int

func ValidateDimension

func ValidateDimension(dimension int) error

func ValidateKey

func ValidateKey(key string) error

func ValidateRequiredMetadata

func ValidateRequiredMetadata(metadata map[string]any, required []string) error

func ValidateVector

func ValidateVector(vector []float32, dimension int) error

Types

type BedrockRuntimeAPI

type BedrockRuntimeAPI interface {
	InvokeModel(context.Context, *bedrockruntime.InvokeModelInput, ...func(*bedrockruntime.Options)) (*bedrockruntime.InvokeModelOutput, error)
}

type Call

type Call struct {
	Operation      string
	Keys           []string
	Records        []VectorRecord
	Vector         []float32
	TopK           int
	Filter         map[string]any
	ReturnMetadata bool
}

type DeleteInput

type DeleteInput struct {
	Keys []string
}

type Embedder

type Embedder interface {
	Embed(context.Context, string) ([]float32, error)
	EmbedBatch(context.Context, []string) ([][]float32, error)
}

type Error

type Error struct {
	Code    string
	Message string
	Cause   error
}

func NewError

func NewError(code, message string, cause error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FakeEmbedder

type FakeEmbedder struct {
	Embeddings map[string][]float32
	Default    []float32
	Calls      []string
}

func NewFakeEmbedder

func NewFakeEmbedder(embeddings map[string][]float32) *FakeEmbedder

func (*FakeEmbedder) Embed

func (e *FakeEmbedder) Embed(_ context.Context, text string) ([]float32, error)

func (*FakeEmbedder) EmbedBatch

func (e *FakeEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

type FakeStore

type FakeStore struct {
	Dimension            int
	RequiredMetadataKeys []string
	// contains filtered or unexported fields
}

func NewFakeStore

func NewFakeStore(dimension int) *FakeStore

func (*FakeStore) Calls

func (s *FakeStore) Calls() []Call

func (*FakeStore) DeleteVectors

func (s *FakeStore) DeleteVectors(_ context.Context, input DeleteInput) error

func (*FakeStore) GetVectors

func (s *FakeStore) GetVectors(_ context.Context, input GetInput) ([]VectorRecord, error)

func (*FakeStore) PutVectors

func (s *FakeStore) PutVectors(_ context.Context, input PutInput) error

func (*FakeStore) QueryVectors

func (s *FakeStore) QueryVectors(_ context.Context, input QueryInput) ([]QueryHit, error)

func (*FakeStore) SetError

func (s *FakeStore) SetError(operation string, err error)

type GetInput

type GetInput struct {
	Keys           []string
	ReturnMetadata bool
}

type PutInput

type PutInput struct {
	Records []VectorRecord
}

type QueryHit

type QueryHit struct {
	Key      string         `json:"key"`
	Distance float32        `json:"distance"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type QueryInput

type QueryInput struct {
	Vector         []float32
	TopK           int
	Filter         map[string]any
	ReturnMetadata bool
}

type S3VectorStore

type S3VectorStore struct {
	Client           S3VectorsAPI
	VectorBucketName string
	IndexName        string
	Dimension        int
	MaxBatchSize     int
}

func NewS3VectorStore

func NewS3VectorStore(ctx context.Context, vectorBucketName, indexName string, dimension int) (*S3VectorStore, error)

func (*S3VectorStore) DeleteVectors

func (s *S3VectorStore) DeleteVectors(ctx context.Context, input DeleteInput) error

func (*S3VectorStore) GetVectors

func (s *S3VectorStore) GetVectors(ctx context.Context, input GetInput) ([]VectorRecord, error)

func (*S3VectorStore) PutVectors

func (s *S3VectorStore) PutVectors(ctx context.Context, input PutInput) error

func (*S3VectorStore) QueryVectors

func (s *S3VectorStore) QueryVectors(ctx context.Context, input QueryInput) ([]QueryHit, error)

type SemanticIndex

type SemanticIndex struct {
	Store                Store
	Embedder             Embedder
	Dimension            int
	RequiredMetadataKeys []string
}

func (*SemanticIndex) PutText

func (i *SemanticIndex) PutText(ctx context.Context, records []SemanticRecord) error

func (*SemanticIndex) QueryText

func (i *SemanticIndex) QueryText(ctx context.Context, text string, input QueryInput) ([]QueryHit, error)

type SemanticRecord

type SemanticRecord struct {
	Key      string
	Text     string
	Metadata map[string]any
}

type Store

type Store interface {
	PutVectors(context.Context, PutInput) error
	GetVectors(context.Context, GetInput) ([]VectorRecord, error)
	DeleteVectors(context.Context, DeleteInput) error
	QueryVectors(context.Context, QueryInput) ([]QueryHit, error)
}

type TitanEmbedder

type TitanEmbedder struct {
	Runtime          BedrockRuntimeAPI
	ModelID          string
	Dimensions       int
	Normalize        bool
	BatchConcurrency int
}

func NewTitanEmbedder

func NewTitanEmbedder(ctx context.Context) (*TitanEmbedder, error)

func (*TitanEmbedder) Embed

func (e *TitanEmbedder) Embed(ctx context.Context, text string) ([]float32, error)

func (*TitanEmbedder) EmbedBatch

func (e *TitanEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)

type VectorRecord

type VectorRecord struct {
	Key      string         `json:"key"`
	Data     []float32      `json:"data"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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