vectorstore

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolOptions added in v1.0.1

type PoolOptions struct {
	MaxConns    int
	IdleConns   int
	IdleTimeout time.Duration
}

PoolOptions configures the connection pool

func DefaultPoolOptions added in v1.0.1

func DefaultPoolOptions() PoolOptions

DefaultPoolOptions returns default pool options

type PoolStats added in v1.0.1

type PoolStats struct {
	ActiveConnections int
	MaxConnections    int
	IdleConnections   int
}

PoolStats represents pool statistics

type PooledStore added in v1.0.1

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

PooledStore wraps a Store with connection pooling

func NewPooledStore added in v1.0.1

func NewPooledStore(store Store, opts PoolOptions) *PooledStore

NewPooledStore creates a new pooled store wrapper

func (*PooledStore) Add added in v1.0.1

func (p *PooledStore) Add(ctx context.Context, chunks []core.Chunk, embeddings [][]float32) error

Add adds chunks to the store with pooling

func (*PooledStore) Close added in v1.0.1

func (p *PooledStore) Close() error

Close closes the pooled store and waits for all active operations to complete

func (*PooledStore) Delete added in v1.0.1

func (p *PooledStore) Delete(ctx context.Context, ids []string) error

Delete deletes chunks from the store with pooling

func (*PooledStore) Search added in v1.0.1

func (p *PooledStore) Search(ctx context.Context, query []float32, opts SearchOptions) ([]core.Result, error)

Search searches the store with pooling

func (*PooledStore) SearchByMetadata added in v1.0.1

func (p *PooledStore) SearchByMetadata(ctx context.Context, metadata map[string]string) ([]core.Chunk, error)

SearchByMetadata searches by metadata with pooling

func (*PooledStore) Stats added in v1.0.1

func (p *PooledStore) Stats() PoolStats

Stats returns pool statistics

type SearchOptions

type SearchOptions struct {
	TopK     int                    // Number of top results to return
	Filter   map[string]interface{} // Metadata filters
	MinScore float32                // Minimum similarity score
	Metadata map[string]string      // Additional metadata for search
}

SearchOptions configures search behavior

This struct defines options for vector search operations.

Example:

opts := SearchOptions{
    TopK:     5,
    MinScore: 0.7,
    Filter: map[string]interface{}{
        "source": "technical-docs",
    },
}

type Store

type Store interface {
	// Add adds chunks and their embeddings to the vector store
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - chunks: Slice of document chunks
	// - embeddings: Slice of embeddings, one for each chunk
	//
	// Returns:
	// - error: Error if storage fails
	Add(ctx context.Context, chunks []core.Chunk, embeddings [][]float32) error

	// Search searches for similar vectors to the query embedding
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - query: Query embedding
	// - opts: Search options (TopK, filters, etc.)
	//
	// Returns:
	// - []core.Result: Slice of search results
	// - error: Error if search fails
	Search(ctx context.Context, query []float32, opts SearchOptions) ([]core.Result, error)

	// Delete removes vectors by their IDs
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - ids: Slice of vector IDs to delete
	//
	// Returns:
	// - error: Error if deletion fails
	Delete(ctx context.Context, ids []string) error

	// SearchByMetadata searches for chunks with matching metadata
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - metadata: Metadata key-value pairs to match
	//
	// Returns:
	// - []core.Chunk: Slice of matching chunks
	// - error: Error if search fails
	SearchByMetadata(ctx context.Context, metadata map[string]string) ([]core.Chunk, error)
}

Store defines the interface for vector storage

This interface is implemented by all vector store backends (Memory, Milvus, Qdrant, Pinecone, Weaviate) and allows the RAG engine to store and retrieve embeddings.

Example implementation:

type MemoryStore struct {
    vectors []Vector
    mutex   sync.RWMutex
}

func (s *MemoryStore) Add(ctx context.Context, chunks []core.Chunk, embeddings [][]float32) error {
    // Store chunks and embeddings in memory
}

func (s *MemoryStore) Search(ctx context.Context, query []float32, opts SearchOptions) ([]core.Result, error) {
    // Search for similar embeddings
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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