graph

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package graph provides graph-related utilities for RAG systems. It includes components for extracting entities and relationships from text, as well as searching knowledge graphs for relevant information.

Package graph provides graph-related utilities for RAG systems. It includes components for extracting entities and relationships from text, as well as searching knowledge graphs for relevant information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GlobalSearcher

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

GlobalSearcher performs Map-Reduce over Community Summaries for macro-level questions. It helps answer broad questions by synthesizing information from multiple communities in the knowledge graph.

func NewGlobalSearcher

func NewGlobalSearcher(store abstraction.GraphStore, llm core.Client) *GlobalSearcher

NewGlobalSearcher creates a new global searcher.

Parameters: - store: The graph store to use for searching - llm: The LLM client to use for synthesizing results

Returns: - A new GlobalSearcher instance

func (*GlobalSearcher) Search

func (s *GlobalSearcher) Search(ctx context.Context, query string, communityLevel int) (string, error)

Search performs Map-Reduce over Community Summaries for macro-level questions.

Parameters: - ctx: The context for the operation - query: The query to answer - communityLevel: The level of community summaries to use

Returns: - A synthesized answer based on community summaries - An error if searching fails

type GraphExtractor

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

GraphExtractor uses an LLM to extract Entities (Nodes) and Relationships (Edges) from text chunks. It helps build knowledge graphs from unstructured text for better retrieval and reasoning.

func DefaultGraphExtractor

func DefaultGraphExtractor(llm core.Client) *GraphExtractor

DefaultGraphExtractor 创建默认的图提取器 使用 gochat 的标准 LLM 客户端进行实体和关系提取

func NewGraphExtractor

func NewGraphExtractor(llm core.Client) *GraphExtractor

NewGraphExtractor creates a new graph extractor.

Parameters: - llm: The LLM client to use for extraction

Returns: - A new GraphExtractor instance

func (*GraphExtractor) Extract

func (e *GraphExtractor) Extract(ctx context.Context, chunk *entity.Chunk) ([]abstraction.Node, []abstraction.Edge, error)

Extract extracts entities and relationships from a text chunk.

Parameters: - ctx: The context for the operation - chunk: The text chunk to extract from

Returns: - A slice of nodes (entities) - A slice of edges (relationships) - An error if extraction fails

type LocalSearcher

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

LocalSearcher performs N-Hop traversal from specific entities to gather relational context. It helps retrieve relevant information by traversing the knowledge graph from given entities.

func NewLocalSearcher

func NewLocalSearcher(store abstraction.GraphStore) *LocalSearcher

NewLocalSearcher creates a new local searcher.

Parameters: - store: The graph store to use for searching

Returns: - A new LocalSearcher instance

func (*LocalSearcher) Search

func (s *LocalSearcher) Search(ctx context.Context, entities []string, maxHops int, topK int) (string, error)

Search performs N-Hop traversal from specific entities to gather relational context.

Parameters: - ctx: The context for the operation - entities: The entities to start the search from - maxHops: The maximum number of hops to traverse - topK: The maximum number of results to return

Returns: - A string representation of the search results - An error if searching fails

Jump to

Keyboard shortcuts

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