indexer

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package indexer 提供 RAG 系统的文档索引器

本文件实现知识图谱索引器:

  • GraphIndexer: 基于知识图谱的索引器
  • Entity: 实体节点
  • Relation: 实体关系
  • GraphStore: 图存储接口
  • MemoryGraphStore: 内存图存储实现

知识图谱索引可以:

  • 提取文档中的实体和关系
  • 构建知识图谱
  • 支持图遍历查询
  • 与向量检索结合使用

设计参考:

  • LlamaIndex KnowledgeGraphIndex
  • Neo4j GraphRAG
  • Microsoft GraphRAG

Package indexer 提供 RAG 系统的文档索引器

Indexer 用于将文档向量化并存储到向量数据库:

  • VectorIndexer: 基于向量存储的索引器
  • BatchIndexer: 批量索引器

Package indexer 提供文档索引功能

本文件实现 SQL 索引:

  • 结构化数据索引
  • SQL 查询接口
  • 表结构自动推断
  • 查询优化

设计借鉴:

  • LlamaIndex: SQL Index
  • LangChain: SQL Database
  • DuckDB: 嵌入式分析

Index

Constants

View Source
const (
	// DefaultEntityQueryLimit 默认实体查询限制
	// 用于批量删除等操作时的最大查询数量
	DefaultEntityQueryLimit = 10000

	// DefaultBatchSize 默认批处理大小
	DefaultBatchSize = 1000
)

索引器默认配置常量

Variables

View Source
var DefaultImportOptions = ImportOptions{
	BatchSize:   1000,
	CreateTable: true,
	OnConflict:  "error",
}

DefaultImportOptions 默认导入选项

Functions

This section is empty.

Types

type ColumnInfo

type ColumnInfo struct {
	// Name 列名
	Name string `json:"name"`

	// Type 数据类型
	Type string `json:"type"`

	// Nullable 是否可空
	Nullable bool `json:"nullable"`

	// Default 默认值
	Default *string `json:"default,omitempty"`

	// Description 列描述
	Description string `json:"description,omitempty"`

	// IsPrimaryKey 是否主键
	IsPrimaryKey bool `json:"is_primary_key,omitempty"`

	// ForeignKey 外键引用
	ForeignKey *ForeignKeyInfo `json:"foreign_key,omitempty"`
}

ColumnInfo 列信息

type ConcurrentIndexer

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

ConcurrentIndexer 并发索引器

func NewConcurrentIndexer

func NewConcurrentIndexer(store vector.Store, embedder vector.Embedder, opts ...ConcurrentIndexerOption) *ConcurrentIndexer

NewConcurrentIndexer 创建并发索引器

func (*ConcurrentIndexer) Clear

func (i *ConcurrentIndexer) Clear(ctx context.Context) error

Clear 清空索引

func (*ConcurrentIndexer) Count

func (i *ConcurrentIndexer) Count(ctx context.Context) (int, error)

Count 返回文档数量

func (*ConcurrentIndexer) Delete

func (i *ConcurrentIndexer) Delete(ctx context.Context, ids []string) error

Delete 删除文档

func (*ConcurrentIndexer) Index

func (i *ConcurrentIndexer) Index(ctx context.Context, docs []rag.Document) error

Index 并发索引文档

type ConcurrentIndexerOption

type ConcurrentIndexerOption func(*ConcurrentIndexer)

ConcurrentIndexerOption ConcurrentIndexer 选项

func WithConcurrency

func WithConcurrency(n int) ConcurrentIndexerOption

WithConcurrency 设置并发数

func WithConcurrentBatchSize

func WithConcurrentBatchSize(size int) ConcurrentIndexerOption

WithConcurrentBatchSize 设置批量大小

type Entity

type Entity struct {
	// ID 实体唯一标识
	ID string `json:"id"`

	// Name 实体名称
	Name string `json:"name"`

	// Type 实体类型
	Type EntityType `json:"type"`

	// Description 实体描述
	Description string `json:"description,omitempty"`

	// Properties 实体属性
	Properties map[string]any `json:"properties,omitempty"`

	// SourceDocIDs 来源文档ID列表
	SourceDocIDs []string `json:"source_doc_ids,omitempty"`

	// Embedding 实体向量 (可选)
	Embedding []float32 `json:"embedding,omitempty"`

	// CreatedAt 创建时间
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt 更新时间
	UpdatedAt time.Time `json:"updated_at"`
}

