wasmclient

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeGRPCWebFrame

func DecodeGRPCWebFrame(framed []byte) ([]byte, string, error)

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

func EncodeGRPCWebFrame(payload []byte, includeOkTrailer bool) []byte

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

func NewEdgeIndex(metric Metric, m, efConstruction int) *EdgeIndex

NewEdgeIndex creates a lightweight HNSW index suitable for WASM and edge environments.

func (*EdgeIndex) Delete

func (idx *EdgeIndex) Delete(id string) bool

Delete marks a document deleted in the edge index.

func (*EdgeIndex) ExportJSON

func (idx *EdgeIndex) ExportJSON() ([]byte, error)

ExportJSON serializes local edge index documents for IndexedDB/KV persistence.

func (*EdgeIndex) ImportJSON

func (idx *EdgeIndex) ImportJSON(data []byte) error

ImportJSON restores serialized edge index documents and rebuilds the HNSW graph.

func (*EdgeIndex) Len

func (idx *EdgeIndex) Len() int

Len returns active (non-deleted) documents in the edge index.

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.

const (
	MetricCosine Metric = "cosine"
	MetricL2     Metric = "l2"
)

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.

Jump to

Keyboard shortcuts

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