vectordb

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package vectordb contains vectordb interface and different engines like memory, chromem and milvus implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float32s

func Float32s(v []float64) []float32

Float32s converts a Vector ([]float64) to []float32. This is necessary because ChromeM uses float32 for vector operations, while our interface uses float64 for broader compatibility.

func Float64s

func Float64s(v []float32) []float64

Types

type Engine

type Engine interface {
	Insert(context.Context, string, ...Record) error
	Search(context.Context, []float64, ...SearchOption) ([]Record, error)
}

type EngineType

type EngineType string
const (
	Memory  EngineType = "memory"
	Chromem EngineType = "chromem"
	Milvus  EngineType = "milvus"
)

type Option

type Option func(*Options)

Option is a function type for configuring VectorDB instances. It follows the functional options pattern for clean and flexible configuration.

func WithColumns

func WithColumns(columns ...string) Option

WithColumns specifies which columns to retrieve from the database. This can optimize performance by only fetching needed fields.

Example:

retriever, err := NewRetriever(
    WithColumns("Text", "Metadata", "Source"),
)

func WithDimension

func WithDimension(dimension int) Option

WithDimension sets the dimension of vectors to be stored. This must match the dimension of your embedding model: - text-embedding-3-small: 1536 - text-embedding-ada-002: 1536 - Cohere embed-multilingual-v3.0: 1024

func WithEngine

func WithEngine(engine EngineType) Option

WithEngineType sets the database type. Supported types: - "milvus": Production-grade vector database - "memory": In-memory database for testing - "chromem": Chrome-based persistent storage

func WithHybrid

func WithHybrid(enabled bool) Option

WithHybrid enables or disables hybrid search. Hybrid search combines vector similarity with keyword matching.

Example:

retriever, err := NewRetriever(
    WithHybrid(true), // Enable hybrid search
)

func WithMinScore

func WithMinScore(score float64) Option

WithMinScore sets the minimum similarity score threshold. Results with scores below this threshold will be filtered out.

Example:

retriever, err := NewRetriever(
    WithMinScore(0.8), // Only return high-confidence matches
)

func WithTopK

func WithTopK(k int) Option

WithTopK sets the maximum number of results to return. The actual number of results may be less if MinScore filtering is applied.

Example:

retriever, err := NewRetriever(
    WithTopK(10), // Return top 10 results
)

type Options

type Options struct {
	EngineType EngineType // Database type (e.g., "milvus", "memory")
	TopK       int        // Maximum number of results to return
	MinScore   float64    // Minimum similarity score threshold
	UseHybrid  bool       // Enable hybrid search (vector + keyword)
	Columns    []string   // Columns to retrieve from the database
	Dimension  int        // Vector dimension
}

type Record

type Record struct {
	// ID is the identifier for the result
	ID string
	// Score is the similarity score for the result
	Score float64
	// Embedding embeddings for doc
	Embedding embedder.Embedding
}

Record represents a single result from a vector similarity search.

type SearchOption

type SearchOption func(*SearchOptions)

func SearchWithCollection

func SearchWithCollection(name string) SearchOption

func SearchWithExclude

func SearchWithExclude(v string) SearchOption

func SearchWithInclude

func SearchWithInclude(v string) SearchOption

func SearchWithMeta

func SearchWithMeta(meta map[string]string) SearchOption

func SearchWithTopK

func SearchWithTopK(topK int) SearchOption

type SearchOptions

type SearchOptions struct {
	Collection string
	TopK       int
	Meta       map[string]string
	Include    string
	Exclude    string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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