Documentation
¶
Index ¶
- Constants
- type Config
- type DistanceMetric
- type EmbeddingType
- type FlatIndexAdapter
- type HNSWIndexAdapter
- type IVFIndexAdapter
- type Index
- type IndexConfig
- type IndexType
- type Logger
- type PureGoVectorDB
- func (db *PureGoVectorDB) BatchGetByID(ids []string) ([]*Vector, error)
- func (db *PureGoVectorDB) Close() error
- func (db *PureGoVectorDB) Count() (int, error)
- func (db *PureGoVectorDB) Delete(id string) error
- func (db *PureGoVectorDB) Deletes(ids []string) error
- func (db *PureGoVectorDB) DisableAutoSave() error
- func (db *PureGoVectorDB) EnableAutoSave(interval time.Duration, savePath string) error
- func (db *PureGoVectorDB) ForceSave(path string) error
- func (db *PureGoVectorDB) GetBatchEmbeddingFunc() embedding.BatchEmbeddingFunc
- func (db *PureGoVectorDB) GetByID(id string) (*Vector, error)
- func (db *PureGoVectorDB) GetConfig() Config
- func (db *PureGoVectorDB) GetEmbeddingFunc() embedding.EmbeddingFunc
- func (db *PureGoVectorDB) Insert(vectors []Vector) error
- func (db *PureGoVectorDB) IsDirty() bool
- func (db *PureGoVectorDB) Load(path string) error
- func (db *PureGoVectorDB) Save(path string) error
- func (db *PureGoVectorDB) Search(query Vector, opts SearchOptions) ([]SearchResult, error)
- func (db *PureGoVectorDB) SetBatchEmbeddingFunc(fn embedding.BatchEmbeddingFunc)
- func (db *PureGoVectorDB) SetEmbeddingFunc(fn embedding.EmbeddingFunc)
- type SearchOptions
- type SearchResult
- type Storage
- type StorageType
- type Vector
- type VectorDB
Constants ¶
View Source
const ( Cosine = types.Cosine L2 = types.L2 InnerProduct = types.InnerProduct HNSW = types.HNSW IVF = types.IVF Flat = types.Flat Memory = types.Memory Badger = types.Badger BBolt = types.BBolt Pebble = types.Pebble MMap = types.MMap EmbeddingOpenAI = types.EmbeddingOpenAI EmbeddingTFIDF = types.EmbeddingTFIDF EmbeddingBM25 = types.EmbeddingBM25 EmbeddingBM25F = types.EmbeddingBM25F EmbeddingBM25L = types.EmbeddingBM25L EmbeddingBM25P = types.EmbeddingBM25P )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistanceMetric ¶
type DistanceMetric = types.DistanceMetric
type EmbeddingType ¶
type EmbeddingType = types.EmbeddingType
type FlatIndexAdapter ¶
type FlatIndexAdapter struct {
// contains filtered or unexported fields
}
FlatIndexAdapter Flat索引适配器
func (*FlatIndexAdapter) Count ¶
func (a *FlatIndexAdapter) Count() int
func (*FlatIndexAdapter) Delete ¶
func (a *FlatIndexAdapter) Delete(id int) error
func (*FlatIndexAdapter) Search ¶
func (a *FlatIndexAdapter) Search(query []float32, k int) []types.IndexSearchResult
type HNSWIndexAdapter ¶
type HNSWIndexAdapter struct {
// contains filtered or unexported fields
}
HNSWIndexAdapter HNSW索引适配器
func (*HNSWIndexAdapter) Count ¶
func (a *HNSWIndexAdapter) Count() int
func (*HNSWIndexAdapter) Delete ¶
func (a *HNSWIndexAdapter) Delete(id int) error
func (*HNSWIndexAdapter) Search ¶
func (a *HNSWIndexAdapter) Search(query []float32, k int) []types.IndexSearchResult
type IVFIndexAdapter ¶
type IVFIndexAdapter struct {
// contains filtered or unexported fields
}
IVFIndexAdapter IVF索引适配器
func (*IVFIndexAdapter) Count ¶
func (a *IVFIndexAdapter) Count() int
func (*IVFIndexAdapter) Delete ¶
func (a *IVFIndexAdapter) Delete(id int) error
func (*IVFIndexAdapter) Search ¶
func (a *IVFIndexAdapter) Search(query []float32, k int) []types.IndexSearchResult
type Index ¶
type Index interface {
// Insert 插入向量到索引
Insert(id int, vector []float32) error
// Search 搜索最近邻
Search(query []float32, k int) []types.IndexSearchResult
// Delete 从索引中删除向量
Delete(id int) error
// Count 返回索引中的向量数量
Count() int
}
Index 统一的索引接口
type IndexConfig ¶
type IndexConfig struct {
Dimension int
MaxVectors int
DistanceFunc func(a, b []float32) float32
// HNSW 参数
M int
EfConstruction int
// IVF 参数
NumClusters int
Nprobe int
}
IndexConfig 索引配置
type Logger ¶
type Logger interface {
Info(msg string, args ...interface{})
Error(msg string, args ...interface{})
Debug(msg string, args ...interface{})
Warn(msg string, args ...interface{})
}
Logger 日志接口
type PureGoVectorDB ¶
type PureGoVectorDB struct {
// contains filtered or unexported fields
}
PureGoVectorDB 纯 Go 向量数据库实现
func NewPureGoVectorDB ¶
func NewPureGoVectorDB(config Config) (*PureGoVectorDB, error)
NewPureGoVectorDB 创建向量数据库
func (*PureGoVectorDB) BatchGetByID ¶ added in v1.0.2
func (db *PureGoVectorDB) BatchGetByID(ids []string) ([]*Vector, error)
BatchGetByID 根据ID列表批量获取向量
func (*PureGoVectorDB) Deletes ¶ added in v1.0.4
func (db *PureGoVectorDB) Deletes(ids []string) error
Deletes 删除向量
func (*PureGoVectorDB) DisableAutoSave ¶
func (db *PureGoVectorDB) DisableAutoSave() error
DisableAutoSave 禁用自动保存
func (*PureGoVectorDB) EnableAutoSave ¶
func (db *PureGoVectorDB) EnableAutoSave(interval time.Duration, savePath string) error
EnableAutoSave 启用自动保存
func (*PureGoVectorDB) ForceSave ¶
func (db *PureGoVectorDB) ForceSave(path string) error
ForceSave 强制立即保存
func (*PureGoVectorDB) GetBatchEmbeddingFunc ¶
func (db *PureGoVectorDB) GetBatchEmbeddingFunc() embedding.BatchEmbeddingFunc
GetBatchEmbeddingFunc 获取批量Embedding函数
func (*PureGoVectorDB) GetByID ¶ added in v1.0.2
func (db *PureGoVectorDB) GetByID(id string) (*Vector, error)
GetByID 根据ID获取向量
func (*PureGoVectorDB) GetEmbeddingFunc ¶
func (db *PureGoVectorDB) GetEmbeddingFunc() embedding.EmbeddingFunc
GetEmbeddingFunc 获取Embedding函数
func (*PureGoVectorDB) Insert ¶
func (db *PureGoVectorDB) Insert(vectors []Vector) error
Insert 插入向量
func (*PureGoVectorDB) Search ¶
func (db *PureGoVectorDB) Search(query Vector, opts SearchOptions) ([]SearchResult, error)
Search 搜索向量
func (*PureGoVectorDB) SetBatchEmbeddingFunc ¶
func (db *PureGoVectorDB) SetBatchEmbeddingFunc(fn embedding.BatchEmbeddingFunc)
SetBatchEmbeddingFunc 设置批量Embedding函数
func (*PureGoVectorDB) SetEmbeddingFunc ¶
func (db *PureGoVectorDB) SetEmbeddingFunc(fn embedding.EmbeddingFunc)
SetEmbeddingFunc 设置Embedding函数
type SearchOptions ¶
type SearchOptions = types.SearchOptions
type SearchResult ¶
type SearchResult = types.SearchResult
type Storage ¶
type Storage interface {
Get(id string) (*Vector, error)
BatchGet(ids []string) ([]*Vector, error)
Put(vec *Vector) error
BatchPut(vectors []*Vector) error
Delete(id string) error
BatchDelete(ids []string) error
Iterate(fn func(*Vector) bool) error
Count() (int, error)
Save(path string) error
Load(path string) error
Close() error
}
Storage 存储接口
type StorageType ¶
type StorageType = types.StorageType
type VectorDB ¶
type VectorDB interface {
Insert(vectors []Vector) error
Delete(ids []string) error
Search(query Vector, opts SearchOptions) ([]SearchResult, error)
GetByID(id string) (*Vector, error)
BatchGetByID(ids []string) ([]*Vector, error)
Save(path string) error
Load(path string) error
Close() error
Count() (int, error)
}
VectorDB 向量数据库接口
Click to show internal directories.
Click to hide internal directories.