iface

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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 Config

type Config = types.Config

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 默认配置

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) Insert

func (a *FlatIndexAdapter) Insert(id int, vector []float32) 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) Insert

func (a *HNSWIndexAdapter) Insert(id int, vector []float32) 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) Insert

func (a *IVFIndexAdapter) Insert(id int, vector []float32) 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 统一的索引接口

func NewFlatIndex

func NewFlatIndex(config IndexConfig) Index

NewFlatIndex 创建Flat索引

func NewHNSWIndex

func NewHNSWIndex(config IndexConfig) Index

NewHNSWIndex 创建HNSW索引

func NewIVFIndex

func NewIVFIndex(config IndexConfig) Index

NewIVFIndex 创建IVF索引

func NewIndex

func NewIndex(indexType IndexType, config IndexConfig) (Index, error)

NewIndex 创建索引

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 IndexType

type IndexType = types.IndexType

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 日志接口

func NewLogger

func NewLogger(name string) Logger

NewLogger 创建日志包装器

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) Close

func (db *PureGoVectorDB) Close() error

Close 关闭数据库

func (*PureGoVectorDB) Count

func (db *PureGoVectorDB) Count() (int, error)

Count 获取向量数量

func (*PureGoVectorDB) Delete

func (db *PureGoVectorDB) Delete(id string) error

Delete 删除向量

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) GetConfig

func (db *PureGoVectorDB) GetConfig() Config

GetConfig 获取数据库配置

func (*PureGoVectorDB) GetEmbeddingFunc

func (db *PureGoVectorDB) GetEmbeddingFunc() embedding.EmbeddingFunc

GetEmbeddingFunc 获取Embedding函数

func (*PureGoVectorDB) Insert

func (db *PureGoVectorDB) Insert(vectors []Vector) error

Insert 插入向量

func (*PureGoVectorDB) IsDirty

func (db *PureGoVectorDB) IsDirty() bool

IsDirty 检查是否有未保存的数据

func (*PureGoVectorDB) Load

func (db *PureGoVectorDB) Load(path string) error

Load 加载数据库

func (*PureGoVectorDB) Save

func (db *PureGoVectorDB) Save(path string) error

Save 保存数据库

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 Vector

type Vector = types.Vector

从 types 包导入所有类型

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 向量数据库接口

Jump to

Keyboard shortcuts

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