vectorstore

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Package vectorstore provides a generic interface for vector stores.

Index

Constants

View Source
const (
	// Default class names (Weaviate prefers PascalCase)
	DefaultClassName = "BifrostStore"
)

Default values for Weaviate vector index configuration

Variables

View Source
var (
	ErrNotFound     = errors.New("vectorstore: not found")
	ErrNotSupported = errors.New("vectorstore: operation not supported on this store")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled bool            `json:"enabled"`
	Type    VectorStoreType `json:"type"`
	Config  any             `json:"config"`
}

Config represents the configuration for the vector store.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the config from JSON.

type DeleteResult added in v1.0.3

type DeleteResult struct {
	ID     string
	Status DeleteStatus
	Error  string
}

DeleteResult represents the result of a delete operation.

type DeleteStatus added in v1.0.3

type DeleteStatus string
const (
	DeleteStatusSuccess DeleteStatus = "success"
	DeleteStatusError   DeleteStatus = "error"
)

type Query added in v1.0.3

type Query struct {
	Field    string
	Operator QueryOperator
	Value    interface{}
}

Query represents a query to the vector store.

type QueryOperator added in v1.0.3

type QueryOperator string
const (
	QueryOperatorEqual              QueryOperator = "Equal"
	QueryOperatorNotEqual           QueryOperator = "NotEqual"
	QueryOperatorGreaterThan        QueryOperator = "GreaterThan"
	QueryOperatorLessThan           QueryOperator = "LessThan"
	QueryOperatorGreaterThanOrEqual QueryOperator = "GreaterThanOrEqual"
	QueryOperatorLessThanOrEqual    QueryOperator = "LessThanOrEqual"
	QueryOperatorLike               QueryOperator = "Like"
	QueryOperatorContainsAny        QueryOperator = "ContainsAny"
	QueryOperatorContainsAll        QueryOperator = "ContainsAll"
	QueryOperatorIsNull             QueryOperator = "IsNull"
	QueryOperatorIsNotNull          QueryOperator = "IsNotNull"
)

type SearchResult added in v1.0.3

type SearchResult struct {
	ID         string
	Score      *float64
	Properties map[string]interface{}
}

SearchResult represents a search result with metadata.

type VectorStore

type VectorStore interface {
	CreateNamespace(ctx context.Context, namespace string, properties map[string]VectorStoreProperties) error
	GetChunk(ctx context.Context, namespace string, id string) (SearchResult, error)
	GetChunks(ctx context.Context, namespace string, ids []string) ([]SearchResult, error)
	GetAll(ctx context.Context, namespace string, queries []Query, selectFields []string, cursor *string, limit int64) ([]SearchResult, *string, error)
	GetNearest(ctx context.Context, namespace string, vector []float32, queries []Query, selectFields []string, threshold float64, limit int64) ([]SearchResult, error)
	Add(ctx context.Context, namespace string, id string, embedding []float32, metadata map[string]interface{}) error
	Delete(ctx context.Context, namespace string, id string) error
	DeleteAll(ctx context.Context, namespace string, queries []Query) ([]DeleteResult, error)
	Close(ctx context.Context, namespace string) error
}

VectorStore represents the interface for the vector store.

func NewVectorStore

func NewVectorStore(ctx context.Context, config *Config, logger schemas.Logger) (VectorStore, error)

NewVectorStore returns a new vector store based on the configuration.

type VectorStoreProperties added in v1.0.6

type VectorStoreProperties struct {
	DataType    VectorStorePropertyType `json:"data_type"`
	Description string                  `json:"description"`
}

type VectorStorePropertyType added in v1.0.6

type VectorStorePropertyType string
const (
	VectorStorePropertyTypeString      VectorStorePropertyType = "string"
	VectorStorePropertyTypeInteger     VectorStorePropertyType = "integer"
	VectorStorePropertyTypeBoolean     VectorStorePropertyType = "boolean"
	VectorStorePropertyTypeStringArray VectorStorePropertyType = "string[]"
)

type VectorStoreType

type VectorStoreType string
const (
	VectorStoreTypeWeaviate VectorStoreType = "weaviate"
)

type WeaviateConfig added in v1.0.3

type WeaviateConfig struct {
	// Connection settings
	Scheme     string              `json:"scheme"`                // "http" or "https" - REQUIRED
	Host       string              `json:"host"`                  // "localhost:8080" - REQUIRED
	GrpcConfig *WeaviateGrpcConfig `json:"grpc_config,omitempty"` // grpc config for weaviate (optional)

	// Authentication settings (optional)
	ApiKey  string            `json:"api_key,omitempty"` // API key for authentication
	Headers map[string]string `json:"headers,omitempty"` // Additional headers

	// Connection settings
	Timeout time.Duration `json:"timeout,omitempty"` // Request timeout (optional)
}

WeaviateConfig represents the configuration for the Weaviate vector store.

type WeaviateGrpcConfig added in v1.0.6

type WeaviateGrpcConfig struct {
	// Host is the host of the weaviate server (host:port).
	// If host is without a port number then the 80 port for insecured and 443 port for secured connections will be used.
	Host string `json:"host"`
	// Secured is a boolean flag indicating if the connection is secured
	Secured bool `json:"secured"`
}

type WeaviateStore added in v1.0.3

type WeaviateStore struct {
	// contains filtered or unexported fields
}

WeaviateStore represents the Weaviate vector store.

func (*WeaviateStore) Add added in v1.0.3

func (s *WeaviateStore) Add(ctx context.Context, className string, id string, embedding []float32, metadata map[string]interface{}) error

Add stores a new object (with or without embedding)

func (*WeaviateStore) Close added in v1.0.3

func (s *WeaviateStore) Close(ctx context.Context, className string) error

func (*WeaviateStore) CreateNamespace added in v1.0.6

func (s *WeaviateStore) CreateNamespace(ctx context.Context, className string, properties map[string]VectorStoreProperties) error

func (*WeaviateStore) Delete added in v1.0.3

func (s *WeaviateStore) Delete(ctx context.Context, className string, id string) error

Delete removes multiple objects by ID

func (*WeaviateStore) DeleteAll added in v1.0.3

func (s *WeaviateStore) DeleteAll(ctx context.Context, className string, queries []Query) ([]DeleteResult, error)

func (*WeaviateStore) GetAll added in v1.0.3

func (s *WeaviateStore) GetAll(ctx context.Context, className string, queries []Query, selectFields []string, cursor *string, limit int64) ([]SearchResult, *string, error)

GetAll with filtering + pagination

func (*WeaviateStore) GetChunk added in v1.0.3

func (s *WeaviateStore) GetChunk(ctx context.Context, className string, id string) (SearchResult, error)

GetChunk returns the "metadata" for a single key

func (*WeaviateStore) GetChunks added in v1.0.3

func (s *WeaviateStore) GetChunks(ctx context.Context, className string, ids []string) ([]SearchResult, error)

GetChunks returns multiple objects by ID

func (*WeaviateStore) GetNearest added in v1.0.3

func (s *WeaviateStore) GetNearest(
	ctx context.Context,
	className string,
	vector []float32,
	queries []Query,
	selectFields []string,
	threshold float64,
	limit int64,
) ([]SearchResult, error)

GetNearest with explicit filters only

Jump to

Keyboard shortcuts

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