engine

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadOnly                       = errors.New("database is read-only")
	ErrWriteTxActive                  = errors.New("write transaction is already active")
	ErrManagedTransaction             = errors.New("managed transaction cannot be completed directly")
	ErrInactiveTx                     = errors.New("transaction is inactive")
	ErrDatabaseClosed                 = errors.New("database is closed")
	ErrTransactionsActive             = errors.New("database has active transactions")
	ErrSnapshotActive                 = errors.New("database has an active snapshot")
	ErrWriteConflict                  = errors.New("write transaction conflicts with current commit")
	ErrRecoveryRequired               = errors.New("database requires close and recovery")
	ErrResourceLimit                  = errors.New("resource limit exceeded")
	ErrAlreadyExists                  = errors.New("already exists")
	ErrInvalidArgument                = errors.New("invalid argument")
	ErrVectorIndexMaintenanceRequired = errors.New("vector index maintenance required")
	ErrUnsupportedOption              = errors.New("unsupported option")
	ErrCommitOutcomeUnknown           = store.ErrCommitOutcomeUnknown
)
View Source
var (
	ErrDatabaseLocked         = errors.New("database is locked")
	ErrDatabaseLayoutConflict = errors.New("database layout conflicts with existing owner")
)

Functions

This section is empty.

Types

type CreateEdgeOptions

type CreateEdgeOptions struct {
	Properties map[string]any
}

type CreateNodeOptions

type CreateNodeOptions struct {
	Labels     []string
	Properties map[string]any
}

type DB

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

func Deserialize

func Deserialize(data []byte, opts OpenOptions) (*DB, error)

Deserialize opens a database from bytes returned by Serialize.

func Open

func Open(path string, opts OpenOptions) (*DB, error)

func OpenContext

func OpenContext(ctx context.Context, path string, opts OpenOptions) (*DB, error)

func (*DB) Begin

func (db *DB) Begin(readOnly bool) (*Tx, error)

func (*DB) BeginSnapshot

func (db *DB) BeginSnapshot() (*Snapshot, error)

func (*DB) BeginWriteContext added in v0.5.0

func (db *DB) BeginWriteContext(ctx context.Context) (*Tx, error)

BeginWriteContext waits for the single writer slot until ctx is canceled. Begin(false) remains the nonblocking compatibility API.

func (*DB) CacheClear

func (db *DB) CacheClear() error

func (*DB) CacheStats

func (db *DB) CacheStats() (QueryCacheStats, error)

func (*DB) Changes

func (db *DB) Changes(afterSequence uint64, limit uint, timeoutMS uint32) ([]StreamRecord, error)

func (*DB) ChangesContext added in v0.3.0

func (db *DB) ChangesContext(ctx context.Context, afterSequence uint64, opts StreamReadOptions) (StreamReadResult, error)

func (*DB) Checkpoint

func (db *DB) Checkpoint() error

func (*DB) CheckpointContext added in v0.5.0

func (db *DB) CheckpointContext(ctx context.Context) error

CheckpointContext waits for the writer slot until ctx is canceled. The existing Checkpoint method remains nonblocking for compatibility.

func (*DB) Close

func (db *DB) Close() error

func (*DB) CloseContext added in v0.5.0

func (db *DB) CloseContext(ctx context.Context) error

CloseContext waits for the writer slot until ctx is canceled. After the closed transition, teardown is deliberately noncancelable.

func (*DB) CreateEdgePropertyIndex

func (db *DB) CreateEdgePropertyIndex(edgeType, property string) error

func (*DB) CreateEdgePropertyIndexContext added in v0.5.0

func (db *DB) CreateEdgePropertyIndexContext(ctx context.Context, edgeType, property string) error

func (*DB) CreateNodePropertyIndex

func (db *DB) CreateNodePropertyIndex(label, property string) error

func (*DB) CreateNodePropertyIndexContext added in v0.5.0

func (db *DB) CreateNodePropertyIndexContext(ctx context.Context, label, property string) error

func (*DB) DropEdgePropertyIndex

