graph

package
v2.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchEdgeOperation

type BatchEdgeOperation struct {
	Edges []*GraphEdge
}

BatchEdgeOperation represents a batch operation for edges

type BatchGraphOperation

type BatchGraphOperation struct {
	NodeUpserts []*GraphNode
	NodeDeletes []string
	EdgeUpserts []*GraphEdge
	EdgeDeletes []string
}

BatchGraphOperation allows multiple graph operations in a single transaction

type BatchNodeOperation

type BatchNodeOperation struct {
	Nodes []*GraphNode
}

BatchNodeOperation represents a batch operation for nodes

type BatchResult

type BatchResult struct {
	SuccessCount int
	FailedCount  int
	Errors       []error
}

BatchResult contains the results of a batch operation

type Community

type Community struct {
	ID    int      `json:"id"`
	Nodes []string `json:"nodes"`
	Score float64  `json:"score"` // Modularity score
}

Community represents a detected community of nodes

type EdgePrediction

type EdgePrediction struct {
	FromNodeID string  `json:"from_node_id"`
	ToNodeID   string  `json:"to_node_id"`
	Score      float64 `json:"score"`
	Method     string  `json:"method"`
}

EdgePrediction represents a predicted edge with confidence score

type ExportFormat

type ExportFormat string

ExportFormat represents supported export formats

const (
	FormatGraphML ExportFormat = "graphml"
	FormatGEXF    ExportFormat = "gexf"
	FormatJSON    ExportFormat = "json"
)

func DetectFormat

func DetectFormat(reader io.Reader) (ExportFormat, error)

DetectFormat attempts to detect the format of the input

type GEXFAttValue

type GEXFAttValue struct {
	For   string `xml:"for,attr"`
	Value string `xml:"value,attr"`
}

GEXFAttValue represents a GEXF attribute value

type GEXFAttr

type GEXFAttr struct {
	ID    string `xml:"id,attr"`
	Title string `xml:"title,attr"`
	Type  string `xml:"type,attr"`
}

GEXFAttr represents a GEXF attribute

type GEXFAttrs

type GEXFAttrs struct {
	Class string     `xml:"class,attr"`
	Attrs []GEXFAttr `xml:"attribute"`
}

GEXFAttrs represents GEXF attributes

type GEXFDocument

type GEXFDocument struct {
	XMLName xml.Name  `xml:"gexf"`
	XMLNS   string    `xml:"xmlns,attr"`
	Version string    `xml:"version,attr"`
	Meta    GEXFMeta  `xml:"meta"`
	Graph   GEXFGraph `xml:"graph"`
}

GEXFDocument represents a GEXF document

type GEXFEdge

type GEXFEdge struct {
	ID     string  `xml:"id,attr"`
	Source string  `xml:"source,attr"`
	Target string  `xml:"target,attr"`
	Weight float64 `xml:"weight,attr,omitempty"`
	Type   string  `xml:"type,attr,omitempty"`
}

GEXFEdge represents a GEXF edge

type GEXFEdges

type GEXFEdges struct {
	Edges []GEXFEdge `xml:"edge"`
}

GEXFEdges represents GEXF edges container

type GEXFGraph

type GEXFGraph struct {
	Mode            string    `xml:"mode,attr"`
	DefaultEdgeType string    `xml:"defaultedgetype,attr"`
	Attributes      GEXFAttrs `xml:"attributes"`
	Nodes           GEXFNodes `xml:"nodes"`
	Edges           GEXFEdges `xml:"edges"`
}

GEXFGraph represents a GEXF graph

type GEXFMeta

type GEXFMeta struct {
	Creator     string `xml:"creator"`
	Description string `xml:"description"`
}

GEXFMeta represents GEXF metadata

type GEXFNode

type GEXFNode struct {
	ID        string         `xml:"id,attr"`
	Label     string         `xml:"label,attr"`
	AttValues []GEXFAttValue `xml:"attvalues>attvalue"`
}

GEXFNode represents a GEXF node

type GEXFNodes

type GEXFNodes struct {
	Nodes []GEXFNode `xml:"node"`
}

GEXFNodes represents GEXF nodes container

type GraphEdge