Entity 实体节点

type EntityExtractor

type EntityExtractor interface {
	// Extract 从文本中抽取实体和关系
	Extract(ctx context.Context, text string) ([]*Entity, []*Relation, error)
}

EntityExtractor 实体抽取器接口

type EntityQuery

type EntityQuery struct {
	// Types 实体类型过滤
	Types []EntityType

	// NamePattern 名称模式 (支持通配符)
	NamePattern string

	// Properties 属性过滤
	Properties map[string]any

	// Limit 返回数量限制
	Limit int

	// Offset 偏移量
	Offset int
}

EntityQuery 实体查询条件

type EntityType

type EntityType string

EntityType 实体类型

const (
	// 常见实体类型
	EntityTypePerson       EntityType = "PERSON"       // 人物
	EntityTypeOrganization EntityType = "ORGANIZATION" // 组织
	EntityTypeLocation     EntityType = "LOCATION"     // 地点
	EntityTypeEvent        EntityType = "EVENT"        // 事件
	EntityTypeConcept      EntityType = "CONCEPT"      // 概念
	EntityTypeProduct      EntityType = "PRODUCT"      // 产品
	EntityTypeTechnology   EntityType = "TECHNOLOGY"   // 技术
	EntityTypeDate         EntityType = "DATE"         // 日期
	EntityTypeOther        EntityType = "OTHER"        // 其他
)

type ForeignKeyInfo

type ForeignKeyInfo struct {
	// Table 引用表
	Table string `json:"table"`

	// Column 引用列
	Column string `json:"column"`
}

ForeignKeyInfo 外键信息

type GraphContext

type GraphContext struct {
	// Entities 相关实体
	Entities []*Entity

	// Relations 相关关系
	Relations []*Relation

	// Triples 三元组列表
	Triples []Triple
}

GraphContext 图检索上下文

func (*GraphContext) ToText

func (gc *GraphContext) ToText() string

ToText 转换为文本描述

type GraphIndexer

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

GraphIndexer 知识图谱索引器

func NewGraphIndexer

func NewGraphIndexer(store GraphStore, opts ...GraphIndexerOption) *GraphIndexer

NewGraphIndexer 创建知识图谱索引器

func (*GraphIndexer) Clear

func (i *GraphIndexer) Clear(ctx context.Context) error

Clear 清空索引

func (*GraphIndexer) Count

func (i *GraphIndexer) Count(ctx context.Context) (int, error)

Count 返回实体数量

func (*GraphIndexer) Delete

func (i *GraphIndexer) Delete(ctx context.Context, ids []string) error

Delete 删除文档相关实体

func (*GraphIndexer) Index

func (i *GraphIndexer) Index(ctx context.Context, docs []rag.Document) error

Index 索引文档到知识图谱

func (*GraphIndexer) Store

func (i *GraphIndexer) Store() GraphStore

Store 获取底层图存储

type GraphIndexerOption

type GraphIndexerOption func(*GraphIndexer)

GraphIndexerOption GraphIndexer 选项

func WithExtractor

func WithExtractor(extractor EntityExtractor) GraphIndexerOption

WithExtractor 设置实体抽取器

func WithGraphBatchSize

func WithGraphBatchSize(size int) GraphIndexerOption

WithGraphBatchSize 设置批量大小

type GraphRetriever

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

GraphRetriever 基于知识图谱的检索器

func NewGraphRetriever

func NewGraphRetriever(store GraphStore, opts ...GraphRetrieverOption) *GraphRetriever

NewGraphRetriever 创建图检索器

func (*GraphRetriever) Retrieve

func (r *GraphRetriever) Retrieve(ctx context.Context, query string) (*GraphContext, error)

Retrieve 基于查询检索相关实体和上下文

type GraphRetrieverOption

type GraphRetrieverOption func(*GraphRetriever)

GraphRetrieverOption GraphRetriever 选项

func WithMaxDepth

func WithMaxDepth(depth int) GraphRetrieverOption

WithMaxDepth 设置最大遍历深度

func WithMaxResults

func WithMaxResults(max int) GraphRetrieverOption

WithMaxResults 设置最大结果数

type GraphStats

