vectordb

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExistsError

func IsAlreadyExistsError(err error) bool

IsAlreadyExistsError checks if an error is an already exists error

func IsAuthenticationError

func IsAuthenticationError(err error) bool

IsAuthenticationError checks if an error is an authentication error

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError checks if an error is a connection error

func IsErrorType

func IsErrorType(err error, errorType ErrorType) bool

IsErrorType checks if an error is of a specific type

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if an error is a not found error

func IsSupported

func IsSupported(dbType VectorDBType) bool

IsSupported checks if a database type is supported in the global registry

func IsTimeoutError

func IsTimeoutError(err error) bool

IsTimeoutError checks if an error is a timeout error

func IsUnsupportedError

func IsUnsupportedError(err error) bool

IsUnsupportedError checks if an error is an unsupported operation error

func RegisterFactory

func RegisterFactory(dbType VectorDBType, factory ClientFactory)

RegisterFactory registers a client factory globally

Types

type ClientFactory

type ClientFactory interface {
	// CreateClient creates a new vector database client
	CreateClient(config *Config) (VectorDBClient, error)

	// GetSupportedTypes returns the list of supported database types
	GetSupportedTypes() []VectorDBType

	// ValidateConfig validates the configuration for the specific database type
	ValidateConfig(config *Config) error
}

ClientFactory defines the interface for creating vector database clients

type CollectionInfo

type CollectionInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Count       int64  `json:"count"`
}

CollectionInfo represents information about a collection

type CollectionOperations

type CollectionOperations interface {
	// CreateCollection creates a new collection with the given schema
	CreateCollection(ctx context.Context, name string, schema *CollectionSchema) error

	// DeleteCollection deletes a collection and all its documents
	DeleteCollection(ctx context.Context, name string) error

	// ListCollections returns a list of all collections
	ListCollections(ctx context.Context) ([]CollectionInfo, error)

	// CollectionExists checks if a collection exists
	CollectionExists(ctx context.Context, name string) (bool, error)

	// GetCollectionCount returns the number of documents in a collection
	GetCollectionCount(ctx context.Context, name string) (int64, error)
}

CollectionOperations defines collection management operations

type CollectionSchema

type CollectionSchema struct {
	Class      string           `json:"class"`
	Vectorizer string           `json:"vectorizer,omitempty"`
	Properties []SchemaProperty `json:"properties"`
}

CollectionSchema represents a collection schema

type Config

type Config struct {
	Type         VectorDBType `yaml:"type"`
	URL          string       `yaml:"url,omitempty"`
	APIKey       string       `yaml:"api_key,omitempty"`
	OpenAIAPIKey string       `yaml:"openai_api_key,omitempty"`
	Timeout      int          `yaml:"timeout,omitempty"`

	// Mock-specific configuration
	Enabled            bool `yaml:"enabled,omitempty"`
	SimulateEmbeddings bool `yaml:"simulate_embeddings,omitempty"`
	EmbeddingDimension int  `yaml:"embedding_dimension,omitempty"`

	// Supabase-specific configuration
	DatabaseURL string `yaml:"database_url,omitempty"`
	DatabaseKey string `yaml:"database_key,omitempty"`

	// Milvus-specific configuration
	Username string `yaml:"username,omitempty"`
	Password string `yaml:"password,omitempty"`
	Database string `yaml:"database,omitempty"`
}

Config represents the configuration for a vector database client

type Document

type Document struct {
	ID        string                 `json:"id"`
	Text      string                 `json:"text"`
	Content   string                 `json:"content"`
	Image     string                 `json:"image"`
	ImageData string                 `json:"image_data"`
	URL       string                 `json:"url"`
	Metadata  map[string]interface{} `json:"metadata"`
}

Document represents a document in the vector database

type DocumentOperations

type DocumentOperations interface {
	// CreateDocument creates a new document in the specified collection
	CreateDocument(ctx context.Context, collectionName string, document *Document) error

	// CreateDocuments creates multiple documents in batch
	CreateDocuments(ctx context.Context, collectionName string, documents []*Document) error

	// GetDocument retrieves a document by ID
	GetDocument(ctx context.Context, collectionName, documentID string) (*Document, error)

	// UpdateDocument updates an existing document
	UpdateDocument(ctx context.Context, collectionName string, document *Document) error

	// DeleteDocument deletes a document by ID
	DeleteDocument(ctx context.Context, collectionName, documentID string) error

	// DeleteDocuments deletes multiple documents by IDs
	DeleteDocuments(ctx context.Context, collectionName string, documentIDs []string) error

	// DeleteDocumentsByMetadata deletes documents matching metadata criteria
	DeleteDocumentsByMetadata(ctx context.Context, collectionName string, metadata map[string]interface{}) error

	// ListDocuments returns a list of documents in a collection
	ListDocuments(ctx context.Context, collectionName string, limit int, offset int) ([]*Document, error)
}

