protocol

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DocumentToNeuron

func DocumentToNeuron(doc map[string]any, dim int) (*core.Neuron, error)

DocumentToNeuron creates a neuron from a document (for inserts)

func MarshalResult

func MarshalResult(r *Result) ([]byte, error)

MarshalResult serializes a result

func NeuronToDocument

func NeuronToDocument(n *core.Neuron, projection map[string]int) map[string]any

NeuronToDocument converts a neuron to a document map

Types

type Command

type Command struct {
	Type       CommandType    `json:"type"`
	Collection string         `json:"collection"`
	Document   map[string]any `json:"document,omitempty"`
	Filter     map[string]any `json:"filter,omitempty"`
	Update     map[string]any `json:"update,omitempty"`
	Pipeline   []any          `json:"pipeline,omitempty"`
	Options    CommandOptions `json:"options,omitempty"`
}

Command represents a database command

func ParseCommand

func ParseCommand(data []byte) (*Command, error)

ParseCommand parses a JSON command string

type CommandHandler

type CommandHandler func(worker *concurrency.BrainWorker, cmd *Command) *Result

CommandHandler is a function that handles a specific command type. Implementations receive the worker and parsed command, returning a result.

type CommandOptions

type CommandOptions struct {
	Limit      int            `json:"limit,omitempty"`
	Skip       int            `json:"skip,omitempty"`
	Sort       map[string]int `json:"sort,omitempty"`
	Projection map[string]int `json:"projection,omitempty"`
	Depth      int            `json:"depth,omitempty"` // For search spread
	Upsert     bool           `json:"upsert,omitempty"`
}

CommandOptions for queries

type CommandType

type CommandType string

Command types

const (
	CmdInsert    CommandType = "insert"
	CmdFind      CommandType = "find"
	CmdFindOne   CommandType = "findOne"
	CmdUpdate    CommandType = "update"
	CmdUpdateOne CommandType = "updateOne"
	CmdDelete    CommandType = "delete"
	CmdDeleteOne CommandType = "deleteOne"
	CmdAggregate CommandType = "aggregate"
	CmdCount     CommandType = "count"
	CmdActivate  CommandType = "activate" // Fire a neuron
	CmdSearch    CommandType = "search"   // Semantic-like search with spread
	CmdStats     CommandType = "stats"
)

type Executor

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

Executor executes commands against a brain worker using a pluggable command registry. Handlers are looked up by CommandType at dispatch time, so new command types can be registered without modifying Execute.

func NewExecutor

func NewExecutor() *Executor

NewExecutor creates a new command executor with the built-in command set.

func (*Executor) Execute

func (e *Executor) Execute(worker *concurrency.BrainWorker, cmd *Command) *Result

Execute dispatches a command to the appropriate registered handler.

func (*Executor) ListCommands

func (e *Executor) ListCommands() []CommandType

ListCommands returns all registered command types.

func (*Executor) Register

func (e *Executor) Register(ct CommandType, h CommandHandler)

Register adds or replaces a handler for the given command type.

func (*Executor) Unregister

func (e *Executor) Unregister(ct CommandType)

Unregister removes a handler for the given command type.

type FilterMatcher

type FilterMatcher struct{}

FilterMatcher evaluates filters against neurons

func NewFilterMatcher

func NewFilterMatcher() *FilterMatcher

NewFilterMatcher creates a new filter matcher

func (*FilterMatcher) MatchNeuron

func (fm *FilterMatcher) MatchNeuron(n *core.Neuron, filter map[string]any) bool

MatchNeuron checks if a neuron matches the filter

type Query

type Query struct {
	Collection string         `json:"collection"` // "neurons" or "synapses"
	Filter     map[string]any `json:"filter"`
	Projection map[string]int `json:"projection,omitempty"`
	Sort       map[string]int `json:"sort,omitempty"`
	Limit      int            `json:"limit,omitempty"`
	Skip       int            `json:"skip,omitempty"`
}

Query represents a MongoDB-like query

type Result

type Result struct {
	Success     bool   `json:"success"`
	Data        any    `json:"data,omitempty"`
	Count       int    `json:"count,omitempty"`
	InsertedID  string `json:"insertedId,omitempty"`
	ModifiedCnt int    `json:"modifiedCount,omitempty"`
	DeletedCnt  int    `json:"deletedCount,omitempty"`
	Error       string `json:"error,omitempty"`
}

Result represents a command result

Jump to

Keyboard shortcuts

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