type GraphStats struct {
	// EntityCount 实体数量
	EntityCount int

	// RelationCount 关系数量
	RelationCount int

	// EntityTypeCounts 各类型实体数量
	EntityTypeCounts map[EntityType]int

	// RelationTypeCounts 各类型关系数量
	RelationTypeCounts map[RelationType]int
}

GraphStats 图统计信息

type GraphStore

type GraphStore interface {
	// AddEntity 添加实体
	AddEntity(ctx context.Context, entity *Entity) error

	// AddEntities 批量添加实体
	AddEntities(ctx context.Context, entities []*Entity) error

	// GetEntity 获取实体
	GetEntity(ctx context.Context, id string) (*Entity, error)

	// GetEntityByName 按名称获取实体
	GetEntityByName(ctx context.Context, name string) (*Entity, error)

	// SearchEntities 搜索实体
	SearchEntities(ctx context.Context, query EntityQuery) ([]*Entity, error)

	// UpdateEntity 更新实体
	UpdateEntity(ctx context.Context, entity *Entity) error

	// DeleteEntity 删除实体
	DeleteEntity(ctx context.Context, id string) error

	// AddRelation 添加关系
	AddRelation(ctx context.Context, relation *Relation) error

	// AddRelations 批量添加关系
	AddRelations(ctx context.Context, relations []*Relation) error

	// GetRelation 获取关系
	GetRelation(ctx context.Context, id string) (*Relation, error)

	// GetRelations 获取实体的关系
	GetRelations(ctx context.Context, entityID string, direction RelationDirection) ([]*Relation, error)

	// SearchRelations 搜索关系
	SearchRelations(ctx context.Context, query RelationQuery) ([]*Relation, error)

	// DeleteRelation 删除关系
	DeleteRelation(ctx context.Context, id string) error

	// GetNeighbors 获取邻居实体
	GetNeighbors(ctx context.Context, entityID string, depth int) ([]*Entity, error)

	// GetSubgraph 获取子图
	GetSubgraph(ctx context.Context, entityIDs []string, depth int) (*Subgraph, error)

	// Clear 清空图
	Clear(ctx context.Context) error

	// Stats 获取统计信息
	Stats(ctx context.Context) (*GraphStats, error)
}

GraphStore 图存储接口

type ImportOptions

type ImportOptions struct {
	// BatchSize 批量大小
	BatchSize int

	// CreateTable 自动创建表
	CreateTable bool

	// TruncateFirst 先清空表
	TruncateFirst bool

	// OnConflict 冲突处理
	OnConflict string // "ignore", "update", "error"
}

ImportOptions 导入选项

type IncrementalIndexer

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

IncrementalIndexer 增量索引器 只索引新增或变更的文档

func NewIncrementalIndexer

func NewIncrementalIndexer(store vector.Store, embedder vector.Embedder, opts ...IncrementalIndexerOption) *IncrementalIndexer

NewIncrementalIndexer 创建增量索引器

func (*IncrementalIndexer) Clear

func (i *IncrementalIndexer) Clear(ctx context.Context) error

Clear 清空索引

func (*IncrementalIndexer) Count

func (i *IncrementalIndexer) Count(ctx context.Context) (int, error)

Count 返回文档数量

func (*IncrementalIndexer) Delete

func (i *IncrementalIndexer) Delete(ctx context.Context, ids []string) error

Delete 删除文档

func (*IncrementalIndexer) Index

func (i *IncrementalIndexer) Index(ctx context.Context, docs []rag.Document) error

Index 增量索引文档

type IncrementalIndexerOption

type IncrementalIndexerOption func(*IncrementalIndexer)

IncrementalIndexerOption IncrementalIndexer 选项

func WithIncrementalBatchSize

func WithIncrementalBatchSize(size int) IncrementalIndexerOption

WithIncrementalBatchSize 设置批量大小

type IndexInfo

type IndexInfo struct {
	// Name 索引名
	Name string `json:"name"`

	// Columns 索引列
	Columns []string `json:"columns"`

	// Unique 是否唯一
	Unique bool `json:"unique"`
}

IndexInfo 索引信息

type LLMEntityExtractor

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

LLMEntityExtractor 基于 LLM 的实体抽取器

func NewLLMEntityExtractor

func NewLLMEntityExtractor(provider llm.Provider, opts ...LLMExtractorOption) *LLMEntityExtractor

NewLLMEntityExtractor 创建 LLM 实体抽取器

func (*LLMEntityExtractor) Extract