DocumentOperations defines document management operations

type ErrorType

type ErrorType string

ErrorType represents the type of vector database error

const (
	ErrorTypeConnection     ErrorType = "connection"
	ErrorTypeAuthentication ErrorType = "authentication"
	ErrorTypeNotFound       ErrorType = "not_found"
	ErrorTypeAlreadyExists  ErrorType = "already_exists"
	ErrorTypeInvalidConfig  ErrorType = "invalid_config"
	ErrorTypeInvalidSchema  ErrorType = "invalid_schema"
	ErrorTypeInvalidQuery   ErrorType = "invalid_query"
	ErrorTypeTimeout        ErrorType = "timeout"
	ErrorTypeQuotaExceeded  ErrorType = "quota_exceeded"
	ErrorTypeInternal       ErrorType = "internal"
	ErrorTypeUnsupported    ErrorType = "unsupported"
)

type FieldDefinition

type FieldDefinition struct {
	Name string
	Type string
}

FieldDefinition represents a field in a collection schema

type QueryOperations

type QueryOperations interface {
	// SearchSemantic performs semantic search using vector embeddings
	SearchSemantic(ctx context.Context, collectionName, query string, options *QueryOptions) ([]*QueryResult, error)

	// SearchBM25 performs keyword-based search using BM25
	SearchBM25(ctx context.Context, collectionName, query string, options *QueryOptions) ([]*QueryResult, error)

	// SearchHybrid performs hybrid search combining vector and keyword search
	SearchHybrid(ctx context.Context, collectionName, query string, options *QueryOptions) ([]*QueryResult, error)

	// SearchByMetadata searches documents by metadata fields
	SearchByMetadata(ctx context.Context, collectionName string, metadata map[string]interface{}, options *QueryOptions) ([]*QueryResult, error)
}

QueryOperations defines search and query operations

type QueryOptions

type QueryOptions struct {
	TopK           int     `json:"top_k"`
	Distance       float64 `json:"distance"`
	SearchMetadata bool    `json:"search_metadata"`
	NoTruncate     bool    `json:"no_truncate"`
	UseBM25        bool    `json:"use_bm25"`
}

QueryOptions represents options for querying the vector database

type QueryResult

type QueryResult struct {
	Document Document `json:"document"`
	Score    float64  `json:"score"`
}

QueryResult represents a search result with score

type Registry

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

Registry holds all registered client factories

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new factory registry

func (*Registry) CreateClient

func (r *Registry) CreateClient(config *Config) (VectorDBClient, error)

CreateClient creates a client using the appropriate factory

func (*Registry) GetSupportedTypes

func (r *Registry) GetSupportedTypes() []VectorDBType

GetSupportedTypes returns all supported database types

func (*Registry) IsSupported

func (r *Registry) IsSupported(dbType VectorDBType) bool

IsSupported checks if a database type is supported

func (*Registry) Register

func (r *Registry) Register(dbType VectorDBType, factory ClientFactory)

Register registers a client factory for a specific database type

type SchemaOperations

type SchemaOperations interface {
	// GetSchema retrieves the schema for a collection
	GetSchema(ctx context.Context, collectionName string) (*CollectionSchema, error)

	// UpdateSchema updates the schema for a collection
	UpdateSchema(ctx context.Context, collectionName string, schema *CollectionSchema) error

	// GetDefaultSchema returns a default schema for the given type
	GetDefaultSchema(schemaType SchemaType, collectionName string) *CollectionSchema

	// ValidateSchema validates a schema definition
	ValidateSchema(schema *CollectionSchema) error
}

SchemaOperations defines schema management operations

type SchemaProperty

type SchemaProperty struct {
	Name             string                 `json:"name" yaml:"name"`
	DataType         []string               `json:"dataType" yaml:"datatype"`
	Description      string                 `json:"description,omitempty" yaml:"description,omitempty"`
	NestedProperties []SchemaProperty       `json:"nestedProperties,omitempty" yaml:"nestedproperties,omitempty"`
	JSONSchema       map[string]interface{} `json:"json_schema,omitempty" yaml:"json_schema,omitempty"`
}

