vectorstore

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterCondition added in v0.6.0

type FilterCondition struct {
	Field    string         // Field to filter on
	Operator FilterOperator // Operator to use
	Value    interface{}    // Value to compare against
}

FilterCondition represents a single filter condition

Example:

condition := FilterCondition{
    Field:    "source",
    Operator: FilterOpEq,
    Value:    "technical-docs",
}

type FilterOperator added in v0.6.0

type FilterOperator string

FilterOperator defines filter operators for structured queries

const (
	FilterOpEq       FilterOperator = "eq"       // Equal
	FilterOpNeq      FilterOperator = "neq"      // Not equal
	FilterOpGt       FilterOperator = "gt"       // Greater than
	FilterOpGte      FilterOperator = "gte"      // Greater than or equal
	FilterOpLt       FilterOperator = "lt"       // Less than
	FilterOpLte      FilterOperator = "lte"      // Less than or equal
	FilterOpIn       FilterOperator = "in"       // In array
	FilterOpNin      FilterOperator = "nin"      // Not in array
	FilterOpContains FilterOperator = "contains" // Contains substring
)

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)

	// SearchStructured performs a structured search with filters
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - query: Structured query with filters
	// - embedding: Query embedding
	//
	// Returns:
	// - []core.Result: Slice of search results
	// - error: Error if search fails
	SearchStructured(ctx context.Context, query *StructuredQuery, embedding []float32) ([]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

	// GetByMetadata retrieves vectors by metadata
	//
	// Parameters:
	// - ctx: Context for cancellation and timeout
	// - metadata: Metadata filter
	//
	// Returns:
	// - []core.Result: Slice of matching results
	// - error: Error if retrieval fails
	GetByMetadata(ctx context.Context, metadata map[string]string) ([]core.Result, 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
}

type StructuredQuery added in v0.6.0

type StructuredQuery struct {
	Query    string            // Natural language query
	Filters  []FilterCondition // Filter conditions
	TopK     int               // Number of top results
	MinScore float32           // Minimum similarity score
}

StructuredQuery represents a structured search query

Example:

query := &StructuredQuery{
    Query: "Go programming language",
    Filters: []FilterCondition{
        {
            Field:    "category",
            Operator: FilterOpEq,
            Value:    "programming",
        },
    },
    TopK:     5,
    MinScore: 0.7,
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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