model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	ID          uuid.UUID `json:"id"`
	DocumentID  int64     `json:"document_id"`
	DocumentRID uuid.UUID `json:"document_rid"`
	Content     string    `json:"content"`
	Path        string    `json:"path"` // ltree path
	Embedding   []float32 `json:"embedding,omitempty"`
	StartPos    *int      `json:"start_pos,omitempty"`
	EndPos      *int      `json:"end_pos,omitempty"`
	ChunkIndex  *int      `json:"chunk_index,omitempty"`
	Metadata    Metadata  `json:"metadata,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	// Results
	Similarity *float64 `json:"similarity,omitempty"`
	IsMatch    *bool    `json:"is_match,omitempty"`
}

Chunk represents a document chunk (node in the graph)

type ChunkMention

type ChunkMention struct {
	ChunkID      uuid.UUID `json:"chunk_id"`
	EdgeID       uuid.UUID `json:"edge_id"`
	EdgeMetadata Metadata  `json:"edge_metadata,omitempty"`
}

ChunkMention represents a chunk that mentions an entity

type Document

type Document struct {
	ID        int64     `json:"id"`
	RID       uuid.UUID `json:"rid"`
	Title     string    `json:"title"`
	Source    string    `json:"source,omitempty"`
	Content   string    `json:"content,omitempty" db:"-"` // Temporary field for processing, not stored in DB
	Metadata  Metadata  `json:"metadata,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Document represents a source document

func NewDocumentFromFile

func NewDocumentFromFile(filePath string, metadata Metadata) (*Document, error)

NewDocumentFromFile reads a file and creates a Document with the file content The title defaults to the filename, and source to the file path

type Edge

type Edge struct {
	ID             uuid.UUID  `json:"id"`
	SourceChunkID  *uuid.UUID `json:"source_chunk_id,omitempty"`
	TargetChunkID  *uuid.UUID `json:"target_chunk_id,omitempty"`
	SourceEntityID *uuid.UUID `json:"source_entity_id,omitempty"`
	TargetEntityID *uuid.UUID `json:"target_entity_id,omitempty"`
	EdgeType       EdgeType   `json:"edge_type"`
	Weight         float64    `json:"weight"`
	Bidirectional  bool       `json:"bidirectional"`
	Metadata       Metadata   `json:"metadata,omitempty"`
	CreatedAt      time.Time  `json:"created_at"`
}

Edge represents a relationship between chunks and/or entities

type EdgeConnection

type EdgeConnection struct {
	Edge       *Edge `json:"edge"`
	IsOutgoing bool  `json:"is_outgoing"`
}

EdgeConnection represents an edge with directional information

type EdgeType

type EdgeType string

EdgeType represents the type of relationship between nodes

const (
	EdgeTypeSemantic      EdgeType = "semantic"
	EdgeTypeHierarchical  EdgeType = "hierarchical"
	EdgeTypeReference     EdgeType = "reference"
	EdgeTypeEntityMention EdgeType = "entity_mention"
	EdgeTypeTemporal      EdgeType = "temporal"
	EdgeTypeCausal        EdgeType = "causal"
	EdgeTypeCustom        EdgeType = "custom"
)

type Entity

type Entity struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Type      string    `json:"entity_type"`
	Metadata  Metadata  `json:"metadata,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

Entity represents a named entity (person, place, concept, etc.)

type Metadata

type Metadata map[string]interface{}

Metadata represents JSONB metadata stored in PostgreSQL

func (Metadata) Marshal

func (m Metadata) Marshal() ([]byte, error)

Marshal converts Metadata to JSON bytes

func (*Metadata) Scan

func (m *Metadata) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database retrieval

func (*Metadata) Unmarshal

func (m *Metadata) Unmarshal(value interface{}) error

Unmarshal converts JSON bytes or Metadata to Metadata

func (Metadata) Value

func (m Metadata) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database storage

type QueryConfig

type QueryConfig struct {
	// Vector search parameters
	TopK                int     `json:"top_k"`
	SimilarityThreshold float64 `json:"similarity_threshold,omitempty"`

	// Document filtering
	DocumentRIDs []uuid.UUID `json:"document_rids,omitempty"` // Filter by specific documents

	// Graph traversal parameters
	MaxHops             int        `json:"max_hops,omitempty"`
	EdgeTypes           []EdgeType `json:"edge_types,omitempty"` // Filter by edge types
	FollowBidirectional bool       `json:"follow_bidirectional"`

	// Ltree parameters
	IncludeAncestors   bool `json:"include_ancestors"`
	IncludeDescendants bool `json:"include_descendants"`
	IncludeSiblings    bool `json:"include_siblings"`

	// Ranking parameters
	VectorWeight    float64 `json:"vector_weight"`    // Weight for similarity score
	GraphWeight     float64 `json:"graph_weight"`     // Weight for graph distance
	HierarchyWeight float64 `json:"hierarchy_weight"` // Weight for hierarchy distance
}

QueryConfig represents configuration for a retrieval query

func DefaultQueryConfig

func DefaultQueryConfig() QueryConfig

DefaultQueryConfig returns a sensible default configuration

type RetrievalResult

type RetrievalResult struct {
	Chunk             *Chunk   `json:"chunk"`
	Score             float64  `json:"score"`            // Combined score from ranking
	SimilarityScore   float64  `json:"similarity_score"` // Cosine similarity score
	GraphDistance     int      `json:"graph_distance"`   // Distance from query node in graph
	RetrievalMethod   string   `json:"retrieval_method"` // How it was retrieved (vector, graph, ltree)
	ConnectedEntities []Entity `json:"connected_entities,omitempty"`
}

RetrievalResult represents a chunk retrieved by a query

type TraversalNode

type TraversalNode struct {
	ChunkID uuid.UUID   `json:"chunk_id"`
	Depth   int         `json:"depth"`
	Path    []uuid.UUID `json:"path"`
}

TraversalNode represents a node in a graph traversal

Jump to

Keyboard shortcuts

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