vector

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortHybridResults

func SortHybridResults(results []HybridSearchResult)

SortHybridResults trie les résultats par score combiné décroissant

Types

type DocumentData

type DocumentData struct {
	ID       string `json:"id"`
	Content  string `json:"content"`
	Metadata string `json:"metadata"`
}

DocumentData represents the data structure for Bleve indexing

type EnhancedHybridStore

type EnhancedHybridStore struct {
	VectorStore VectorStoreInterface `json:"-"`
	TextIndex   bleve.Index          `json:"-"`
	WeightBM25  float64              `json:"weight_bm25"`
	// contains filtered or unexported fields
}

EnhancedHybridStore combines HNSW vector search and BM25 text search

func NewEnhancedHybridStore

func NewEnhancedHybridStore(indexPath string, dimensions int) (*EnhancedHybridStore, error)

NewEnhancedHybridStore creates a new enhanced hybrid store

func (*EnhancedHybridStore) Add

func (hs *EnhancedHybridStore) Add(id string, vector []float32)

Add implements the VectorStoreInterface

func (*EnhancedHybridStore) AddDocument

func (hs *EnhancedHybridStore) AddDocument(id string, content string, metadata string, vector []float32) error

AddDocument adds a document to both the vector and text indexes

func (*EnhancedHybridStore) Close

func (hs *EnhancedHybridStore) Close() error

Close properly closes the indexes

func (*EnhancedHybridStore) GetContent

func (hs *EnhancedHybridStore) GetContent(id string) string

GetContent returns a document's content

func (*EnhancedHybridStore) GetMetadata

func (hs *EnhancedHybridStore) GetMetadata(id string) string

GetMetadata returns a document's metadata

func (*EnhancedHybridStore) HybridSearch

func (hs *EnhancedHybridStore) HybridSearch(queryVector []float32, queryText string, limit int) ([]HybridSearchResult, error)

HybridSearch performs a combined vector and text search

func (*EnhancedHybridStore) Load

func (hs *EnhancedHybridStore) Load(path string) error

Load loads the store from a file

func (*EnhancedHybridStore) Remove

func (hs *EnhancedHybridStore) Remove(id string)

Remove removes a document from both indexes

func (*EnhancedHybridStore) Save

func (hs *EnhancedHybridStore) Save(vectorPath string) error

Save saves both indexes

func (*EnhancedHybridStore) Search

func (hs *EnhancedHybridStore) Search(query []float32, limit int) []SearchResult

Search implements the basic vector search interface

type HNSWStore

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

HNSWStore implements a vector store using a simpler approximation since the full HNSW algorithm isn't available

func NewHNSWStore

func NewHNSWStore(dimensions int) *HNSWStore

NewHNSWStore creates a new vector store

func (*HNSWStore) Add

func (s *HNSWStore) Add(id string, vector []float32)

Add adds a vector to the store

func (*HNSWStore) Load

func (s *HNSWStore) Load(path string) error

Load loads the vector store from disk

func (*HNSWStore) Remove

func (s *HNSWStore) Remove(id string)

Remove removes a vector from the store

func (*HNSWStore) Save

func (s *HNSWStore) Save(path string) error

Save saves the vector store to disk

func (*HNSWStore) Search

func (s *HNSWStore) Search(query []float32, limit int) []SearchResult

Search searches for similar vectors using cosine similarity

type HybridSearchResult

type HybridSearchResult struct {
	ID            string  `json:"id"`
	VectorScore   float64 `json:"vector_score"`
	TextScore     float64 `json:"text_score"`
	CombinedScore float64 `json:"combined_score"`
}

HybridSearchResult représente un résultat de recherche hybride

type SearchResult

type SearchResult struct {
	ID    string  `json:"id"`
	Score float64 `json:"score"`
}

SearchResult represents a search result

type Store

type Store struct {
	Items []VectorItem `json:"items"`
}

Store is a simple vector storage with cosine similarity search

func NewStore

func NewStore() *Store

NewStore creates a new vector storage

func (*Store) Add

func (s *Store) Add(id string, vector []float32)

Add adds a vector to the storage

func (*Store) Load

func (s *Store) Load(path string) error

Load loads the vector storage from a file

func (*Store) Remove

func (s *Store) Remove(id string)

Remove removes a vector from the storage by its ID

func (*Store) Save

func (s *Store) Save(path string) error

Save saves the vector storage to a file

func (*Store) Search

func (s *Store) Search(query []float32, limit int) []SearchResult

Search searches for the most similar vectors

type VectorItem

type VectorItem struct {
	ID     string    `json:"id"`
	Vector []float32 `json:"vector"`
}

VectorItem represents an item in the vector storage

type VectorStoreInterface

type VectorStoreInterface interface {
	Add(id string, vector []float32)
	Search(query []float32, limit int) []SearchResult
	Remove(id string)
	Save(path string) error
	Load(path string) error
}

VectorStoreInterface defines the common interface for vector stores

Jump to

Keyboard shortcuts

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