client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptimizationUnspecified             = pb.Optimization_OPTIMIZATION_UNSPECIFIED
	OptimizationMinimumSpanningTree     = pb.Optimization_OPTIMIZATION_MINIMUM_SPANNING_TREE
	OptimizationMaximumSpanningTree     = pb.Optimization_OPTIMIZATION_MAXIMUM_SPANNING_TREE
	OptimizationShortestPathTree        = pb.Optimization_OPTIMIZATION_SHORTEST_PATH_TREE
	OptimizationShortestPathTreeInverse = pb.Optimization_OPTIMIZATION_SHORTEST_PATH_TREE_INVERSE
)

Variables

View Source
var ErrInvalidType = errors.New("invalid type")

ErrInvalidType is returned by a Vertex.*Value method when the underlying oneof variant does not match the requested Go type and no safe coercion is available.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by GetVertex / GetEdge when the requested key or edge does not exist. Use errors.Is to detect it; the underlying gRPC error (with codes.NotFound) is wrapped for callers that need the full detail.

View Source
var ErrOverflow = errors.New("value overflow")

ErrOverflow is returned when a value is read into a Go type that cannot represent it (e.g. reading a negative int64 as uint, or a uint64 above math.MaxInt64 as int).

Functions

This section is empty.

Types

type Edge added in v0.5.0

type Edge pb.Edge

Edge is a thin type alias over the generated protobuf Edge that lets the client return the full record (including Expiration) instead of just the weight.

func (*Edge) ExpirationTime added in v0.5.0

func (e *Edge) ExpirationTime() time.Time

ExpirationTime returns the absolute expiration carried by e, or the zero time if no expiration was set on the server response.

type EdgeInput added in v0.5.0

type EdgeInput struct {
	Tail       string
	Head       string
	Weight     float32
	Expiration time.Time
}

EdgeInput describes one edge for the batch AddEdges / PutEdges APIs.

type EdgeRef added in v0.5.0

type EdgeRef struct {
	Tail string
	Head string
}

EdgeRef identifies an edge by its (tail, head) pair without weight. Used by DeleteEdges.

type Lantern

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

func NewLantern

func NewLantern(target string, opts ...Option) (*Lantern, error)

NewLantern dials target (host:port) and returns a connected Lantern client.

The connection is established lazily on the first RPC (grpc.NewClient semantics); pass a context with a deadline to your first call if you need bounded connect time.

Defaults:

  • insecure credentials (override with WithTransportCredentials)
  • retry policy on every idempotent RPC (override with WithDefaultServiceConfig)
  • batch helpers auto-chunk at 1000 entries (override with WithBatchChunkSize)

func (*Lantern) AddEdge

func (l *Lantern) AddEdge(ctx context.Context, tail string, head string, weight float32, ttl time.Duration) error

AddEdge accumulates weight onto the (tail, head) pair: repeated calls with the same endpoints sum their weights.

func (*Lantern) AddEdgeAt added in v0.5.0

func (l *Lantern) AddEdgeAt(ctx context.Context, tail string, head string, weight float32, expiration time.Time) error

AddEdgeAt is AddEdge with an absolute expiration.

func (*Lantern) AddEdges added in v0.5.0

func (l *Lantern) AddEdges(ctx context.Context, inputs []EdgeInput) error

AddEdges accumulates weight onto a batch of edges. Automatically chunked.

func (*Lantern) Close

func (l *Lantern) Close() error

func (*Lantern) DeleteEdge added in v0.4.0

func (l *Lantern) DeleteEdge(ctx context.Context, tail string, head string) error

func (*Lantern) DeleteEdges added in v0.5.0

func (l *Lantern) DeleteEdges(ctx context.Context, refs []EdgeRef) error

DeleteEdges removes a batch of edges. Automatically chunked.

func (*Lantern) DeleteVertex added in v0.4.0

func (l *Lantern) DeleteVertex(ctx context.Context, key string) error

func (*Lantern) DeleteVertices added in v0.5.0

func (l *Lantern) DeleteVertices(ctx context.Context, keys []string) error

DeleteVertices removes a batch of vertices. Automatically chunked to respect the server's MaxBatchSize cap. Edges incident to removed vertices are reaped lazily by the server's GC loop.

func (*Lantern) GetEdge

func (l *Lantern) GetEdge(ctx context.Context, tail string, head string) (*Edge, error)

GetEdge fetches the edge weight (and any expiration) between tail and head.

func (*Lantern) GetVertex

func (l *Lantern) GetVertex(ctx context.Context, key string) (*Vertex, error)

GetVertex fetches the vertex at key. Returns an error wrapping ErrNotFound when the key is absent.

func (*Lantern) Illuminate

func (l *Lantern) Illuminate(ctx context.Context, seed string, step uint32, k uint32, tfidf bool) (*model.Graph[string, *Vertex], error)

Illuminate runs a k-bounded BFS from seed, returning the resulting subgraph.

func (*Lantern) IlluminateWithOptimization added in v0.5.0

func (l *Lantern) IlluminateWithOptimization(ctx context.Context, seed string, step uint32, k uint32, tfidf bool, opt Optimization) (*model.Graph[string, *Vertex], error)

IlluminateWithOptimization is Illuminate with an explicit server-side post-processing strategy. Pass OptimizationUnspecified to disable it.

func (*Lantern) PutEdge added in v0.4.0

func (l *Lantern) PutEdge(ctx context.Context, tail string, head string, weight float32, ttl time.Duration) error

PutEdge overwrites the (tail, head) pair.

func (*Lantern) PutEdgeAt added in v0.5.0

func (l *Lantern) PutEdgeAt(ctx context.Context, tail string, head string, weight float32, expiration time.Time) error

