vector

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type       string                 `json:"type"`              // Type of vector store (e.g., "pinecone", "weaviate", "local")
	Dimension  int                    `json:"dimension"`         // Dimension of vectors
	MetricType string                 `json:"metric_type"`       // Distance metric type (e.g., "cosine", "euclidean", "dot_product")
	Options    map[string]interface{} `json:"options,omitempty"` // Additional store-specific options
}

Config holds configuration for vector stores

type Document

type Document struct {
	ID       string                 `json:"id"`
	Content  string                 `json:"content"`
	Vector   Vector                 `json:"vector"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Document represents a document with its vector embedding

type LocalStore

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

LocalStore implements an in-memory vector store

func (*LocalStore) Clear

func (s *LocalStore) Clear(ctx context.Context) error

func (*LocalStore) Close

func (s *LocalStore) Close() error

func (*LocalStore) Delete

func (s *LocalStore) Delete(ctx context.Context, ids ...string) error

func (*LocalStore) Get

func (s *LocalStore) Get(ctx context.Context, ids ...string) ([]Document, error)

func (*LocalStore) Insert

func (s *LocalStore) Insert(ctx context.Context, docs ...Document) error

func (*LocalStore) Search

func (s *LocalStore) Search(ctx context.Context, queryVector Vector, limit int) ([]SearchResult, error)

func (*LocalStore) Update

func (s *LocalStore) Update(ctx context.Context, docs ...Document) error

type MetricType

type MetricType string

MetricType represents supported distance metrics

const (
	MetricCosine     MetricType = "cosine"      // Cosine similarity
	MetricEuclidean  MetricType = "euclidean"   // Euclidean distance
	MetricDotProduct MetricType = "dot_product" // Dot product similarity
)

type PineconeStore

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

PineconeStore implements vector store using Pinecone

func (*PineconeStore) Clear

func (s *PineconeStore) Clear(ctx context.Context) error

func (*PineconeStore) Close

func (s *PineconeStore) Close() error

func (*PineconeStore) Delete

func (s *PineconeStore) Delete(ctx context.Context, ids ...string) error

func (*PineconeStore) Get

func (s *PineconeStore) Get(ctx context.Context, ids ...string) ([]Document, error)

func (*PineconeStore) Insert

func (s *PineconeStore) Insert(ctx context.Context, docs ...Document) error

func (*PineconeStore) Search

func (s *PineconeStore) Search(ctx context.Context, queryVector Vector, limit int) ([]SearchResult, error)

func (*PineconeStore) Update

func (s *PineconeStore) Update(ctx context.Context, docs ...Document) error

type SearchResult

type SearchResult struct {
	Document Document `json:"document"`
	Score    float32  `json:"score"`
}

SearchResult represents a search result with similarity score

type Store

type Store interface {
	// Insert adds documents to the store
	Insert(ctx context.Context, docs ...Document) error

	// Search finds similar documents based on query vector
	Search(ctx context.Context, queryVector Vector, limit int) ([]SearchResult, error)

	// Delete removes documents from the store
	Delete(ctx context.Context, ids ...string) error

	// Update updates existing documents
	Update(ctx context.Context, docs ...Document) error

	// Get retrieves documents by their IDs
	Get(ctx context.Context, ids ...string) ([]Document, error)

	// Clear removes all documents from the store
	Clear(ctx context.Context) error

	// Close closes the store connection
	Close() error
}

Store defines the interface for vector storage implementations

func NewLocalStore

func NewLocalStore(ctx context.Context, config Config) (Store, error)

NewLocalStore creates a new local vector store

func NewPineconeStore

func NewPineconeStore(ctx context.Context, config Config) (Store, error)

NewPineconeStore creates a new Pinecone vector store

func NewStore

func NewStore(ctx context.Context, config Config) (Store, error)

NewStore creates a new vector store based on config

func NewWeaviateStore

func NewWeaviateStore(ctx context.Context, config Config) (Store, error)

NewWeaviateStore creates a new Weaviate vector store

type StoreType

type StoreType string

StoreType represents supported vector store types

const (
	TypePinecone StoreType = "pinecone" // Pinecone vector store
	TypeWeaviate StoreType = "weaviate" // Weaviate vector store
	TypeLocal    StoreType = "local"    // Local in-memory vector store
)

type Vector

type Vector []float32

Vector represents a high-dimensional vector

type WeaviateStore

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

WeaviateStore implements vector store using Weaviate

func (*WeaviateStore) Clear

func (s *WeaviateStore) Clear(ctx context.Context) error

func (*WeaviateStore) Close

func (s *WeaviateStore) Close() error

func (*WeaviateStore) Delete

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

func (*WeaviateStore) Get

func (s *WeaviateStore) Get(ctx context.Context, ids ...string) ([]Document, error)

func (*WeaviateStore) Insert

func (s *WeaviateStore) Insert(ctx context.Context, docs ...Document) error

func (*WeaviateStore) Search

func (s *WeaviateStore) Search(ctx context.Context, queryVector Vector, limit int) ([]SearchResult, error)

func (*WeaviateStore) Update

func (s *WeaviateStore) Update(ctx context.Context, docs ...Document) error

Jump to

Keyboard shortcuts

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