func (e *LLMEntityExtractor) Extract(ctx context.Context, text string) ([]*Entity, []*Relation, error)

Extract 从文本中抽取实体和关系

type LLMExtractorOption

type LLMExtractorOption func(*LLMEntityExtractor)

LLMExtractorOption LLM 抽取器选项

func WithEntityTypes

func WithEntityTypes(types ...EntityType) LLMExtractorOption

WithEntityTypes 设置要抽取的实体类型

func WithExtractorModel

func WithExtractorModel(model string) LLMExtractorOption

WithExtractorModel 设置模型

type MemoryGraphStore

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

MemoryGraphStore 内存图存储

func NewMemoryGraphStore

func NewMemoryGraphStore() *MemoryGraphStore

NewMemoryGraphStore 创建内存图存储

func (*MemoryGraphStore) AddEntities

func (s *MemoryGraphStore) AddEntities(ctx context.Context, entities []*Entity) error

AddEntities 批量添加实体

func (*MemoryGraphStore) AddEntity

func (s *MemoryGraphStore) AddEntity(ctx context.Context, entity *Entity) error

AddEntity 添加实体

func (*MemoryGraphStore) AddRelation

func (s *MemoryGraphStore) AddRelation(ctx context.Context, relation *Relation) error

AddRelation 添加关系

func (*MemoryGraphStore) AddRelations

func (s *MemoryGraphStore) AddRelations(ctx context.Context, relations []*Relation) error

AddRelations 批量添加关系

func (*MemoryGraphStore) Clear

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

Clear 清空图

func (*MemoryGraphStore) DeleteEntity

func (s *MemoryGraphStore) DeleteEntity(ctx context.Context, id string) error

DeleteEntity 删除实体

func (*MemoryGraphStore) DeleteRelation

func (s *MemoryGraphStore) DeleteRelation(ctx context.Context, id string) error

DeleteRelation 删除关系

func (*MemoryGraphStore) GetEntity

func (s *MemoryGraphStore) GetEntity(ctx context.Context, id string) (*Entity, error)

GetEntity 获取实体

func (*MemoryGraphStore) GetEntityByName

func (s *MemoryGraphStore) GetEntityByName(ctx context.Context, name string) (*Entity, error)

GetEntityByName 按名称获取实体

func (*MemoryGraphStore) GetNeighbors

func (s *MemoryGraphStore) GetNeighbors(ctx context.Context, entityID string, depth int) ([]*Entity, error)

GetNeighbors 获取邻居实体

func (*MemoryGraphStore) GetRelation

func (s *MemoryGraphStore) GetRelation(ctx context.Context, id string) (*Relation, error)

GetRelation 获取关系

func (*MemoryGraphStore) GetRelations

func (s *MemoryGraphStore) GetRelations(ctx context.Context, entityID string, direction RelationDirection) ([]*Relation, error)

GetRelations 获取实体的关系

func (*MemoryGraphStore) GetSubgraph

func (s *MemoryGraphStore) GetSubgraph(ctx context.Context, entityIDs []string, depth int) (*Subgraph, error)

GetSubgraph 获取子图

func (*MemoryGraphStore) SearchEntities

func (s *MemoryGraphStore) SearchEntities(ctx context.Context, query EntityQuery) ([]*Entity, error)

SearchEntities 搜索实体

func (*MemoryGraphStore) SearchRelations

func (s *MemoryGraphStore) SearchRelations(ctx context.Context, query RelationQuery) ([]*Relation, error)

SearchRelations 搜索关系

func (*MemoryGraphStore) Stats

func (s *MemoryGraphStore) Stats(ctx context.Context) (*GraphStats, error)

Stats 获取统计信息

func (*MemoryGraphStore) UpdateEntity

func (s *MemoryGraphStore) UpdateEntity(ctx context.Context, entity *Entity) error

UpdateEntity 更新实体

type NLQuery

type NLQuery interface {
	// ToSQL 转换为 SQL
	ToSQL(ctx context.Context, question string, tables []*TableInfo) (string, error)
}

NLQuery 自然语言查询接口

type QueryBuilder

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

QueryBuilder 查询构建器

func NewQueryBuilder

func NewQueryBuilder(table string) *QueryBuilder

NewQueryBuilder 创建查询构建器

func (*QueryBuilder) Build

func (b *QueryBuilder) Build() string

Build 构建 SQL