func (db *DB) DropEdgePropertyIndex(edgeType, property string) error

func (*DB) DropNodePropertyIndex

func (db *DB) DropNodePropertyIndex(label, property string) error

func (*DB) FTSSearch

func (db *DB) FTSSearch(query string, opts FTSSearchOptions) ([]FTSSearchResult, error)

func (*DB) FTSSearchContext

func (db *DB) FTSSearchContext(ctx context.Context, query string, opts FTSSearchOptions) ([]FTSSearchResult, error)

func (*DB) GenerationRetentionStats added in v0.5.0

func (db *DB) GenerationRetentionStats() (GenerationRetentionStats, error)

func (*DB) GetNodesByLabel

func (db *DB) GetNodesByLabel(label string) ([]uint64, error)

func (*DB) GetStreamOffset

func (db *DB) GetStreamOffset(stream, consumer string) (uint64, bool, error)

func (*DB) IsOpen

func (db *DB) IsOpen() bool

func (*DB) Query

func (db *DB) Query(query string, params map[string]any) (QueryResult, error)

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, params map[string]any, opts QueryOptions) (QueryResult, error)

func (*DB) ReadStream

func (db *DB) ReadStream(stream string, afterSequence uint64, limit uint, timeoutMS uint32) ([]StreamRecord, error)

func (*DB) ReadStreamContext added in v0.3.0

func (db *DB) ReadStreamContext(ctx context.Context, stream string, afterSequence uint64, opts StreamReadOptions) (StreamReadResult, error)

ReadStreamContext reads stream records until a record is available, the byte budget is reached, or ctx is canceled. A zero MaxBytes disables the byte limit.

func (*DB) RebuildVectorIndexContext

func (db *DB) RebuildVectorIndexContext(ctx context.Context) error

func (*DB) Serialize

func (db *DB) Serialize() ([]byte, error)

Serialize returns a standalone database file. Writing the bytes to a regular file produces a path that Open can read and update.

func (*DB) SnapshotGraph

func (db *DB) SnapshotGraph() (*store.GraphState, *GenerationLease, error)

func (*DB) Update

func (db *DB) Update(fn func(*Tx) error) error

func (*DB) UpdateContext

func (db *DB) UpdateContext(ctx context.Context, fn func(*Tx) error) error

func (*DB) VectorIndexStats

func (db *DB) VectorIndexStats() (VectorIndexStats, error)

func (*DB) VectorSearch

func (db *DB) VectorSearch(vector []float32, opts VectorSearchOptions) ([]VectorSearchResult, error)

func (*DB) VectorSearchContext

func (db *DB) VectorSearchContext(ctx context.Context, vector []float32, opts VectorSearchOptions) ([]VectorSearchResult, error)

func (*DB) View

func (db *DB) View(fn func(*Tx) error) error

type DurabilityMode

type DurabilityMode uint8
const (
	DurabilityStandard DurabilityMode = iota
	DurabilityFull
)

type Edge

type Edge struct {
	ID         uint64
	SourceID   uint64
	TargetID   uint64
	Type       string
	Properties map[string]any
}

type FTSSearchOptions

type FTSSearchOptions struct {
	Limit         uint32
	MaxDistance   uint32
	MinTermLength uint32
	MaxWork       uint64
	MaxBytes      uint64
}

type FTSSearchResult

type FTSSearchResult struct {
	NodeID uint64
	Score  float32
}

type GenerationLease added in v0.5.0

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

GenerationLease pins a graph generation until Release. It is used by read transactions, snapshots, and exports; callers must release it exactly once.

func (*GenerationLease) Release added in v0.5.0

func (lease *GenerationLease) Release()

Release releases this generation pin. It is idempotent.

type GenerationRetentionStats added in v0.5.0

type GenerationRetentionStats struct {
	ActiveLeases         uint64
	ActiveSnapshotLeases uint64
	RetainedGenerations  uint64
	RetainedLogicalBytes uint64
	OldestLeaseAge       time.Duration
}

type Node

type Node struct {
	ID         uint64
	Labels     []string
	Properties map[string]any
}

