Documentation
¶
Index ¶
- Constants
- Variables
- type Edge
- type EdgeInput
- type EdgeRef
- type Lantern
- func (l *Lantern) AddEdge(ctx context.Context, tail string, head string, weight float32, ...) error
- func (l *Lantern) AddEdgeAt(ctx context.Context, tail string, head string, weight float32, ...) error
- func (l *Lantern) AddEdges(ctx context.Context, inputs []EdgeInput) error
- func (l *Lantern) Close() error
- func (l *Lantern) DeleteEdge(ctx context.Context, tail string, head string) error
- func (l *Lantern) DeleteEdges(ctx context.Context, refs []EdgeRef) error
- func (l *Lantern) DeleteVertex(ctx context.Context, key string) error
- func (l *Lantern) DeleteVertices(ctx context.Context, keys []string) error
- func (l *Lantern) GetEdge(ctx context.Context, tail string, head string) (*Edge, error)
- func (l *Lantern) GetVertex(ctx context.Context, key string) (*Vertex, error)
- func (l *Lantern) Illuminate(ctx context.Context, seed string, step uint32, k uint32, tfidf bool) (*model.Graph[string, *Vertex], error)
- func (l *Lantern) IlluminateWithOptimization(ctx context.Context, seed string, step uint32, k uint32, tfidf bool, ...) (*model.Graph[string, *Vertex], error)
- func (l *Lantern) PutEdge(ctx context.Context, tail string, head string, weight float32, ...) error
- func (l *Lantern) PutEdgeAt(ctx context.Context, tail string, head string, weight float32, ...) error
- func (l *Lantern) PutEdges(ctx context.Context, inputs []EdgeInput) error
- func (l *Lantern) PutVertex(ctx context.Context, key string, value any, ttl time.Duration) error
- func (l *Lantern) PutVertexAt(ctx context.Context, key string, value any, expiration time.Time) error
- func (l *Lantern) PutVertices(ctx context.Context, inputs []VertexInput) error
- type Optimization
- type Option
- func WithBatchChunkSize(n int) Option
- func WithCompression(name string) Option
- func WithDefaultServiceConfig(json string) Option
- func WithDefaultTimeout(d time.Duration) Option
- func WithDialOption(opts ...grpc.DialOption) Option
- func WithTransportCredentials(creds credentials.TransportCredentials) Option
- type Vertex
- func (v *Vertex) BoolValue() (bool, error)
- func (v *Vertex) BytesValue() ([]byte, error)
- func (v *Vertex) DurationValue() (time.Duration, error)
- func (v *Vertex) ExpirationTime() time.Time
- func (v *Vertex) FloatValue() (float64, error)
- func (v *Vertex) IntValue() (int, error)
- func (v *Vertex) IsNil() bool
- func (v *Vertex) Kind() VertexKind
- func (v *Vertex) MarshalJSON() ([]byte, error)
- func (v *Vertex) StringValue() (string, error)
- func (v *Vertex) TimeValue() (time.Time, error)
- func (v *Vertex) UIntValue() (uint, error)
- type VertexInput
- type VertexKind
Constants ¶
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 ¶
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.
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.
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
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
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
EdgeInput describes one edge for the batch AddEdges / PutEdges APIs.
type EdgeRef ¶ added in v0.5.0
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 ¶
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
AddEdges accumulates weight onto a batch of edges. Automatically chunked.
func (*Lantern) DeleteEdge ¶ added in v0.4.0
func (*Lantern) DeleteEdges ¶ added in v0.5.0
DeleteEdges removes a batch of edges. Automatically chunked.
func (*Lantern) DeleteVertex ¶ added in v0.4.0
func (*Lantern) DeleteVertices ¶ added in v0.5.0
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 ¶
GetEdge fetches the edge weight (and any expiration) between tail and head.
func (*Lantern) GetVertex ¶
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
PutEdges overwrites a batch of edges. Automatically chunked.
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
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
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
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
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 ¶
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) BytesValue ¶
func (*Vertex) DurationValue ¶ added in v0.5.0
func (*Vertex) ExpirationTime ¶ added in v0.5.0
ExpirationTime returns the absolute expiration carried by v, or the zero time if no expiration was set on the server response.
func (*Vertex) FloatValue ¶
FloatValue widens any numeric oneof variant to float64.
func (*Vertex) IntValue ¶
IntValue returns the underlying signed integer value. It also accepts unsigned variants and reports ErrOverflow when a Uint64 value exceeds math.MaxInt64.
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
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 ¶
type VertexInput ¶ added in v0.5.0
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 )