type GraphEdge struct {
	ID         string                 `json:"id"`
	FromNodeID string                 `json:"from_node_id"`
	ToNodeID   string                 `json:"to_node_id"`
	EdgeType   string                 `json:"edge_type,omitempty"`
	Weight     float64                `json:"weight"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Vector     []float32              `json:"vector,omitempty"` // Optional edge embedding
	CreatedAt  time.Time              `json:"created_at"`
}

GraphEdge represents a directed edge between two nodes

type GraphFilter

type GraphFilter struct {
	NodeTypes []string `json:"node_types,omitempty"`
	EdgeTypes []string `json:"edge_types,omitempty"`
	MaxDepth  int      `json:"max_depth,omitempty"`
}

GraphFilter defines filtering options for graph queries

type GraphMLData

type GraphMLData struct {
	Key   string `xml:"key,attr"`
	Value string `xml:",chardata"`
}

GraphMLData represents GraphML data

type GraphMLDocument

type GraphMLDocument struct {
	XMLName xml.Name     `xml:"graphml"`
	XMLNS   string       `xml:"xmlns,attr"`
	Keys    []GraphMLKey `xml:"key"`
	Graph   GraphMLGraph `xml:"graph"`
}

GraphMLDocument represents a GraphML document

type GraphMLEdge

type GraphMLEdge struct {
	ID     string        `xml:"id,attr"`
	Source string        `xml:"source,attr"`
	Target string        `xml:"target,attr"`
	Data   []GraphMLData `xml:"data"`
}

GraphMLEdge represents a GraphML edge

type GraphMLGraph

type GraphMLGraph struct {
	ID          string        `xml:"id,attr"`
	EdgeDefault string        `xml:"edgedefault,attr"`
	Nodes       []GraphMLNode `xml:"node"`
	Edges       []GraphMLEdge `xml:"edge"`
}

GraphMLGraph represents a GraphML graph

type GraphMLKey

type GraphMLKey struct {
	ID       string `xml:"id,attr"`
	For      string `xml:"for,attr"`
	AttrName string `xml:"attr.name,attr"`
	AttrType string `xml:"attr.type,attr"`
}

GraphMLKey represents a GraphML key definition

type GraphMLNode

type GraphMLNode struct {
	ID   string        `xml:"id,attr"`
	Data []GraphMLData `xml:"data"`
}

GraphMLNode represents a GraphML node

type GraphNode

type GraphNode struct {
	ID         string                 `json:"id"`
	Vector     []float32              `json:"vector"`
	Content    string                 `json:"content,omitempty"`
	NodeType   string                 `json:"node_type,omitempty"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	CreatedAt  time.Time              `json:"created_at"`
	UpdatedAt  time.Time              `json:"updated_at"`
}

GraphNode represents a node in the graph with vector embedding

type GraphResult

type GraphResult struct {
	Nodes []*GraphNode `json:"nodes"`
	Edges []*GraphEdge `json:"edges"`
}

GraphResult represents a subgraph or query result

type GraphStatistics

type GraphStatistics struct {
	NodeCount           int     `json:"node_count"`
	EdgeCount           int     `json:"edge_count"`
	AverageDegree       float64 `json:"average_degree"`
	Density             float64 `json:"density"`
	ConnectedComponents int     `json:"connected_components"`
}

GraphStatistics represents overall graph statistics

type GraphStore

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

GraphStore provides graph operations on top of the vector store

func NewGraphStore

func NewGraphStore(s *core.SQLiteStore) *GraphStore

NewGraphStore creates a new graph store from a SQLite store

func (*GraphStore) CommunityDetection

func (g *GraphStore) CommunityDetection(ctx context.Context) ([]Community, error)

CommunityDetection performs community detection using the Louvain method Optimized to reduce DB queries.

func (*GraphStore) Connected

func (g *GraphStore) Connected(ctx context.Context, nodeID1, nodeID2 string, maxDepth int) (bool, error)

Connected checks if two nodes are connected within a given depth

func (*GraphStore) DeleteEdge

func (g *GraphStore) DeleteEdge(ctx context.Context, edgeID string) error

DeleteEdge removes an edge from the graph

func (*GraphStore) DeleteEdgesBatch

func (g *GraphStore) DeleteEdgesBatch(ctx context.Context, edgeIDs []string) (*BatchResult, error)

DeleteEdgesBatch deletes multiple edges in a single transaction

func (*GraphStore) DeleteNode

func (g *GraphStore) DeleteNode(ctx context.Context, nodeID string) error

DeleteNode removes a node and all its edges

func (*GraphStore) DeleteNodesBatch

func (g *GraphStore) DeleteNodesBatch(ctx context.Context, nodeIDs []string) (*BatchResult, error)

DeleteNodesBatch deletes multiple nodes in a single transaction

func (*GraphStore) EnableHNSWIndex

func (g *GraphStore) EnableHNSWIndex(dimensions int) error

EnableHNSWIndex enables HNSW indexing for the graph store

func (*GraphStore) ExecuteBatch

func (g *GraphStore) ExecuteBatch(ctx context.Context, ops *BatchGraphOperation) (*BatchResult, error)

ExecuteBatch executes multiple graph operations in a single transaction