PutEdgeAt is PutEdge with an absolute expiration.

func (*Lantern) PutEdges added in v0.5.0

func (l *Lantern) PutEdges(ctx context.Context, inputs []EdgeInput) error

PutEdges overwrites a batch of edges. Automatically chunked.

func (*Lantern) PutVertex

func (l *Lantern) PutVertex(ctx context.Context, key string, value any, ttl time.Duration) error

PutVertex upserts a single vertex with a relative TTL.

func (*Lantern) PutVertexAt added in v0.5.0

func (l *Lantern) PutVertexAt(ctx context.Context, key string, value any, expiration time.Time) error

PutVertexAt upserts a single vertex with an absolute expiration time.

func (*Lantern) PutVertices added in v0.5.0

func (l *Lantern) PutVertices(ctx context.Context, inputs []VertexInput) error

PutVertices upserts a batch of vertices. Large batches are automatically chunked according to WithBatchChunkSize (default 1000).

type Optimization added in v0.5.0

type Optimization = pb.Optimization

Optimization re-exports the server-side Optimization enum so SDK callers do not need to import the generated proto package directly.

type Option added in v0.5.0

type Option func(*options)

Option configures a Lantern client. Pass options to NewLantern.

func WithBatchChunkSize added in v0.5.0

func WithBatchChunkSize(n int) Option

WithBatchChunkSize overrides the auto-chunk size used by PutVertices, AddEdges, and PutEdges. Must be > 0; otherwise the default is kept.

func WithCompression added in v0.5.0

func WithCompression(name string) Option

WithCompression enables a per-call default compressor (e.g. "gzip"). The named compressor must be registered (gzip is registered automatically by this package). Pass "" to disable.

func WithDefaultServiceConfig added in v0.5.0

func WithDefaultServiceConfig(json string) Option

WithDefaultServiceConfig overrides the built-in retry policy with a custom gRPC service config JSON. Pass "" to disable the default policy entirely.

func WithDefaultTimeout added in v0.5.0

func WithDefaultTimeout(d time.Duration) Option

WithDefaultTimeout applies a per-call timeout to every RPC whose context has no deadline. RPCs whose caller already supplied a deadline are left alone. Pass 0 (the default) to disable.

func WithDialOption added in v0.5.0

func WithDialOption(opts ...grpc.DialOption) Option

WithDialOption appends an arbitrary grpc.DialOption. Use this for keepalive, balancer choice, or other transport-level tuning.

func WithTransportCredentials added in v0.5.0

func WithTransportCredentials(creds credentials.TransportCredentials) Option

WithTransportCredentials sets the gRPC transport credentials (TLS, mTLS). When unset, the client uses insecure credentials.

type Vertex

type Vertex pb.Vertex

Vertex is a thin type alias over the generated protobuf Vertex that adds Go-friendly value accessors. Convert a *pb.Vertex with (*Vertex)(p).

func (*Vertex) BoolValue

func (v *Vertex) BoolValue() (bool, error)

func (*Vertex) BytesValue

func (v *Vertex) BytesValue() ([]byte, error)

func (*Vertex) DurationValue added in v0.5.0

func (v *Vertex) DurationValue() (time.Duration, error)

func (*Vertex) ExpirationTime added in v0.5.0

func (v *Vertex) ExpirationTime() time.Time

ExpirationTime returns the absolute expiration carried by v, or the zero time if no expiration was set on the server response.

func (*Vertex) FloatValue

func (v *Vertex) FloatValue() (float64, error)

FloatValue widens any numeric oneof variant to float64.

func (*Vertex) IntValue

func (v *Vertex) IntValue() (int, error)

IntValue returns the underlying signed integer value. It also accepts unsigned variants and reports ErrOverflow when a Uint64 value exceeds math.MaxInt64.

func (*Vertex) IsNil

func (v *Vertex) IsNil() bool

func (*Vertex) Kind added in v0.5.0

func (v *Vertex) Kind() VertexKind

Kind reports which oneof variant is set on v.

func (*Vertex) MarshalJSON added in v0.5.0

func (v *Vertex) MarshalJSON() ([]byte, error)

MarshalJSON renders a Vertex as a stable, human-readable JSON object so callers don't have to peek at protobuf-generated oneof field names (e.g. "String_", "Int64", "Nil"). The shape is:

{
  "key":        "<key>",                // omitted when empty
  "type":       "string"|"int32"|...,   // VertexKind in lowercase
  "value":      <typed JSON value>,     // null for nil/unset
  "expiration": "<RFC3339Nano>"         // omitted when zero
}

Bytes are base64-encoded (Go's default for []byte); timestamps are RFC3339Nano.

func (*Vertex) StringValue

func (v *Vertex) StringValue() (string, error)

func (*Vertex) TimeValue

func (v *Vertex) TimeValue() (time.Time, error)

func (*Vertex) UIntValue

func (v *Vertex) UIntValue() (uint, error)

UIntValue returns the underlying unsigned integer value. It also accepts signed variants and reports ErrOverflow when the value is negative.

type VertexInput added in v0.5.0

type VertexInput struct {
	Key        string
	Value      any
	Expiration time.Time
}

VertexInput describes one vertex for the batch PutVertices API.

type VertexKind added in v0.5.0

type VertexKind int

VertexKind identifies which oneof variant is set on a Vertex. Use Vertex.Kind to dispatch without writing a switch over Value.(type).

const (
	VertexKindUnset VertexKind = iota
	VertexKindFloat32
	VertexKindFloat64
	VertexKindInt32
	VertexKindInt64
	VertexKindUint32
	VertexKindUint64
	VertexKindBool
	VertexKindString
	VertexKindBytes
	VertexKindTimestamp
	VertexKindNil
	VertexKindDuration
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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