milvus

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package milvus 提供基于 Milvus 的消息检索

Package milvus 提供基于 Milvus 的消息存储

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocStore

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

DocStore 基于 Milvus 的通用文档存储

func NewDocStore

func NewDocStore(config *DocStoreConfig, embedding EmbeddingFunc) (*DocStore, error)

func (*DocStore) Close

func (d *DocStore) Close() error

func (*DocStore) DeleteCollection

func (d *DocStore) DeleteCollection(ctx context.Context, collection string) error

func (*DocStore) GetDocuments

func (d *DocStore) GetDocuments(ctx context.Context, collection string) ([]*schema.Document, error)

func (*DocStore) RecallDocuments

func (d *DocStore) RecallDocuments(ctx context.Context, collection string, query string, topK int) ([]*schema.Document, error)

func (*DocStore) SaveDocuments

func (d *DocStore) SaveDocuments(ctx context.Context, collection string, docs []*schema.Document) error

type DocStoreConfig

type DocStoreConfig struct {
	Addr       string
	Collection string // Milvus collection 名
	VectorDim  int
	Username   string
	Password   string
	DBName     string
	APIKey     string
	TLS        bool
}

func DefaultDocStoreConfig

func DefaultDocStoreConfig() *DocStoreConfig

type EmbeddingFunc

type EmbeddingFunc func(ctx context.Context, text string) ([]float32, error)

type IndexItem

type IndexItem struct {
	ID        string
	SessionID string
	Role      string
	Content   string
	Timestamp int64
	Embedding []float32
}

IndexItem 用于重建索引的数据项

type Retriever

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

Retriever 基于 Milvus 的检索器

func NewRetriever

func NewRetriever(config *RetrieverConfig, embedding EmbeddingFunc) (*Retriever, error)

func NewRetrieverFromStore

func NewRetrieverFromStore(store *Store, embedding EmbeddingFunc) (*Retriever, error)

NewRetrieverFromStore 从已有 Store 创建 Retriever(共享连接)

func (*Retriever) AddToIndex

func (r *Retriever) AddToIndex(ctx context.Context, id string, content string, embedding []float32) error

func (*Retriever) Close

func (r *Retriever) Close() error

func (*Retriever) IndexReady

func (r *Retriever) IndexReady() bool

func (*Retriever) RebuildIndex

func (r *Retriever) RebuildIndex(ctx context.Context, items []IndexItem) error

func (*Retriever) Recall

func (r *Retriever) Recall(ctx context.Context, sessionID string, query string, topK int) ([]*schema.Message, error)

func (*Retriever) RemoveFromIndex

func (r *Retriever) RemoveFromIndex(ctx context.Context, sessionID string) error

type RetrieverConfig

type RetrieverConfig struct {
	Addr       string // 默认 "localhost:19530"
	Collection string // 默认 "pulse_messages"
	VectorDim  int    // 默认 768

	// 认证配置(可选)
	Username string
	Password string
	DBName   string
	APIKey   string
	TLS      bool
}

RetrieverConfig Milvus 检索配置

func DefaultRetrieverConfig

func DefaultRetrieverConfig() *RetrieverConfig

type Store

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

Store 基于 Milvus 的消息持久化存储

func NewStore

func NewStore(config *StoreConfig) (*Store, error)

func NewStoreFromClient

func NewStoreFromClient(c client.Client, config *StoreConfig) (*Store, error)

NewStoreFromClient 从已有 client 创建 Store(与 Retriever 共享连接)

func (*Store) ClearSession

func (s *Store) ClearSession(ctx context.Context, sessionID string) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) GetClient

func (s *Store) GetClient() client.Client

GetClient 获取底层 Milvus 客户端(供 Retriever 共享连接)

func (*Store) GetSession

func (s *Store) GetSession(ctx context.Context, sessionID string) ([]*schema.Message, error)

func (*Store) Save

func (s *Store) Save(ctx context.Context, sessionID string, msgs []*schema.Message) error

type StoreConfig

type StoreConfig struct {
	Addr       string // 默认 "localhost:19530"
	Collection string // 默认 "pulse_messages"
	VectorDim  int    // 默认 768

	// 认证配置(可选)
	Username string // Milvus 用户名
	Password string // Milvus 密码
	DBName   string // 数据库名
	APIKey   string // API Key
	TLS      bool   // 启用 TLS
}

StoreConfig Milvus 存储配置

func DefaultStoreConfig

func DefaultStoreConfig() *StoreConfig

Jump to

Keyboard shortcuts

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