Documentation
¶
Index ¶
- func GetChunks(content string, opts ...ChunkOption) ([]*core.Chunk, error)
- func GetFileChunks(file string, opts ...ChunkOption) ([]*core.Chunk, error)
- func NewFulltextIndexer(store core.FullTextStore) (core.Indexer, error)
- func NewFulltextIndexerWithFile(dbPath string) (core.Indexer, error)
- func NewSafeFulltextIndexer(dbPath string) (core.Indexer, error)
- func NewSemanticIndexer(db core.VectorStore, embedder core.Embedder) core.Indexer
- type ChunkOption
- type CommunityIndexer
- type GraphIndexer
- func (g *GraphIndexer) Add(ctx context.Context, content string) (*core.Chunk, error)
- func (g *GraphIndexer) AddFile(ctx context.Context, filePath string) (*core.Chunk, error)
- func (g *GraphIndexer) Close(ctx context.Context) error
- func (g *GraphIndexer) DB() core.GraphStore
- func (g *GraphIndexer) IndexChunk(ctx context.Context, chunk *core.Chunk) error
- func (g *GraphIndexer) IndexChunks(ctx context.Context, chunks []*core.Chunk) error
- func (g *GraphIndexer) Name() string
- func (g *GraphIndexer) NewQuery(terms string) core.Query
- func (g *GraphIndexer) Remove(ctx context.Context, chunkID string) error
- func (g *GraphIndexer) Search(ctx context.Context, qry core.Query) ([]core.Hit, error)
- func (g *GraphIndexer) SearchByChunkIDs(ctx context.Context, chunkIDs []string, depth, limit int, ...) ([]core.Hit, error)
- func (g *GraphIndexer) SearchGlobal(ctx context.Context, query string, level int) ([]core.Hit, error)
- func (g *GraphIndexer) Type() string
- type GraphOption
- type GraphSearchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChunks ¶
func GetChunks(content string, opts ...ChunkOption) ([]*core.Chunk, error)
GetChunks 根据文本内容进行结构化和分块 如果没有指定策略,会根据内容自动选择最佳分块策略 返回完整的分块数组
func GetFileChunks ¶
func GetFileChunks(file string, opts ...ChunkOption) ([]*core.Chunk, error)
GetFileChunks 根据文件路径进行结构化和分块 如果没有指定策略,会根据内容自动选择最佳分块策略 返回完整的分块数组
func NewFulltextIndexer ¶
func NewFulltextIndexer(store core.FullTextStore) (core.Indexer, error)
func NewFulltextIndexerWithFile ¶
NewFulltextIndexer 创建全文索引器
func NewSafeFulltextIndexer ¶
NewSafeFulltextIndexer 创建线程安全的全文索引器
func NewSemanticIndexer ¶
Types ¶
type ChunkOption ¶
type ChunkOption func(*chunkOption)
ChunkOption 分块选项
func WithChunkStrategy ¶
func WithChunkStrategy(strategy core.ChunkStrategy) ChunkOption
WithChunkStrategy 设置分块策略
type CommunityIndexer ¶
type CommunityIndexer struct {
// contains filtered or unexported fields
}
CommunityIndexer 社区索引器 负责:社区检测 → 摘要生成 → 存储 → Global Search 查询
func NewCommunityIndexer ¶
func NewCommunityIndexer(store core.GraphStore, client chat.Client, detector ...core.CommunityDetector) *CommunityIndexer
NewCommunityIndexer 创建社区索引器 detector 参数可选,如果为 nil 则使用默认的连通分量检测器
func (*CommunityIndexer) Build ¶
func (ci *CommunityIndexer) Build(ctx context.Context, maxLevel int) error
Build 执行完整的社区构建流程 1. 社区检测(纯图算法) 2. 社区摘要生成(LLM) 3. 摘要存储到图数据库 maxLevel: 层次聚类最大深度(0 = 单层)
func (*CommunityIndexer) SearchGlobal ¶
func (ci *CommunityIndexer) SearchGlobal(ctx context.Context, query string, level int) ([]core.CommunityMatch, error)
SearchGlobal 通过社区摘要回答全局性问题 (Global Search) 流程:获取社区摘要 → LLM Map-Reduce 生成答案 返回匹配的社区信息,不生成最终答案(答案生成由调用方完成)
type GraphIndexer ¶
type GraphIndexer struct {
// contains filtered or unexported fields
}
GraphIndexer 知识图谱索引器 与语义/全文索引器不同,GraphRAG 的索引是构建实体-关系图,查询是图遍历 支持两种查询模式: 1. 独立 GraphRAG 模式(需要 client):Query → LLM提取实体 → 图遍历 2. 混合模式(通过 Chunk IDs):Query → Semantic搜索 → Chunks → 关联 Nodes/Edges
func NewGraphIndexer ¶
func NewGraphIndexer(store core.GraphStore, opts ...any) *GraphIndexer
NewGraphIndexer 创建知识图谱索引器 client 参数可选:
- 提供 client:支持独立 GraphRAG 模式(索引 + 查询都用 LLM)
- 不提供 client:仅支持混合模式(索引时不用 LLM,查询时通过 Chunk IDs)
opts 可选配置,如 WithCache
func (*GraphIndexer) Add ¶
Add 从内容构建知识图谱(实现 core.Indexer 接口) 流程:分块 → LLM实体关系提取 → 图存储 注意:如果没有 client,会跳过实体提取
func (*GraphIndexer) IndexChunk ¶
IndexChunk indexes a pre-generated chunk (implements core.Indexer interface)
func (*GraphIndexer) IndexChunks ¶
IndexChunks indexes multiple pre-generated chunks in batch (implements core.ChunkIndexer interface)
三重优化流水线:
- 大块优先:将 ParentDoc 子块聚合到父块,减少总 chunk 数
- 分级提取:跳过低价值 chunk(纯描述、过短内容),仅对高价值 chunk 调用 LLM
- 并发提取:远程 LLM 全并发;本地 LLM(Ollama 等)串行提取但并发写入图数据库
func (*GraphIndexer) NewQuery ¶
func (g *GraphIndexer) NewQuery(terms string) core.Query
NewQuery 创建图查询(实现 core.Indexer 接口)
func (*GraphIndexer) Remove ¶
func (g *GraphIndexer) Remove(ctx context.Context, chunkID string) error
Remove 移除与指定 chunk 关联的所有实体和关系(实现 core.Indexer 接口)
func (*GraphIndexer) Search ¶
Search 执行图搜索(实现 core.Indexer 接口) 独立 GraphRAG 模式:LLM实体提取 → 图遍历 → 节点/边序列化 → Hit 注意:需要 client,否则返回空结果
func (*GraphIndexer) SearchByChunkIDs ¶
func (g *GraphIndexer) SearchByChunkIDs(ctx context.Context, chunkIDs []string, depth, limit int, edgeTypes ...[]string) ([]core.Hit, error)
SearchByChunkIDs 通过 Chunk IDs 查询关联的图结构 混合模式:由 HybridIndexer 调用,无需 LLM 流程:Chunk IDs → 查询关联 Nodes → 多跳遍历(可选边类型过滤) → 路径评分 → Hit
支持选项:
- depth: 遍历深度(默认 1,即直接邻居)
- limit: 返回结果数量上限
- edgeTypes: 关系类型过滤,仅遍历指定类型的边
func (*GraphIndexer) SearchGlobal ¶
func (g *GraphIndexer) SearchGlobal(ctx context.Context, query string, level int) ([]core.Hit, error)
SearchGlobal 通过社区摘要回答全局性问题 (Global Search) 适用于:"数据集主要讨论了哪些主题?" 这类宏观问题 需要 client 和已构建的社区摘要
type GraphOption ¶
type GraphOption func(*GraphIndexer)
GraphOption GraphIndexer 的可选配置
func WithCache ¶
func WithCache(cache core.CacheStore) GraphOption
WithCache 设置实体提取缓存(依赖注入 core.CacheStore 接口)
type GraphSearchResult ¶
type GraphSearchResult struct {
Query string `json:"query,omitempty"` // 原始查询
Entities []*core.Node `json:"entities,omitempty"` // 匹配的实体节点
Relations []*core.Edge `json:"relations,omitempty"` // 关联的边
ChunkIDs []string `json:"chunk_ids,omitempty"` // 关联的 chunk ID 列表
DocIDs []string `json:"doc_ids,omitempty"` // 关联的文档 ID 列表
}
GraphSearchResult 图搜索结果,用于序列化为 Hit.Content