concurrency

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddNeuronRequest

type AddNeuronRequest struct {
	Content  string
	ParentID *core.NeuronID
	Metadata map[string]string
}

Request types

type BrainWorker

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

BrainWorker is a dedicated goroutine per user brain

func NewBrainWorker

func NewBrainWorker(indexID core.IndexID, matrix *core.Matrix) *BrainWorker

NewBrainWorker creates a new worker for a user

func (*BrainWorker) Matrix

func (w *BrainWorker) Matrix() *core.Matrix

Matrix returns the underlying matrix

func (*BrainWorker) SetSentimentAnalyzer

func (w *BrainWorker) SetSentimentAnalyzer(a *sentiment.Analyzer)

SetSentimentAnalyzer attaches a sentiment analyzer to the underlying engine for auto-labeling on write and sentiment-aware scoring on search.

func (*BrainWorker) SetVectorizer

func (w *BrainWorker) SetVectorizer(v *vector.Vectorizer, alpha float64, queryRepeat int)

SetVectorizer attaches a vectorizer to the underlying engine for auto-embedding on write and hybrid scoring on search.

func (*BrainWorker) Stats

func (w *BrainWorker) Stats() map[string]any

Stats returns worker stats

func (*BrainWorker) Stop

func (w *BrainWorker) Stop()

Stop gracefully stops the worker

func (*BrainWorker) Submit

func (w *BrainWorker) Submit(op *Operation) (any, error)

Submit queues an operation and waits for result

func (*BrainWorker) SubmitAsync

func (w *BrainWorker) SubmitAsync(op *Operation)

SubmitAsync queues an operation without waiting

type ListNeuronsRequest

type ListNeuronsRequest struct {
	Offset      int
	Limit       int
	DepthFilter *int
}

type OpType

type OpType int

Operation types for the worker

const (
	// Brain-like naming (primary)
	OpWrite       OpType = iota // Add/create neuron (memory formation)
	OpRead                      // Get neuron (memory retrieval)
	OpSearch                    // Search neurons (associative recall)
	OpTouch                     // Update neuron (memory modification)
	OpForget                    // Delete neuron (memory erasure)
	OpRecall                    // List neurons (memory scanning)
	OpFire                      // Activate neuron (neural firing)
	OpDecay                     // Energy decay (forgetting curve)
	OpConsolidate               // Memory consolidation (depth increase)
	OpPrune                     // Remove dead neurons (synaptic pruning)
	OpReorg                     // Reorganize matrix (neural plasticity)
	OpGetStats                  // Get statistics
	OpShutdown                  // Shutdown worker
)

type Operation

type Operation struct {
	Type    OpType
	Payload any
	Result  chan any
	Error   chan error
}

Operation represents a queued operation

type SearchRequest

type SearchRequest struct {
	Query    string
	Depth    int
	Limit    int
	Metadata map[string]string
	Strict   bool
}

type UpdateNeuronRequest

type UpdateNeuronRequest struct {
	ID      core.NeuronID
	Content string
}

type WorkerPool

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

WorkerPool manages all brain workers with isolation

func NewWorkerPool

func NewWorkerPool(store *persistence.Store, bounds core.MatrixBounds) *WorkerPool

NewWorkerPool creates a new worker pool

func (*WorkerPool) ActiveCount

func (p *WorkerPool) ActiveCount() int

ActiveCount returns number of active workers

func (*WorkerPool) Evict

func (p *WorkerPool) Evict(indexID core.IndexID) error

Evict removes a worker and persists its state

func (*WorkerPool) ForEach

func (p *WorkerPool) ForEach(fn func(core.IndexID, *BrainWorker))

ForEach executes a function on each worker

func (*WorkerPool) Get

func (p *WorkerPool) Get(indexID core.IndexID) (*BrainWorker, error)

Get returns existing worker or nil

func (*WorkerPool) GetOrCreate

func (p *WorkerPool) GetOrCreate(indexID core.IndexID) (*BrainWorker, error)

GetOrCreate returns existing worker or creates new one

func (*WorkerPool) ListIndexes

func (p *WorkerPool) ListIndexes() []string

ListIndexes returns all active index IDs

func (*WorkerPool) PersistAll

func (p *WorkerPool) PersistAll() error

PersistAll persists all active workers

func (*WorkerPool) SetMaxIdleTime

func (p *WorkerPool) SetMaxIdleTime(d time.Duration)

SetMaxIdleTime updates the idle eviction threshold at runtime.

func (*WorkerPool) SetMaxNeurons

func (p *WorkerPool) SetMaxNeurons(max int)

SetMaxNeurons updates matrix capacity bounds for active and future indexes.

func (*WorkerPool) SetSentimentAnalyzer

func (p *WorkerPool) SetSentimentAnalyzer(a *sentiment.Analyzer)

SetSentimentAnalyzer attaches a global sentiment analyzer to the pool. All existing and future workers will use it.

func (*WorkerPool) SetVectorAlpha

func (p *WorkerPool) SetVectorAlpha(alpha float64)

SetVectorAlpha updates the vector alpha used by existing and future workers.

func (*WorkerPool) SetVectorizer

func (p *WorkerPool) SetVectorizer(v *vector.Vectorizer, alpha float64)

SetVectorizer attaches a global vectorizer to the pool. All existing and future workers will use it.

func (*WorkerPool) SetVectorizerWithRepeat

func (p *WorkerPool) SetVectorizerWithRepeat(v *vector.Vectorizer, alpha float64, queryRepeat int)

SetVectorizerWithRepeat attaches a global vectorizer with explicit query repeat count.

func (*WorkerPool) Shutdown

func (p *WorkerPool) Shutdown() error

Shutdown gracefully shuts down all workers

func (*WorkerPool) Stats

func (p *WorkerPool) Stats() map[string]any

Stats returns pool statistics

func (*WorkerPool) Truncate

func (p *WorkerPool) Truncate(indexID core.IndexID) error

Truncate removes an index from memory and disk without persisting the in-memory state first.

Jump to

Keyboard shortcuts

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