func (*QueryBuilder) GroupBy

func (b *QueryBuilder) GroupBy(group string) *QueryBuilder

GroupBy 分组

func (*QueryBuilder) Having

func (b *QueryBuilder) Having(having string) *QueryBuilder

Having HAVING 条件

func (*QueryBuilder) Join

func (b *QueryBuilder) Join(join string) *QueryBuilder

Join 添加 JOIN

func (*QueryBuilder) Limit

func (b *QueryBuilder) Limit(limit int) *QueryBuilder

Limit 限制数量

func (*QueryBuilder) Offset

func (b *QueryBuilder) Offset(offset int) *QueryBuilder

Offset 偏移

func (*QueryBuilder) OrderBy

func (b *QueryBuilder) OrderBy(order string) *QueryBuilder

OrderBy 排序

func (*QueryBuilder) Select

func (b *QueryBuilder) Select(columns ...string) *QueryBuilder

Select 选择列

不传任何列名时退回默认的 "*", 避免 Build 生成非法 SQL "SELECT FROM t"。

func (*QueryBuilder) Where

func (b *QueryBuilder) Where(condition string) *QueryBuilder

Where 添加条件

type QueryResult

type QueryResult struct {
	// Columns 列名
	Columns []string `json:"columns"`

	// Rows 行数据
	Rows []map[string]any `json:"rows"`

	// RowCount 行数
	RowCount int `json:"row_count"`

	// Query 执行的查询
	Query string `json:"query,omitempty"`
}

QueryResult 查询结果

type Relation

type Relation struct {
	// ID 关系唯一标识
	ID string `json:"id"`

	// SourceID 源实体ID
	SourceID string `json:"source_id"`

	// TargetID 目标实体ID
	TargetID string `json:"target_id"`

	// Type 关系类型
	Type RelationType `json:"type"`

	// Description 关系描述
	Description string `json:"description,omitempty"`

	// Weight 关系权重 (0-1)
	Weight float64 `json:"weight"`

	// Properties 关系属性
	Properties map[string]any `json:"properties,omitempty"`

	// SourceDocIDs 来源文档ID列表
	SourceDocIDs []string `json:"source_doc_ids,omitempty"`

	// CreatedAt 创建时间
	CreatedAt time.Time `json:"created_at"`
}

Relation 关系边

type RelationDirection

type RelationDirection string

RelationDirection 关系方向

const (
	RelationDirectionOutgoing RelationDirection = "outgoing" // 出边
	RelationDirectionIncoming RelationDirection = "incoming" // 入边
	RelationDirectionBoth     RelationDirection = "both"     // 双向
)

type RelationQuery

type RelationQuery struct {
	// SourceID 源实体ID
	SourceID string

	// TargetID 目标实体ID
	TargetID string

	// Types 关系类型过滤
	Types []RelationType

	// MinWeight 最小权重
	MinWeight float64

	// Limit 返回数量限制
	Limit int
}

RelationQuery 关系查询条件

type RelationType

type RelationType string

RelationType 关系类型

const (
	// 常见关系类型
	RelationTypeIsA        RelationType = "IS_A"        // 是一种
	RelationTypePartOf     RelationType = "PART_OF"     // 是...的一部分
	RelationTypeHasA       RelationType = "HAS_A"       // 拥有
	RelationTypeRelatedTo  RelationType = "RELATED_TO"  // 相关
	RelationTypeCreatedBy  RelationType = "CREATED_BY"  // 由...创建
	RelationTypeLocatedIn  RelationType = "LOCATED_IN"  // 位于
	RelationTypeWorksFor   RelationType = "WORKS_FOR"   // 为...工作
	RelationTypeOccurredOn RelationType = "OCCURRED_ON" // 发生于
	RelationTypeUsedFor    RelationType = "USED_FOR"    // 用于
	RelationTypeCausedBy   RelationType = "CAUSED_BY"   // 由...引起
)

type RuleBasedExtractor

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

RuleBasedExtractor 基于规则的实体抽取器

func NewRuleBasedExtractor

func NewRuleBasedExtractor() *RuleBasedExtractor

NewRuleBasedExtractor 创建基于规则的抽取器

func (*RuleBasedExtractor) AddPattern

func (e *RuleBasedExtractor) AddPattern(entityType EntityType, pattern string) error

AddPattern 添加抽取模式

func (*RuleBasedExtractor) Extract