func (*GraphStore) Export

func (g *GraphStore) Export(ctx context.Context, writer io.Writer, format ExportFormat) error

Export exports the graph in the specified format

func (*GraphStore) ExportGEXF

func (g *GraphStore) ExportGEXF(ctx context.Context, writer io.Writer) error

ExportGEXF exports the graph to GEXF format

func (*GraphStore) ExportGraphML

func (g *GraphStore) ExportGraphML(ctx context.Context, writer io.Writer) error

ExportGraphML exports the graph to GraphML format

func (*GraphStore) ExportJSON

func (g *GraphStore) ExportJSON(ctx context.Context, writer io.Writer) error

ExportJSON exports the graph to JSON format

func (*GraphStore) GetAllNodes

func (g *GraphStore) GetAllNodes(ctx context.Context, filter *GraphFilter) ([]*GraphNode, error)

GetAllNodes retrieves all nodes with optional filtering

func (*GraphStore) GetEdges

func (g *GraphStore) GetEdges(ctx context.Context, nodeID string, direction string) ([]*GraphEdge, error)

GetEdges retrieves edges for a node

func (*GraphStore) GetEdgesBatch

func (g *GraphStore) GetEdgesBatch(ctx context.Context, edgeIDs []string) ([]*GraphEdge, error)

GetEdgesBatch retrieves multiple edges by their IDs

func (*GraphStore) GetGraphStatistics

func (g *GraphStore) GetGraphStatistics(ctx context.Context) (*GraphStatistics, error)

GetGraphStatistics computes statistics about the graph

func (*GraphStore) GetNode

func (g *GraphStore) GetNode(ctx context.Context, nodeID string) (*GraphNode, error)

GetNode retrieves a node by ID

func (*GraphStore) GetNodesBatch

func (g *GraphStore) GetNodesBatch(ctx context.Context, nodeIDs []string) ([]*GraphNode, error)

GetNodesBatch retrieves multiple nodes by their IDs

func (*GraphStore) GraphVectorSearch

func (g *GraphStore) GraphVectorSearch(ctx context.Context, startNodeID string, vector []float32, opts TraversalOptions) ([]*HybridResult, error)

GraphVectorSearch performs vector search within a graph neighborhood

func (*GraphStore) HNSWHybridSearch

func (g *GraphStore) HNSWHybridSearch(ctx context.Context, query *HybridQuery) ([]*HybridResult, error)

HNSWHybridSearch combines HNSW search with graph proximity

func (*GraphStore) HNSWSearch

func (g *GraphStore) HNSWSearch(ctx context.Context, query []float32, k int, threshold float64) ([]*HybridResult, error)

HNSWSearch performs HNSW-accelerated vector search

func (*GraphStore) HybridSearch

func (g *GraphStore) HybridSearch(ctx context.Context, query *HybridQuery) ([]*HybridResult, error)

HybridSearch performs a combined vector and graph search

func (*GraphStore) Import

func (g *GraphStore) Import(ctx context.Context, reader io.Reader, format ExportFormat) error

Import imports a graph in the specified format

func (*GraphStore) ImportGEXF

func (g *GraphStore) ImportGEXF(ctx context.Context, reader io.Reader) error

ImportGEXF imports a graph from GEXF format

func (*GraphStore) ImportGraphML

func (g *GraphStore) ImportGraphML(ctx context.Context, reader io.Reader) error

ImportGraphML imports a graph from GraphML format

func (*GraphStore) ImportJSON

func (g *GraphStore) ImportJSON(ctx context.Context, reader io.Reader) error

ImportJSON imports a graph from JSON format

func (*GraphStore) InitGraphSchema

func (g *GraphStore) InitGraphSchema(ctx context.Context) error

InitGraphSchema creates the graph tables if they don't exist

func (*GraphStore) Neighbors

func (g *GraphStore) Neighbors(ctx context.Context, nodeID string, opts TraversalOptions) ([]*GraphNode, error)

Neighbors performs a breadth-first search to find neighboring nodes

func (*GraphStore) PageRank

func (g *GraphStore) PageRank(ctx context.Context, iterations int, dampingFactor float64) ([]PageRankResult, error)

PageRank calculates PageRank scores for all nodes in the graph Optimized to load only topology (IDs and Edges) instead of full node objects.

func (*GraphStore) PredictEdges

func (g *GraphStore) PredictEdges(ctx context.Context, nodeID string, topK int) ([]EdgePrediction, error)

PredictEdges predicts potential edges using various methods

func (*GraphStore) ShortestPath

func (g *GraphStore) ShortestPath(ctx context.Context, fromID, toID string) (*PathResult, error)

