Documentation
¶
Overview ¶
Package graphrag provides graph-based retrieval-augmented generation capabilities.
GraphRAG extends traditional RAG by leveraging knowledge graphs for enhanced context retrieval. Unlike pure vector search, GraphRAG maintains explicit relationships between entities, enabling:
- Relationship-aware retrieval
- Multi-hop graph traversal
- Community-based global search
- Entity extraction and knowledge building
Index ¶
- Constants
- Variables
- func IsNotFoundError(err error) bool
- func IsValidationError(err error) bool
- type Config
- type Entity
- type EntityTypeSchema
- type ExtractionOption
- func WithDedupThreshold(threshold float32) ExtractionOption
- func WithExtractionEntityTypes(types ...string) ExtractionOption
- func WithExtractionRelationshipTypes(types ...string) ExtractionOption
- func WithMaxEntities(max int) ExtractionOption
- func WithMinConfidence(confidence float32) ExtractionOption
- func WithSchemaGuided(guided bool) ExtractionOption
- type ExtractionOptions
- type ExtractionResult
- type GraphContext
- type GraphPath
- type GraphSchema
- type GraphSearchMode
- type GraphSearchOption
- func WithEntityTypes(types ...string) GraphSearchOption
- func WithIncludeRelationships(include bool) GraphSearchOption
- func WithMaxDepth(depth int) GraphSearchOption
- func WithMinScore(score float32) GraphSearchOption
- func WithMode(mode GraphSearchMode) GraphSearchOption
- func WithRelationshipTypes(types ...string) GraphSearchOption
- func WithSearchTenant(tenant string) GraphSearchOption
- type GraphSearchOptions
- type GraphSearchResult
- type GraphStoreOption
- type GraphStoreOptions
- type PropertySchema
- type Relationship
- type RelationshipDirection
- type RelationshipTypeSchema
Constants ¶
const ( DirectionOutgoing = interfaces.DirectionOutgoing DirectionIncoming = interfaces.DirectionIncoming DirectionBoth = interfaces.DirectionBoth )
Direction constants
const ( SearchModeVector = interfaces.SearchModeVector SearchModeKeyword = interfaces.SearchModeKeyword SearchModeHybrid = interfaces.SearchModeHybrid )
Search mode constants
Variables ¶
var ( // ErrEntityNotFound is returned when an entity cannot be found ErrEntityNotFound = errors.New("entity not found") // ErrRelationshipNotFound is returned when a relationship cannot be found ErrRelationshipNotFound = errors.New("relationship not found") // ErrInvalidEntityID is returned when an entity ID is invalid or empty ErrInvalidEntityID = errors.New("invalid entity ID") // ErrInvalidRelationshipID is returned when a relationship ID is invalid or empty ErrInvalidRelationshipID = errors.New("invalid relationship ID") // ErrMissingEntityName is returned when an entity name is missing ErrMissingEntityName = errors.New("entity name is required") // ErrMissingEntityType is returned when an entity type is missing ErrMissingEntityType = errors.New("entity type is required") // ErrMissingSourceID is returned when a relationship source ID is missing ErrMissingSourceID = errors.New("relationship source ID is required") // ErrMissingTargetID is returned when a relationship target ID is missing ErrMissingTargetID = errors.New("relationship target ID is required") // ErrMissingRelationshipType is returned when a relationship type is missing ErrMissingRelationshipType = errors.New("relationship type is required") // ErrNoEmbedder is returned when an embedder is required but not configured ErrNoEmbedder = errors.New("embedder not configured") // ErrNoLLM is returned when an LLM is required but not provided ErrNoLLM = errors.New("LLM is required for extraction") // ErrConnectionFailed is returned when connection to the backend fails ErrConnectionFailed = errors.New("failed to connect to GraphRAG backend") // ErrSchemaValidation is returned when schema validation fails ErrSchemaValidation = errors.New("schema validation failed") // ErrPathNotFound is returned when no path exists between entities ErrPathNotFound = errors.New("no path found between entities") // ErrMaxDepthExceeded is returned when traversal depth limit is exceeded ErrMaxDepthExceeded = errors.New("maximum traversal depth exceeded") // ErrExtractionFailed is returned when entity extraction fails ErrExtractionFailed = errors.New("entity extraction failed") // ErrDuplicateEntity is returned when trying to create an entity with an existing ID ErrDuplicateEntity = errors.New("entity with this ID already exists") // ErrDuplicateRelationship is returned when trying to create a relationship with an existing ID ErrDuplicateRelationship = errors.New("relationship with this ID already exists") // ErrSourceEntityNotFound is returned when the source entity of a relationship doesn't exist ErrSourceEntityNotFound = errors.New("source entity not found") // ErrTargetEntityNotFound is returned when the target entity of a relationship doesn't exist ErrTargetEntityNotFound = errors.New("target entity not found") // ErrInvalidStrength is returned when relationship strength is outside 0-1 range ErrInvalidStrength = errors.New("relationship strength must be between 0.0 and 1.0") // ErrEmptyQuery is returned when a search query is empty ErrEmptyQuery = errors.New("search query cannot be empty") // ErrInvalidDepth is returned when traversal depth is invalid (negative or too large) ErrInvalidDepth = errors.New("invalid traversal depth") )
Common errors for GraphRAG operations
Functions ¶
func IsNotFoundError ¶
IsNotFoundError returns true if the error is a not-found error
func IsValidationError ¶
IsValidationError returns true if the error is a validation error
Types ¶
type Config ¶
type Config struct {
// Provider is the backend provider ("weaviate", "neo4j")
Provider string `json:"provider" yaml:"provider"`
// Host is the hostname of the backend server
Host string `json:"host" yaml:"host"`
// Scheme is the URL scheme (http or https)
Scheme string `json:"scheme" yaml:"scheme"`
// APIKey is the authentication key
APIKey string `json:"api_key" yaml:"api_key"`
// ClassPrefix is the prefix for collection/class names
ClassPrefix string `json:"class_prefix" yaml:"class_prefix"`
// Schema is the optional schema definition
Schema *GraphSchema `json:"schema,omitempty" yaml:"schema,omitempty"`
}
Config holds configuration for GraphRAG providers
type EntityTypeSchema ¶
type EntityTypeSchema = interfaces.EntityTypeSchema
EntityTypeSchema defines an entity type in the schema
type ExtractionOption ¶
type ExtractionOption = interfaces.ExtractionOption
ExtractionOption represents an option for extraction operations
func WithDedupThreshold ¶
func WithDedupThreshold(threshold float32) ExtractionOption
WithDedupThreshold sets the embedding similarity threshold for deduplication
func WithExtractionEntityTypes ¶
func WithExtractionEntityTypes(types ...string) ExtractionOption
WithExtractionEntityTypes limits extraction to specific entity types
func WithExtractionRelationshipTypes ¶
func WithExtractionRelationshipTypes(types ...string) ExtractionOption
WithExtractionRelationshipTypes limits extraction to specific relationship types
func WithMaxEntities ¶
func WithMaxEntities(max int) ExtractionOption
WithMaxEntities limits the number of extracted entities
func WithMinConfidence ¶
func WithMinConfidence(confidence float32) ExtractionOption
WithMinConfidence sets the minimum extraction confidence
func WithSchemaGuided ¶
func WithSchemaGuided(guided bool) ExtractionOption
WithSchemaGuided enables schema-guided extraction
type ExtractionOptions ¶
type ExtractionOptions = interfaces.ExtractionOptions
ExtractionOptions contains options for extraction operations
type ExtractionResult ¶
type ExtractionResult = interfaces.ExtractionResult
ExtractionResult contains extracted entities and relationships from text
type GraphContext ¶
type GraphContext = interfaces.GraphContext
GraphContext represents context around a central entity from graph traversal
type GraphPath ¶
type GraphPath = interfaces.GraphPath
GraphPath represents a path between two entities
type GraphSchema ¶
type GraphSchema = interfaces.GraphSchema
GraphSchema defines the structure of the knowledge graph
type GraphSearchMode ¶
type GraphSearchMode = interfaces.GraphSearchMode
GraphSearchMode specifies the type of search to perform
type GraphSearchOption ¶
type GraphSearchOption = interfaces.GraphSearchOption
GraphSearchOption represents an option for graph search operations
func WithEntityTypes ¶
func WithEntityTypes(types ...string) GraphSearchOption
WithEntityTypes filters search by entity types
func WithIncludeRelationships ¶
func WithIncludeRelationships(include bool) GraphSearchOption
WithIncludeRelationships includes relationships in results
func WithMaxDepth ¶
func WithMaxDepth(depth int) GraphSearchOption
WithMaxDepth sets maximum traversal depth
func WithMinScore ¶
func WithMinScore(score float32) GraphSearchOption
WithMinScore sets the minimum similarity score
func WithMode ¶
func WithMode(mode GraphSearchMode) GraphSearchOption
WithMode sets the search mode (vector, keyword, hybrid)
func WithRelationshipTypes ¶
func WithRelationshipTypes(types ...string) GraphSearchOption
WithRelationshipTypes filters search by relationship types
func WithSearchTenant ¶
func WithSearchTenant(tenant string) GraphSearchOption
WithSearchTenant sets the tenant for search operations
type GraphSearchOptions ¶
type GraphSearchOptions = interfaces.GraphSearchOptions
GraphSearchOptions contains options for searching graph data
type GraphSearchResult ¶
type GraphSearchResult = interfaces.GraphSearchResult
GraphSearchResult represents a search result from the knowledge graph
type GraphStoreOption ¶
type GraphStoreOption = interfaces.GraphStoreOption
GraphStoreOption represents an option for graph store operations
func WithBatchSize ¶
func WithBatchSize(size int) GraphStoreOption
WithBatchSize sets the batch size for store operations
func WithGenerateEmbeddings ¶
func WithGenerateEmbeddings(generate bool) GraphStoreOption
WithGenerateEmbeddings sets whether to generate embeddings
func WithTenant ¶
func WithTenant(tenant string) GraphStoreOption
WithTenant sets the tenant for graph operations
type GraphStoreOptions ¶
type GraphStoreOptions = interfaces.GraphStoreOptions
GraphStoreOptions contains options for storing graph data
type PropertySchema ¶
type PropertySchema = interfaces.PropertySchema
PropertySchema defines a property in the schema
type Relationship ¶
type Relationship = interfaces.Relationship
Relationship represents an edge connecting two entities
type RelationshipDirection ¶
type RelationshipDirection = interfaces.RelationshipDirection
RelationshipDirection specifies the direction for relationship queries
type RelationshipTypeSchema ¶
type RelationshipTypeSchema = interfaces.RelationshipTypeSchema
RelationshipTypeSchema defines a relationship type in the schema