func (e *RuleBasedExtractor) Extract(ctx context.Context, text string) ([]*Entity, []*Relation, error)

Extract 从文本中抽取实体

type SQLIndex

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

SQLIndex SQL 索引

func NewSQLIndex

func NewSQLIndex(db *sql.DB, config ...SQLIndexConfig) *SQLIndex

NewSQLIndex 创建 SQL 索引

func (*SQLIndex) Close

func (idx *SQLIndex) Close() error

Close 关闭连接

func (*SQLIndex) Execute

func (idx *SQLIndex) Execute(ctx context.Context, query string, args ...any) (sql.Result, error)

Execute 执行非查询语句

func (*SQLIndex) ExportSchema

func (idx *SQLIndex) ExportSchema() ([]byte, error)

ExportSchema 导出 Schema(JSON 格式)

func (*SQLIndex) GenerateSchemaDescription

func (idx *SQLIndex) GenerateSchemaDescription() string

GenerateSchemaDescription 生成 Schema 描述(用于 LLM)

func (*SQLIndex) GetAllTables

func (idx *SQLIndex) GetAllTables() []*TableInfo

GetAllTables 获取所有表

func (*SQLIndex) GetTableInfo

func (idx *SQLIndex) GetTableInfo(tableName string) (*TableInfo, bool)

GetTableInfo 获取表信息

func (*SQLIndex) Import

func (idx *SQLIndex) Import(ctx context.Context, tableName string, data []map[string]any, opts ...ImportOptions) error

Import 导入数据

func (*SQLIndex) LoadSchema

func (idx *SQLIndex) LoadSchema(ctx context.Context) error

LoadSchema 加载数据库 Schema

func (*SQLIndex) Query

func (idx *SQLIndex) Query(ctx context.Context, query string, args ...any) (*QueryResult, error)

Query 执行查询

type SQLIndexConfig

type SQLIndexConfig struct {
	// Driver 数据库驱动
	Driver string

	// DSN 数据源名称
	DSN string

	// MaxOpenConns 最大连接数
	MaxOpenConns int

	// MaxIdleConns 最大空闲连接数
	MaxIdleConns int

	// TablePrefix 表前缀
	TablePrefix string

	// AutoMigrate 自动迁移
	AutoMigrate bool
}

SQLIndexConfig SQL 索引配置

type Subgraph

type Subgraph struct {
	// Entities 实体列表
	Entities []*Entity

	// Relations 关系列表
	Relations []*Relation
}

Subgraph 子图

type TableInfo

type TableInfo struct {
	// Name 表名
	Name string `json:"name"`

	// Columns 列信息
	Columns []*ColumnInfo `json:"columns"`

	// PrimaryKey 主键
	PrimaryKey string `json:"primary_key,omitempty"`

	// Indexes 索引
	Indexes []*IndexInfo `json:"indexes,omitempty"`

	// Description 表描述
	Description string `json:"description,omitempty"`

	// RowCount 行数(估算)
	RowCount int64 `json:"row_count,omitempty"`
}

TableInfo 表信息

type Triple

type Triple struct {
	Subject   string       `json:"subject"`
	Predicate RelationType `json:"predicate"`
	Object    string       `json:"object"`
}

Triple 三元组 (主语-谓语-宾语)

type VectorIndexer

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

VectorIndexer 向量索引器

func NewVectorIndexer

func NewVectorIndexer(store vector.Store, embedder vector.Embedder, opts ...VectorIndexerOption) *VectorIndexer

NewVectorIndexer 创建向量索引器

func (*VectorIndexer) Clear

func (i *VectorIndexer) Clear(ctx context.Context) error

Clear 清空索引

func (*VectorIndexer) Count

func (i *VectorIndexer) Count(ctx context.Context) (int, error)

Count 返回文档数量

func (*VectorIndexer) Delete

func (i *VectorIndexer) Delete(ctx context.Context, ids []string) error

Delete 删除文档

func (*VectorIndexer) Index

func (i *VectorIndexer) Index(ctx context.Context, docs []rag.Document) error

Index 索引文档

type VectorIndexerOption

type VectorIndexerOption func(*VectorIndexer)

VectorIndexerOption VectorIndexer 选项

func WithBatchSize

func WithBatchSize(size int) VectorIndexerOption

WithBatchSize 设置批量大小

Jump to

Keyboard shortcuts

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