type OpenOptions

type OpenOptions struct {
	Create                            bool
	ReadOnly                          bool
	DisableLock                       bool
	CacheSizeMB                       uint32
	PageSize                          uint32
	EnableVector                      bool
	VectorIndexMode                   VectorIndexMode
	VectorDimensions                  uint16
	Durability                        DurabilityMode
	WALCheckpointThresholdBytes       uint64
	ChangefeedMaxBytes                uint64
	MaxDatabaseSnapshotBytes          uint64
	RecoveryMaxDecodedBytes           uint64
	RecoveryMaxFrames                 uint64
	RecoveryMaxWork                   uint64
	VectorIndexBuildMaxWork           uint64
	VectorIndexBuildMaxLogicalBytes   uint64
	DerivedIndexBuildMaxWork          uint64
	DerivedIndexBuildMaxLogicalBytes  uint64
	MaxGenerationLeases               uint64
	MaxRetainedGenerationLogicalBytes uint64
	// contains filtered or unexported fields
}

type QueryCacheStats

type QueryCacheStats struct {
	Entries uint32
	Hits    uint64
	Misses  uint64
}

type QueryError

type QueryError struct {
	Stage QueryErrorStage
	Err   error
}

func (*QueryError) Error

func (e *QueryError) Error() string

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

type QueryErrorStage

type QueryErrorStage uint8
const (
	QueryErrorStageParse QueryErrorStage = iota + 1
	QueryErrorStageExecution
)

type QueryOptions

type QueryOptions struct {
	MaxRows  uint64
	MaxWork  uint64
	MaxBytes uint64
}

type QueryResult

type QueryResult struct {
	Columns []string
	Rows    []map[string]any
}

type Snapshot

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

Snapshot pins one committed database generation while writers continue.

func (*Snapshot) Backup

func (snapshot *Snapshot) Backup(path string) error

func (*Snapshot) Close

func (snapshot *Snapshot) Close() error

type StreamReadOptions added in v0.3.0

type StreamReadOptions struct {
	Limit    uint
	MaxBytes uint64
}

type StreamReadResult added in v0.3.0

type StreamReadResult struct {
	Records      []StreamRecord
	LastSequence uint64
	ByteLimited  bool
}

type StreamRecord

type StreamRecord = store.StreamRecord

type Tx

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

func (*Tx) BatchInsert deprecated

func (tx *Tx) BatchInsert(label string, vectors [][]float32) ([]uint64, error)

Deprecated: use BatchInsertVectors. Earliest removal is v0.6.0.

func (*Tx) BatchInsertVectors

func (tx *Tx) BatchInsertVectors(label string, vectors [][]float32) ([]uint64, error)

BatchInsertVectors inserts vector-bearing nodes with label. Vectors are stored in the "vector" property for compatibility with the public API.

func (*Tx) Commit

func (tx *Tx) Commit() error

func (*Tx) CommitContext

func (tx *Tx) CommitContext(ctx context.Context) error

func (*Tx) CreateEdge

func (tx *Tx) CreateEdge(sourceID uint64, targetID uint64, edgeType string, opts CreateEdgeOptions) (Edge, error)

func (*Tx) CreateNode

func (tx *Tx) CreateNode(opts CreateNodeOptions) (Node, error)

func (*Tx) DeleteAppMetadata

func (tx *Tx) DeleteAppMetadata(key []byte) error

func (*Tx) DeleteEdge

func (tx *Tx) DeleteEdge(sourceID, targetID uint64, edgeType string) error

func (*Tx) DeleteNode

func (tx *Tx) DeleteNode(nodeID uint64) error

func (*Tx) FTSIndex

func (tx *Tx) FTSIndex(nodeID uint64, text string) error

func (*Tx) FTSIndexContext

func (tx *Tx) FTSIndexContext(ctx context.Context, nodeID uint64, text string) error

func (*Tx) FindEdgesByTypeProperty

func (tx *Tx) FindEdgesByTypeProperty(edgeType, property string, value any, limit uint) ([]uint64, error)

