graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntityPerson     = "person"
	EntityOrg        = "organization"
	EntityStandard   = "standard"
	EntityClause     = "clause"
	EntityConcept    = "concept"
	EntityTerm       = "term"
	EntityRegulation = "regulation"
)

Entity type constants used during extraction and storage.

View Source
const (
	RelReferences  = "references"
	RelDefines     = "defines"
	RelAmends      = "amends"
	RelRequires    = "requires"
	RelContradicts = "contradicts"
	RelSupersedes  = "supersedes"
)

Relation type constants used during extraction and storage.

Variables

This section is empty.

Functions

func DetectCommunities

func DetectCommunities(ctx context.Context, s *store.Store) ([]store.Community, error)

DetectCommunities runs community detection on the entity graph. Level-0 communities are connected components. Components larger than minComponentSplit are further split using greedy modularity optimisation and stored as level-1 communities.

func SummarizeCommunities

func SummarizeCommunities(ctx context.Context, s *store.Store, chat llm.Provider, communities []store.Community) error

SummarizeCommunities uses the LLM to generate a natural-language summary for each community based on its member entities. Summaries are generated concurrently (up to 8 at a time) and individual failures are logged but do not abort the entire operation.

Types

type Builder

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

Builder constructs the knowledge graph from document chunks.

func NewBuilder

func NewBuilder(s *store.Store, chat, embed llm.Provider, concurrency int) *Builder

NewBuilder creates a new graph builder.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, docID int64, chunks []store.Chunk, chunkIDs []int64) error

Build extracts entities and relationships from chunks and stores them. chunks and chunkIDs correspond by index.

type ExtractedEntity

type ExtractedEntity struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Description string `json:"description"`
	NameEN      string `json:"name_en"`
}

ExtractedEntity is what the LLM returns from entity extraction.

type ExtractedRelationship

type ExtractedRelationship struct {
	Source       string  `json:"source"`
	Target       string  `json:"target"`
	RelationType string  `json:"relation_type"`
	Description  string  `json:"description"`
	Weight       float64 `json:"weight"`
}

ExtractedRelationship is what the LLM returns from relationship extraction.

type ExtractionResult

type ExtractionResult struct {
	Entities      []ExtractedEntity       `json:"entities"`
	Relationships []ExtractedRelationship `json:"relationships"`
}

ExtractionResult holds the LLM's structured output for a chunk.

type TraversalResult

type TraversalResult struct {
	EntityIDs []int64
	ChunkIDs  []int64
}

TraversalResult contains entities and chunks found via graph traversal.

func Traverse

func Traverse(ctx context.Context, s *store.Store, queryEntities []string, maxDepth int) (*TraversalResult, error)

Traverse finds entities matching query terms and follows relationships to discover related chunks. Uses BFS with configurable depth.

queryEntities are entity names (case-insensitive lookup). The traversal walks outgoing and incoming relationships up to maxDepth hops, collecting all entity IDs and their associated chunk IDs.

Jump to

Keyboard shortcuts

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