Documentation
¶
Index ¶
- func DecodeGRPCWebFrame(framed []byte) ([]byte, string, error)
- func EncodeArrowColumnarDocs(docs []EdgeDocument) ([]byte, error)
- func EncodeGRPCWebFrame(payload []byte, includeOkTrailer bool) []byte
- type ClientConfig
- type ConflictStrategy
- type EdgeClient
- func (c *EdgeClient) Delete(ctx context.Context, id string) error
- func (c *EdgeClient) FlushSync(ctx context.Context) error
- func (c *EdgeClient) LocalIndex() *EdgeIndex
- func (c *EdgeClient) Search(ctx context.Context, query []float32, k int) ([]EdgeSearchResult, error)
- func (c *EdgeClient) SyncEngine() *SyncEngine
- func (c *EdgeClient) Upsert(ctx context.Context, doc EdgeDocument) error
- type EdgeDocument
- type EdgeIndex
- func (idx *EdgeIndex) Delete(id string) bool
- func (idx *EdgeIndex) ExportJSON() ([]byte, error)
- func (idx *EdgeIndex) ImportJSON(data []byte) error
- func (idx *EdgeIndex) Len() int
- func (idx *EdgeIndex) Search(query []float32, k int) ([]EdgeSearchResult, error)
- func (idx *EdgeIndex) Upsert(doc EdgeDocument) error
- type EdgeSearchResult
- type Metric
- type PendingMutation
- type SyncEngine
- func (s *SyncEngine) Drain() []PendingMutation
- func (s *SyncEngine) PendingCount() int
- func (s *SyncEngine) RecordLocal(op string, doc EdgeDocument, ts int64) PendingMutation
- func (s *SyncEngine) Requeue(muts []PendingMutation)
- func (s *SyncEngine) ResolveConflict(local EdgeDocument, localClock map[string]int64, remote EdgeDocument, ...) (EdgeDocument, map[string]int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeGRPCWebFrame ¶
DecodeGRPCWebFrame extracts the data frame payload and optional trailers from a gRPC-Web body.
func EncodeArrowColumnarDocs ¶
func EncodeArrowColumnarDocs(docs []EdgeDocument) ([]byte, error)
EncodeArrowColumnarDocs serializes EdgeDocuments into a compact binary Arrow-layout columnar buffer (magic "LBAR", uint32 count, uint32 dim, contiguous float32 vector buffer + length-prefixed IDs).
func EncodeGRPCWebFrame ¶
EncodeGRPCWebFrame wraps a message payload in a standard 5-byte gRPC-Web data frame (flag 0x00 + 4-byte BigEndian length) and optional trailer frame (flag 0x80).
Types ¶
type ClientConfig ¶
type ClientConfig struct {
Endpoint string `json:"endpoint"`
Dataset string `json:"dataset"`
APIKey string `json:"api_key,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
ClientID string `json:"client_id,omitempty"`
Metric Metric `json:"metric,omitempty"`
ConflictStrategy ConflictStrategy `json:"conflict_strategy,omitempty"`
OfflineFirst bool `json:"offline_first"`
UseGRPCWeb bool `json:"use_grpc_web,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
}
ClientConfig configures an offline-capable WASM / edge Longbow client.
type ConflictStrategy ¶
type ConflictStrategy string
ConflictStrategy determines how divergent local vs remote mutations resolve during sync.
const ( ConflictLWW ConflictStrategy = "lww" ConflictVectorClock ConflictStrategy = "vector_clock" )
type EdgeClient ¶
type EdgeClient struct {
// contains filtered or unexported fields
}
EdgeClient provides hybrid local-HNSW + remote HTTP/gRPC-web transport and offline sync.
func NewEdgeClient ¶
func NewEdgeClient(cfg ClientConfig) (*EdgeClient, error)
NewEdgeClient constructs an edge/WASM Longbow client.
func (*EdgeClient) Delete ¶
func (c *EdgeClient) Delete(ctx context.Context, id string) error
Delete removes locally and queues a tombstone mutation for sync.
func (*EdgeClient) FlushSync ¶
func (c *EdgeClient) FlushSync(ctx context.Context) error
FlushSync pushes queued local mutations to the upstream HTTP/gRPC-web sync endpoint.
func (*EdgeClient) LocalIndex ¶
func (c *EdgeClient) LocalIndex() *EdgeIndex
LocalIndex exposes the embedded pure-Go/WASM HNSW index.
func (*EdgeClient) Search ¶
func (c *EdgeClient) Search(ctx context.Context, query []float32, k int) ([]EdgeSearchResult, error)
Search queries local WASM HNSW when OfflineFirst (or on upstream failure) and falls back/queries upstream HTTP endpoint.
func (*EdgeClient) SyncEngine ¶
func (c *EdgeClient) SyncEngine() *SyncEngine
SyncEngine exposes the offline-first queue and conflict resolver.
func (*EdgeClient) Upsert ¶
func (c *EdgeClient) Upsert(ctx context.Context, doc EdgeDocument) error
Upsert inserts or updates locally immediately (if OfflineFirst or disconnected) and queues sync.
type EdgeDocument ¶
type EdgeDocument struct {
ID string `json:"id"`
Vector []float32 `json:"vector"`
Metadata map[string]any `json:"metadata,omitempty"`
UpdatedAt int64 `json:"updated_at"`
Deleted bool `json:"deleted,omitempty"`
}
EdgeDocument holds a locally cached or edge-indexed vector and its metadata.
func DecodeArrowColumnarDocs ¶
func DecodeArrowColumnarDocs(raw []byte) ([]EdgeDocument, error)
DecodeArrowColumnarDocs deserializes a binary columnar buffer produced by EncodeArrowColumnarDocs.
type EdgeIndex ¶
type EdgeIndex struct {
// contains filtered or unexported fields
}
EdgeIndex implements a zero-dependency, WASM-friendly hierarchical small-world vector index for browser / Cloudflare Workers / Deno offline-first execution.
func NewEdgeIndex ¶
NewEdgeIndex creates a lightweight HNSW index suitable for WASM and edge environments.
func (*EdgeIndex) ExportJSON ¶
ExportJSON serializes local edge index documents for IndexedDB/KV persistence.
func (*EdgeIndex) ImportJSON ¶
ImportJSON restores serialized edge index documents and rebuilds the HNSW graph.
func (*EdgeIndex) Search ¶
func (idx *EdgeIndex) Search(query []float32, k int) ([]EdgeSearchResult, error)
Search performs hierarchical HNSW approximate nearest-neighbor search in pure Go/WASM.
func (*EdgeIndex) Upsert ¶
func (idx *EdgeIndex) Upsert(doc EdgeDocument) error
Upsert inserts or updates a document in the local HNSW graph.
type EdgeSearchResult ¶
type EdgeSearchResult struct {
ID string `json:"id"`
Distance float32 `json:"distance"`
Score float32 `json:"score"`
Metadata map[string]any `json:"metadata,omitempty"`
}
EdgeSearchResult represents a ranked match returned by the edge HNSW index.
type Metric ¶
type Metric string
Metric defines vector similarity metric for local Edge HNSW search.
type PendingMutation ¶
type PendingMutation struct {
ClientID string `json:"client_id"`
Op string `json:"op"` // "upsert" or "delete"
Doc EdgeDocument `json:"doc"`
Timestamp int64 `json:"timestamp"`
Clock map[string]int64 `json:"clock,omitempty"`
}
PendingMutation represents a local offline-first write queued for server synchronization.
type SyncEngine ¶
type SyncEngine struct {
// contains filtered or unexported fields
}
SyncEngine manages offline mutation queuing, vector clocks, and conflict resolution.
func NewSyncEngine ¶
func NewSyncEngine(clientID string, strategy ConflictStrategy) *SyncEngine
NewSyncEngine initializes an offline-first synchronization engine for an edge client.
func (*SyncEngine) Drain ¶
func (s *SyncEngine) Drain() []PendingMutation
Drain returns queued mutations atomically when syncing to upstream.
func (*SyncEngine) PendingCount ¶
func (s *SyncEngine) PendingCount() int
PendingCount returns queued offline mutations waiting to sync.
func (*SyncEngine) RecordLocal ¶
func (s *SyncEngine) RecordLocal(op string, doc EdgeDocument, ts int64) PendingMutation
RecordLocal queues a local mutation and advances the document's vector clock.
func (*SyncEngine) Requeue ¶
func (s *SyncEngine) Requeue(muts []PendingMutation)
Requeue restores mutations if upstream flush fails transiently.
func (*SyncEngine) ResolveConflict ¶
func (s *SyncEngine) ResolveConflict(local EdgeDocument, localClock map[string]int64, remote EdgeDocument, remoteClock map[string]int64, remoteNodeID string) (EdgeDocument, map[string]int64)
ResolveConflict compares a local document state against a remote update and returns the winning EdgeDocument and merged vector clock.