ShortestPath finds the shortest path between two nodes using BFS

func (*GraphStore) SimilarityInGraph

func (g *GraphStore) SimilarityInGraph(ctx context.Context, nodeID string, opts core.SearchOptions) ([]*HybridResult, error)

SimilarityInGraph finds nodes similar to a given node within the graph

func (*GraphStore) Subgraph

func (g *GraphStore) Subgraph(ctx context.Context, nodeIDs []string) (*GraphResult, error)

Subgraph extracts a subgraph containing specified nodes and their connections

func (*GraphStore) UpsertEdge

func (g *GraphStore) UpsertEdge(ctx context.Context, edge *GraphEdge) error

UpsertEdge inserts or updates an edge in the graph

func (*GraphStore) UpsertEdgesBatch

func (g *GraphStore) UpsertEdgesBatch(ctx context.Context, edges []*GraphEdge) (*BatchResult, error)

UpsertEdgesBatch inserts or updates multiple edges in a single transaction

func (*GraphStore) UpsertNode

func (g *GraphStore) UpsertNode(ctx context.Context, node *GraphNode) error

UpsertNode inserts or updates a node in the graph

func (*GraphStore) UpsertNodesBatch

func (g *GraphStore) UpsertNodesBatch(ctx context.Context, nodes []*GraphNode) (*BatchResult, error)

UpsertNodesBatch inserts or updates multiple nodes in a single transaction

type HNSWGraphIndex

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

HNSWGraphIndex provides HNSW-accelerated graph searches

type HybridQuery

type HybridQuery struct {
	Vector          []float32     `json:"vector,omitempty"`
	StartNodeID     string        `json:"start_node_id,omitempty"`
	CenterNodes     []string      `json:"center_nodes,omitempty"`
	GraphFilter     *GraphFilter  `json:"graph_filter,omitempty"`
	TopK            int           `json:"top_k"`
	Threshold       float64       `json:"threshold,omitempty"`
	VectorThreshold float64       `json:"vector_threshold,omitempty"`
	TotalThreshold  float64       `json:"total_threshold,omitempty"`
	VectorWeight    float64       `json:"vector_weight"`
	GraphWeight     float64       `json:"graph_weight"`
	Weights         HybridWeights `json:"weights"`
}

HybridQuery represents a combined vector and graph query

type HybridResult

type HybridResult struct {
	Node          *GraphNode `json:"node"`
	VectorScore   float64    `json:"vector_score"`
	GraphScore    float64    `json:"graph_score"`
	CombinedScore float64    `json:"combined_score"`
	TotalScore    float64    `json:"total_score"`
	Path          []string   `json:"path,omitempty"` // Path from start node
	Distance      int        `json:"distance"`       // Graph distance from start
}

HybridResult represents a result from hybrid search

type HybridWeights

type HybridWeights struct {
	VectorWeight float64 `json:"vector_weight"` // Weight for vector similarity
	GraphWeight  float64 `json:"graph_weight"`  // Weight for graph proximity
	EdgeWeight   float64 `json:"edge_weight"`   // Weight for edge strength
}

HybridWeights defines the weights for hybrid scoring

type PageRankResult

type PageRankResult struct {
	NodeID string  `json:"node_id"`
	Score  float64 `json:"score"`
}

PageRankResult represents the PageRank score for a node

type PathResult

type PathResult struct {
	Nodes    []*GraphNode `json:"nodes"`
	Edges    []*GraphEdge `json:"edges"`
	Distance int          `json:"distance"`
	Weight   float64      `json:"weight"`
}

PathResult represents a path in the graph

type SimpleHNSW

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

SimpleHNSW implements a simplified HNSW-like index for vector search

func NewSimpleHNSW

func NewSimpleHNSW(dimensions int, maxConns int) *SimpleHNSW

NewSimpleHNSW creates a new simplified HNSW index

func (*SimpleHNSW) Add

func (h *SimpleHNSW) Add(id string, vector []float32) error

Add inserts a vector into the HNSW index

func (*SimpleHNSW) Remove

func (h *SimpleHNSW) Remove(nodeID string)

Remove removes a node from the index

func (*SimpleHNSW) Search

func (h *SimpleHNSW) Search(query []float32, k int) []searchCandidate

Search performs HNSW search

type TraversalOptions

type TraversalOptions struct {
	MaxDepth  int      `json:"max_depth"`
	EdgeTypes []string `json:"edge_types,omitempty"`
	NodeTypes []string `json:"node_types,omitempty"`
	Direction string   `json:"direction"` // "out", "in", "both"
	Limit     int      `json:"limit"`
}

TraversalOptions defines options for graph traversal

Jump to

Keyboard shortcuts

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