func (*Tx) FindNodesByLabelProperty

func (tx *Tx) FindNodesByLabelProperty(label, property string, value any, limit uint) ([]uint64, error)

func (*Tx) GetAppMetadata

func (tx *Tx) GetAppMetadata(key []byte) ([]byte, bool, error)

func (*Tx) GetEdgeProperty

func (tx *Tx) GetEdgeProperty(edgeID uint64, key string) (any, bool, error)

func (*Tx) GetIncomingEdges

func (tx *Tx) GetIncomingEdges(nodeID uint64) ([]Edge, error)

func (*Tx) GetIncomingEdgesByType

func (tx *Tx) GetIncomingEdgesByType(nodeID uint64, edgeType string, limit uint) ([]Edge, error)

func (*Tx) GetNode

func (tx *Tx) GetNode(nodeID uint64) (*Node, error)

func (*Tx) GetNodeValue

func (tx *Tx) GetNodeValue(nodeID uint64) (Node, bool, error)

func (*Tx) GetOutgoingEdges

func (tx *Tx) GetOutgoingEdges(nodeID uint64) ([]Edge, error)

func (*Tx) GetOutgoingEdgesByType

func (tx *Tx) GetOutgoingEdgesByType(nodeID uint64, edgeType string, limit uint) ([]Edge, error)

func (*Tx) GetProperty

func (tx *Tx) GetProperty(nodeID uint64, key string) (any, bool, error)

func (*Tx) IsActive

func (tx *Tx) IsActive() bool

func (*Tx) IsReadOnly

func (tx *Tx) IsReadOnly() bool

func (*Tx) NodeExists

func (tx *Tx) NodeExists(nodeID uint64) (bool, error)

func (*Tx) PublishStream

func (tx *Tx) PublishStream(stream, kind string, payload any) error

func (*Tx) PublishStreamGetSequence

func (tx *Tx) PublishStreamGetSequence(stream, kind string, payload any) (uint64, error)

func (*Tx) PutAppMetadata

func (tx *Tx) PutAppMetadata(key, value []byte) error

func (*Tx) Query

func (tx *Tx) Query(query string, params map[string]any) (QueryResult, error)

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, params map[string]any, opts QueryOptions) (QueryResult, error)

func (*Tx) RemoveEdgeProperty

func (tx *Tx) RemoveEdgeProperty(edgeID uint64, key string) error

func (*Tx) Rollback

func (tx *Tx) Rollback() error

func (*Tx) SetEdgeProperty

func (tx *Tx) SetEdgeProperty(edgeID uint64, key string, value any) error

func (*Tx) SetProperty

func (tx *Tx) SetProperty(nodeID uint64, key string, value any) error

func (*Tx) SetStreamOffset

func (tx *Tx) SetStreamOffset(stream, consumer string, sequence uint64) error

func (*Tx) SetVector

func (tx *Tx) SetVector(nodeID uint64, key string, vector []float32) error

func (*Tx) TrimStream

func (tx *Tx) TrimStream(stream string, beforeSequence uint64) error

type VectorIndexMode

type VectorIndexMode uint8
const (
	VectorIndexExactOnly VectorIndexMode = iota
	VectorIndexHNSWSynchronous
)

type VectorIndexStats

type VectorIndexStats struct {
	LiveEntries                uint64
	IndexEntries               uint64
	Tombstones                 uint64
	TombstoneBytes             uint64
	TombstoneBytesUntilRebuild uint64
	MutationDebt               uint64
	RebuildThreshold           uint64
	DebtUntilRebuild           uint64
	EstimatedBuildLogicalBytes uint64
	ExactFallbacks             uint64
	Rebuilds                   uint64
	RebuildNanoseconds         uint64
}

type VectorSearchOptions

type VectorSearchOptions struct {
	K        uint32
	EfSearch uint16
	Exact    bool
	MaxWork  uint64
	MaxBytes uint64
}

type VectorSearchResult

type VectorSearchResult struct {
	NodeID   uint64
	Distance float32
}

Jump to

Keyboard shortcuts

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