SchemaProperty represents a property in a collection schema

type SchemaType

type SchemaType string

SchemaType represents the type of collection schema

const (
	SchemaTypeText  SchemaType = "text"
	SchemaTypeImage SchemaType = "image"
)

type VectorDBClient

type VectorDBClient interface {
	// Health checks the health of the vector database instance
	Health(ctx context.Context) error

	// Collection operations
	CollectionOperations

	// Document operations
	DocumentOperations

	// Query operations
	QueryOperations

	// Schema operations
	SchemaOperations
}

VectorDBClient defines the interface that all vector database implementations must satisfy

func CreateClient

func CreateClient(config *Config) (VectorDBClient, error)

CreateClient creates a client using the global registry

func CreateClientFromVectorDBConfig

func CreateClientFromVectorDBConfig(cfg *config.VectorDBConfig) (VectorDBClient, error)

CreateClientFromVectorDBConfig creates a client from the legacy VectorDBConfig

type VectorDBError

type VectorDBError struct {
	Type       ErrorType
	Message    string
	Cause      error
	Collection string
	Document   string
	Details    map[string]interface{}
}

VectorDBError represents a vector database error with additional context

func ErrAlreadyExists

func ErrAlreadyExists(resource, name string) *VectorDBError

ErrAlreadyExists creates an already exists error

func ErrAuthenticationFailed

func ErrAuthenticationFailed(message string) *VectorDBError

ErrAuthenticationFailed creates an authentication error

func ErrConnectionFailed

func ErrConnectionFailed(message string, cause error) *VectorDBError

ErrConnectionFailed creates a connection error

func ErrInternal

func ErrInternal(message string, cause error) *VectorDBError

ErrInternal creates an internal error

func ErrInvalidConfig

func ErrInvalidConfig(message string) *VectorDBError

ErrInvalidConfig creates an invalid configuration error

func ErrInvalidQuery

func ErrInvalidQuery(message string) *VectorDBError

ErrInvalidQuery creates an invalid query error

func ErrInvalidSchema

func ErrInvalidSchema(message string) *VectorDBError

ErrInvalidSchema creates an invalid schema error

func ErrNotFound

func ErrNotFound(resource, name string) *VectorDBError

ErrNotFound creates a not found error

func ErrQuotaExceeded

func ErrQuotaExceeded(message string) *VectorDBError

ErrQuotaExceeded creates a quota exceeded error

func ErrTimeout

func ErrTimeout(operation string) *VectorDBError

ErrTimeout creates a timeout error

func ErrUnsupported

func ErrUnsupported(operation string) *VectorDBError

ErrUnsupported creates an unsupported operation error

func NewError

func NewError(errorType ErrorType, message string) *VectorDBError

NewError creates a new VectorDBError

func NewErrorWithCause

func NewErrorWithCause(errorType ErrorType, message string, cause error) *VectorDBError

NewErrorWithCause creates a new VectorDBError with a cause

func (*VectorDBError) Error

func (e *VectorDBError) Error() string

Error implements the error interface

func (*VectorDBError) Is

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

Is checks if the error is of a specific type

func (*VectorDBError) Unwrap

func (e *VectorDBError) Unwrap() error

Unwrap returns the underlying cause

func (*VectorDBError) WithCollection

func (e *VectorDBError) WithCollection(collection string) *VectorDBError

WithCollection adds collection context to the error

func (*VectorDBError) WithDetail

func (e *VectorDBError) WithDetail(key string, value interface{}) *VectorDBError

WithDetail adds a detail to the error

func (*VectorDBError) WithDocument

func (e *VectorDBError) WithDocument(document string) *VectorDBError

WithDocument adds document context to the error

type VectorDBType

type VectorDBType string

VectorDBType represents the type of vector database

const (
	VectorDBTypeWeaviateCloud VectorDBType = "weaviate-cloud"
	VectorDBTypeWeaviateLocal VectorDBType = "weaviate-local"
	VectorDBTypeMock          VectorDBType = "mock"
	VectorDBTypeSupabase      VectorDBType = "supabase"
	VectorDBTypeMilvus        VectorDBType = "milvus"
)

func GetSupportedTypes

func GetSupportedTypes() []VectorDBType

GetSupportedTypes returns all supported database types from the global registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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