Documentation
¶
Overview ¶
Package latticedb will host the pure Go LatticeDB engine.
The repo is being bootstrapped contract-first. The engine conformance spec and extracted conformance suite are in docs/ and conformance/go/; the concrete engine API and storage implementation will be built against that contract.
Index ¶
- Constants
- Variables
- func Dump(dbPath string) ([]byte, error)
- func DumpContext(ctx context.Context, dbPath string) ([]byte, error)
- func Export(dbPath string, format ExportFormat, outputPath string) ([]byte, error)
- func ExportContext(ctx context.Context, dbPath string, format ExportFormat, outputPath string) ([]byte, error)
- func HashEmbed(text string, dimensions uint16) ([]float32, error)deprecated
- func SimulateCrash(dbPath string) error
- func Version() string
- type CreateEdgeOptions
- type CreateNodeOptions
- type DB
- func (db *DB) Begin(readOnly bool) (*Tx, error)
- func (db *DB) BeginRead() (*Tx, error)
- func (db *DB) BeginSnapshot() (*Snapshot, error)
- func (db *DB) BeginWrite() (*Tx, error)
- func (db *DB) CacheClear() error
- func (db *DB) CacheStats() (QueryCacheStats, error)
- func (db *DB) Changes(afterSequence uint64, limit uint, timeoutMS uint32) ([]StreamRecord, error)
- func (db *DB) Checkpoint() error
- func (db *DB) Close() error
- func (db *DB) CreateEdgePropertyIndex(edgeType, property string) error
- func (db *DB) CreateNodePropertyIndex(label, property string) error
- func (db *DB) DropEdgePropertyIndex(edgeType, property string) error
- func (db *DB) DropNodePropertyIndex(label, property string) error
- func (db *DB) Dump() ([]byte, error)
- func (db *DB) DumpContext(ctx context.Context) ([]byte, error)
- func (db *DB) DumpTo(output io.Writer) error
- func (db *DB) DumpToContext(ctx context.Context, output io.Writer) error
- func (db *DB) Export(format ExportFormat, outputPath string) ([]byte, error)
- func (db *DB) ExportContext(ctx context.Context, format ExportFormat, outputPath string) ([]byte, error)
- func (db *DB) ExportTo(format ExportFormat, output io.Writer) error
- func (db *DB) ExportToContext(ctx context.Context, format ExportFormat, output io.Writer) error
- func (db *DB) FTSSearch(query string, opts FTSSearchOptions) ([]FTSSearchResult, error)
- func (db *DB) FTSSearchContext(ctx context.Context, query string, opts FTSSearchOptions) ([]FTSSearchResult, error)
- func (db *DB) FTSSearchFuzzy(query string, opts FTSSearchOptions) ([]FTSSearchResult, error)
- func (db *DB) GetNodesByLabel(label string) ([]NodeID, error)
- func (db *DB) GetStreamOffset(stream, consumer string) (uint64, bool, error)
- func (db *DB) IsOpen() bool
- func (db *DB) Path() string
- func (db *DB) Query(query string, params map[string]Value) (QueryResult, error)
- func (db *DB) QueryContext(ctx context.Context, query string, params map[string]Value, opts QueryOptions) (QueryResult, error)
- func (db *DB) ReadStream(stream string, afterSequence uint64, limit uint, timeoutMS uint32) ([]StreamRecord, error)
- func (db *DB) RebuildVectorIndexContext(ctx context.Context) error
- func (db *DB) Serialize() ([]byte, error)
- func (db *DB) Update(fn func(*Tx) error) error
- func (db *DB) UpdateContext(ctx context.Context, fn func(*Tx) error) error
- func (db *DB) VectorIndexStats() (VectorIndexStats, error)
- func (db *DB) VectorSearch(vector []float32, opts VectorSearchOptions) ([]VectorSearchResult, error)
- func (db *DB) VectorSearchContext(ctx context.Context, vector []float32, opts VectorSearchOptions) ([]VectorSearchResult, error)
- func (db *DB) View(fn func(*Tx) error) error
- type DurabilityMode
- type Edge
- type EdgeID
- type EmbeddingAPIFormatdeprecated
- type EmbeddingClientdeprecated
- type EmbeddingConfigdeprecated
- type Error
- type ErrorCode
- type ExportFormat
- type FTSSearchOptions
- type FTSSearchResult
- type Node
- type NodeID
- type OpenOptions
- type QueryCacheStats
- type QueryError
- type QueryErrorLocation
- type QueryErrorStage
- type QueryOptions
- type QueryResult
- type Snapshot
- type StreamRecord
- type Tx
- func (tx *Tx) BatchInsert(label string, vectors [][]float32) ([]uint64, error)deprecated
- func (tx *Tx) BatchInsertVectors(label string, vectors [][]float32) ([]uint64, error)
- func (tx *Tx) Commit() error
- func (tx *Tx) CommitContext(ctx context.Context) error
- func (tx *Tx) CreateEdge(sourceID uint64, targetID uint64, edgeType string, opts CreateEdgeOptions) (Edge, error)
- func (tx *Tx) CreateNode(opts CreateNodeOptions) (Node, error)
- func (tx *Tx) DeleteAppMetadata(key []byte) error
- func (tx *Tx) DeleteEdge(sourceID, targetID NodeID, edgeType string) error
- func (tx *Tx) DeleteNode(nodeID uint64) error
- func (tx *Tx) FTSIndex(nodeID uint64, text string) error
- func (tx *Tx) FTSIndexContext(ctx context.Context, nodeID uint64, text string) error
- func (tx *Tx) FindEdgesByTypeProperty(edgeType, property string, value Value, limit uint) ([]uint64, error)
- func (tx *Tx) FindNodesByLabelProperty(label, property string, value Value, limit uint) ([]uint64, error)
- func (tx *Tx) GetAppMetadata(key []byte) ([]byte, bool, error)
- func (tx *Tx) GetEdgeProperty(edgeID uint64, key string) (Value, bool, error)
- func (tx *Tx) GetIncomingEdges(nodeID uint64) ([]Edge, error)
- func (tx *Tx) GetIncomingEdgesByType(nodeID uint64, edgeType string, limit uint) ([]Edge, error)
- func (tx *Tx) GetNode(nodeID uint64) (*Node, error)
- func (tx *Tx) GetOutgoingEdges(nodeID uint64) ([]Edge, error)
- func (tx *Tx) GetOutgoingEdgesByType(nodeID uint64, edgeType string, limit uint) ([]Edge, error)
- func (tx *Tx) GetProperty(nodeID uint64, key string) (Value, bool, error)
- func (tx *Tx) IsActive() bool
- func (tx *Tx) IsReadOnly() bool
- func (tx *Tx) NodeExists(nodeID uint64) (bool, error)
- func (tx *Tx) PublishStream(stream, kind string, payload Value) error
- func (tx *Tx) PublishStreamGetSequence(stream, kind string, payload Value) (uint64, error)
- func (tx *Tx) PutAppMetadata(key, value []byte) error
- func (tx *Tx) Query(query string, params map[string]Value) (QueryResult, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, params map[string]Value, opts QueryOptions) (QueryResult, error)
- func (tx *Tx) RemoveEdgeProperty(edgeID uint64, key string) error
- func (tx *Tx) Rollback() error
- func (tx *Tx) SetEdgeProperty(edgeID uint64, key string, value Value) error
- func (tx *Tx) SetProperty(nodeID uint64, key string, value Value) error
- func (tx *Tx) SetStreamOffset(stream, consumer string, sequence uint64) error
- func (tx *Tx) SetVector(nodeID uint64, key string, vector []float32) error
- func (tx *Tx) TrimStream(stream string, beforeSequence uint64) error
- type Value
- type VectorIndexMode
- type VectorIndexStats
- type VectorSearchOptions
- type VectorSearchResult
Constants ¶
const ( // Deprecated: use embedding.APIFormatOllama. EmbeddingAPIFormatOllama = latticeembedding.APIFormatOllama // Deprecated: use embedding.APIFormatOpenAI. EmbeddingAPIFormatOpenAI = latticeembedding.APIFormatOpenAI )
Variables ¶
var ( // These aliases preserve the upstream sentinel names. Pure-Go errors may // still carry richer engine-specific sentinels where appropriate. ErrReadOnlyDatabase = ErrReadOnly ErrReadOnlyTx = ErrReadOnly )
var ( ErrReadOnly = engine.ErrReadOnly ErrWriteTxActive = engine.ErrWriteTxActive ErrManagedTransaction = engine.ErrManagedTransaction ErrInactiveTx = engine.ErrInactiveTx ErrDatabaseLocked = engine.ErrDatabaseLocked ErrDatabaseLayoutConflict = engine.ErrDatabaseLayoutConflict ErrDatabaseClosed = engine.ErrDatabaseClosed ErrTransactionsActive = engine.ErrTransactionsActive ErrSnapshotActive = engine.ErrSnapshotActive ErrWriteConflict = engine.ErrWriteConflict ErrRecoveryRequired = engine.ErrRecoveryRequired ErrResourceLimit = engine.ErrResourceLimit ErrAlreadyExists = engine.ErrAlreadyExists ErrInvalidArgument = engine.ErrInvalidArgument ErrVectorIndexMaintenanceRequired = engine.ErrVectorIndexMaintenanceRequired ErrUnsupportedOption = engine.ErrUnsupportedOption ErrCommitOutcomeUnknown = engine.ErrCommitOutcomeUnknown )
var ErrEmbeddingClosed = errors.New("embedding client is closed")
ErrEmbeddingClosed is returned when Embed is called after Close.
Deprecated: use embedding.ErrClosed.
Functions ¶
func ExportContext ¶
func SimulateCrash ¶
Types ¶
type CreateEdgeOptions ¶
type CreateNodeOptions ¶
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)
Open opens a directory-backed database or a regular database file previously returned by Serialize.
func OpenContext ¶
func (*DB) BeginSnapshot ¶
BeginSnapshot pins one committed generation while database writes continue. Only one Snapshot may be active for a DB.
func (*DB) BeginWrite ¶
func (*DB) CacheClear ¶
func (*DB) CacheStats ¶
func (db *DB) CacheStats() (QueryCacheStats, error)
func (*DB) Checkpoint ¶
func (*DB) CreateEdgePropertyIndex ¶
func (*DB) CreateNodePropertyIndex ¶
func (*DB) DropEdgePropertyIndex ¶
func (*DB) DropNodePropertyIndex ¶
func (*DB) DumpToContext ¶
DumpToContext observes cancellation between writes. It cannot interrupt an output writer that is itself blocked in Write.
func (*DB) ExportContext ¶
func (*DB) ExportToContext ¶
ExportToContext observes cancellation between writes. It cannot interrupt an output writer that is itself blocked in Write.
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) FTSSearchFuzzy ¶
func (db *DB) FTSSearchFuzzy(query string, opts FTSSearchOptions) ([]FTSSearchResult, error)
func (*DB) GetStreamOffset ¶
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, params map[string]Value, opts QueryOptions) (QueryResult, error)
func (*DB) ReadStream ¶
func (*DB) RebuildVectorIndexContext ¶
func (*DB) Serialize ¶
Serialize returns a standalone database file. Writing the bytes to a regular file produces a path that Open can read and update.
func (*DB) UpdateContext ¶
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)
type DurabilityMode ¶
type DurabilityMode uint8
const ( DurabilityStandard DurabilityMode = iota DurabilityFull )
type EmbeddingAPIFormat
deprecated
type EmbeddingAPIFormat = latticeembedding.APIFormat
EmbeddingAPIFormat selects the wire format used by an embedding endpoint.
Deprecated: use package github.com/mrchypark/latticedb-go/embedding.
type EmbeddingClient
deprecated
type EmbeddingClient struct {
// contains filtered or unexported fields
}
EmbeddingClient is an optional HTTP embedding client.
Deprecated: use embedding.Client.
func NewEmbeddingClient
deprecated
func NewEmbeddingClient(config EmbeddingConfig) (*EmbeddingClient, error)
NewEmbeddingClient creates an HTTP embedding client.
Deprecated: use embedding.NewClient.
func (*EmbeddingClient) Close ¶
func (client *EmbeddingClient) Close() error
Close releases this client. It is safe to call more than once.
type EmbeddingConfig
deprecated
type EmbeddingConfig = latticeembedding.Config
EmbeddingConfig configures an optional HTTP embedding client.
Deprecated: use embedding.Config.
type ErrorCode ¶
type ErrorCode int
ErrorCode identifies a low-level database error. Values match the upstream Go binding so callers can keep using errors.As and code comparisons.
const ( ErrorOK ErrorCode = 0 ErrorGeneric ErrorCode = -1 ErrorIO ErrorCode = -2 ErrorCorruption ErrorCode = -3 ErrorNotFound ErrorCode = -4 ErrorAlreadyExists ErrorCode = -5 ErrorInvalidArg ErrorCode = -6 ErrorTxnAborted ErrorCode = -7 ErrorLockTimeout ErrorCode = -8 ErrorReadOnly ErrorCode = -9 ErrorFull ErrorCode = -10 ErrorVersionMismatch ErrorCode = -11 ErrorChecksum ErrorCode = -12 ErrorOutOfMemory ErrorCode = -13 ErrorUnsupported ErrorCode = -14 ErrorValueTooLarge ErrorCode = -15 ErrorDatabaseLocked ErrorCode = -16 )
type ExportFormat ¶
type ExportFormat string
const ( ExportFormatJSON ExportFormat = "json" ExportFormatJSONL ExportFormat = "jsonl" ExportFormatCSV ExportFormat = "csv" ExportFormatDOT ExportFormat = "dot" )
type FTSSearchOptions ¶
type FTSSearchResult ¶
type FTSSearchResult = engine.FTSSearchResult
type OpenOptions ¶
type OpenOptions struct {
Create bool
ReadOnly bool
CacheSizeMB uint32
PageSize uint32
EnableWAL bool
DisableWAL bool
EnableAdjacencyCache bool
EnableVectors bool
EnableVector bool
DisableLock bool
VectorIndexMode VectorIndexMode
VectorDimensions uint16
Durability DurabilityMode
WALCheckpointThresholdBytes uint64
// MaxDatabaseSnapshotBytes is a conservative upper bound for the canonical streamed snapshot payload.
MaxDatabaseSnapshotBytes uint64
// VectorIndexBuildMaxWork bounds synchronous HNSW distance work.
VectorIndexBuildMaxWork uint64
// VectorIndexBuildMaxLogicalBytes bounds conservative current+new index metadata, not process RSS.
VectorIndexBuildMaxLogicalBytes uint64
// DerivedIndexBuildMaxWork bounds label, edge, adjacency, and FTS index rebuild work during Open.
DerivedIndexBuildMaxWork uint64
// DerivedIndexBuildMaxLogicalBytes bounds conservative derived posting metadata, not process RSS.
DerivedIndexBuildMaxLogicalBytes uint64
}
type QueryCacheStats ¶
type QueryError ¶
type QueryError struct {
Code ErrorCode
Stage QueryErrorStage
Message string
DiagnosticCode string
Location *QueryErrorLocation
// contains filtered or unexported fields
}
QueryError is a structured query parsing, planning, or execution error.
func (*QueryError) Error ¶
func (e *QueryError) Error() string
func (*QueryError) Unwrap ¶
func (e *QueryError) Unwrap() error
type QueryErrorLocation ¶
QueryErrorLocation identifies the source span associated with a query error.
type QueryErrorStage ¶
type QueryErrorStage int
QueryErrorStage identifies the phase in which a query failed.
const ( QueryErrorStageNone QueryErrorStage = 0 QueryErrorStageParse QueryErrorStage = 1 QueryErrorStageSemantic QueryErrorStage = 2 QueryErrorStagePlan QueryErrorStage = 3 QueryErrorStageExecution QueryErrorStage = 4 )
type QueryOptions ¶
type QueryResult ¶
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is one fixed committed database generation.
type StreamRecord ¶
type StreamRecord = engine.StreamRecord
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a single-owner transaction handle. Its methods must not be called concurrently; use separate read transactions for concurrent work.
func (*Tx) BatchInsertVectors ¶
BatchInsertVectors inserts multiple vector-bearing nodes in a single call.
func (*Tx) CommitContext ¶
CommitContext makes the transaction inactive, whether it succeeds or fails.
func (*Tx) CreateEdge ¶
func (*Tx) CreateNode ¶
func (tx *Tx) CreateNode(opts CreateNodeOptions) (Node, error)
func (*Tx) DeleteAppMetadata ¶
func (*Tx) DeleteNode ¶
func (*Tx) FTSIndexContext ¶
func (*Tx) FindEdgesByTypeProperty ¶
func (*Tx) FindNodesByLabelProperty ¶
func (*Tx) GetEdgeProperty ¶
func (*Tx) GetIncomingEdgesByType ¶
func (*Tx) GetOutgoingEdgesByType ¶
func (*Tx) IsReadOnly ¶
func (*Tx) PublishStreamGetSequence ¶
func (*Tx) PutAppMetadata ¶
func (*Tx) QueryContext ¶
func (tx *Tx) QueryContext(ctx context.Context, query string, params map[string]Value, opts QueryOptions) (QueryResult, error)
func (*Tx) SetEdgeProperty ¶
func (*Tx) SetStreamOffset ¶
type VectorIndexMode ¶
type VectorIndexMode uint8
const ( // VectorIndexExactOnly is the safe zero-value: no derived index build or memory overhead. VectorIndexExactOnly VectorIndexMode = iota // VectorIndexHNSWSynchronous builds the approximate index before Open returns. 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 disables the approximate index and scans every vector.
Exact bool
// MaxWork and MaxBytes bound one direct search request's scalar work and logical scratch/result bytes, not process RSS. Zero MaxWork means no caller-requested work limit; zero MaxBytes uses a 64 MiB logical scratch limit.
MaxWork uint64
MaxBytes uint64
}
type VectorSearchResult ¶
type VectorSearchResult = engine.VectorSearchResult