Documentation
¶
Overview ¶
Package cortext is a pure-Go (no CGO) binding for the Cortext multimodal memory engine. Shared libraries and model shards come from the augmem/cortext.cpp GitHub Release asset tarball (see EnsureAssets), or from CORTEXT_LIBRARY_PATH / CORTEXT_ASSETS_DIR when set explicitly.
Index ¶
- Constants
- func AssetsDir() string
- func EnsureAssets() (string, error)
- func LastError() string
- func LibraryPath() string
- func LoadLibrary() error
- func MaterializeModel(dbPath string) (string, error)
- func Ptr[T any](value T) *T
- func ResetAssetsForTest()
- func ResetLibraryForTest()
- func Version() string
- type Config
- type EmbeddingResult
- type Handle
- func (h *Handle) Close()
- func (h *Handle) Consolidate() (map[string]any, error)
- func (h *Handle) ConsolidateJSON() ([]byte, error)
- func (h *Handle) EmbedAudio(pcm []float32) ([]float32, error)
- func (h *Handle) EmbedAudioJSON(pcm []float32) ([]byte, error)
- func (h *Handle) EmbedImage(data []byte, width int, height int, channels int) ([]float32, error)
- func (h *Handle) EmbedImageJSON(data []byte, width int, height int, channels int) ([]byte, error)
- func (h *Handle) EmbedText(text string) ([]float32, error)
- func (h *Handle) EmbedTextJSON(text string) ([]byte, error)
- func (h *Handle) Flush() error
- func (h *Handle) ProcessAudio(pcm []float32, sourceID string) (map[string]any, error)
- func (h *Handle) ProcessAudioJSON(pcm []float32, sourceID string) ([]byte, error)
- func (h *Handle) ProcessAudioJSONWithOptions(pcm []float32, sourceID string, options *ProcessOptions) ([]byte, error)
- func (h *Handle) ProcessAudioWithMedia(pcm []float32, sourceID string, media *Media) (map[string]any, error)
- func (h *Handle) ProcessAudioWithMediaAndOptions(pcm []float32, sourceID string, media *Media, options *ProcessOptions) (map[string]any, error)
- func (h *Handle) ProcessAudioWithMediaJSON(pcm []float32, sourceID string, media *Media) ([]byte, error)
- func (h *Handle) ProcessAudioWithMediaJSONWithOptions(pcm []float32, sourceID string, media *Media, options *ProcessOptions) ([]byte, error)
- func (h *Handle) ProcessAudioWithOptions(pcm []float32, sourceID string, options *ProcessOptions) (map[string]any, error)
- func (h *Handle) ProcessImage(data []byte, width int, height int, channels int, sourceID string) (map[string]any, error)
- func (h *Handle) ProcessImageJSON(data []byte, width int, height int, channels int, sourceID string) ([]byte, error)
- func (h *Handle) ProcessImageJSONWithOptions(data []byte, width int, height int, channels int, sourceID string, ...) ([]byte, error)
- func (h *Handle) ProcessImageWithMedia(data []byte, width int, height int, channels int, sourceID string, ...) (map[string]any, error)
- func (h *Handle) ProcessImageWithMediaAndOptions(data []byte, width int, height int, channels int, sourceID string, ...) (map[string]any, error)
- func (h *Handle) ProcessImageWithMediaJSON(data []byte, width int, height int, channels int, sourceID string, ...) ([]byte, error)
- func (h *Handle) ProcessImageWithMediaJSONWithOptions(data []byte, width int, height int, channels int, sourceID string, ...) ([]byte, error)
- func (h *Handle) ProcessImageWithOptions(data []byte, width int, height int, channels int, sourceID string, ...) (map[string]any, error)
- func (h *Handle) ProcessText(text string, sourceID string) (map[string]any, error)
- func (h *Handle) ProcessTextJSON(text string, sourceID string) ([]byte, error)
- func (h *Handle) ProcessTextJSONWithOptions(text string, sourceID string, options *ProcessOptions) ([]byte, error)
- func (h *Handle) ProcessTextWithMedia(text string, sourceID string, media *Media) (map[string]any, error)
- func (h *Handle) ProcessTextWithMediaAndOptions(text string, sourceID string, media *Media, options *ProcessOptions) (map[string]any, error)
- func (h *Handle) ProcessTextWithMediaJSON(text string, sourceID string, media *Media) ([]byte, error)
- func (h *Handle) ProcessTextWithMediaJSONWithOptions(text string, sourceID string, media *Media, options *ProcessOptions) ([]byte, error)
- func (h *Handle) ProcessTextWithOptions(text string, sourceID string, options *ProcessOptions) (map[string]any, error)
- func (h *Handle) Reset() error
- type Media
- type ProcessOptions
- type Retention
Constants ¶
const AssetsVersion = "2.0.0"
AssetsVersion is the augmem/cortext.cpp release that provides shared natives and model shards (cortext-assets-<version>.tar.gz). Override with CORTEXT_ASSETS_VERSION.
const ModuleVersion = "2.0.0"
ModuleVersion is this Go module's release line. It is independent of the bundled engine AssetsVersion but usually tracks the same minor line.
Variables ¶
This section is empty.
Functions ¶
func AssetsDir ¶
func AssetsDir() string
AssetsDir returns the last EnsureAssets root, or empty if not yet loaded.
func EnsureAssets ¶
EnsureAssets downloads (if needed) and unpacks the shared Cortext release asset tarball from github.com/augmem/cortext.cpp, then returns the root that contains native/ and models/.
Layout after unpack:
native/<platform-tag>/libcortext.* models/manifest.json models/AIST-87M-GGUF/chunks/… models/mdbr-leaf-ir/vocab.txt
Resolution order for the asset root:
- CORTEXT_ASSETS_DIR (pre-unpacked tree)
- User/cache dir for AssetsVersion (download once, reuse)
Override the release with CORTEXT_ASSETS_VERSION or the full archive URL with CORTEXT_ASSETS_URL. Checksum is verified from the release .sha256 asset unless CORTEXT_ASSETS_SHA256 is set.
func LastError ¶
func LastError() string
LastError returns the last error produced by this OS thread's C API calls. Note: goroutine migration between calls can lose thread-local error text; prefer the error returned from each method when available.
func LibraryPath ¶
func LibraryPath() string
LibraryPath returns the absolute path that was successfully loaded, if any.
func LoadLibrary ¶
func LoadLibrary() error
LoadLibrary loads the native Cortext shared library if it is not already loaded. New and Version call this automatically. This may download release assets.
func MaterializeModel ¶
MaterializeModel reassembles AIST model chunks from the release asset tree into a local cache and returns the full .gguf path. When the manifest declares the late-interaction reranker (AIST-87M-LI.gguf, required by v5 engines), it is checksummed and placed beside the AIST file, where the engine looks for it unless CORTEXT_LI_MODEL_PATH is set.
Release natives embed AIST and assemble it inside the library on first create. Call MaterializeModel only when an external filesystem GGUF is required.
Chunks always come from EnsureAssets() (augmem/cortext.cpp release tarball).
Cache location (first match wins):
- CORTEXT_MODEL_CACHE_DIR
- sibling of dbPath: <dir(dbPath)>/.cortext-assets (":memory:" → cwd)
- user cache under augmem/cortext/models
func ResetAssetsForTest ¶
func ResetAssetsForTest()
ResetAssetsForTest clears the process-wide assets singleton (tests only).
func ResetLibraryForTest ¶
func ResetLibraryForTest()
ResetLibraryForTest clears the process-wide library singleton (tests only).
Types ¶
type Config ¶
type Config struct {
Focus *float64
Sensitivity *float64
Stability *float64
AffectInterrupt *bool
AffectRetrieval *bool
ReinforcementEnabled *bool
SequentialEdgesEnabled *bool
SignalFilterAudio *bool
SignalFilterImage *bool
SignalFilterText *bool
}
Config overrides native defaults. Nil fields retain their native defaults.
type EmbeddingResult ¶
type EmbeddingResult struct {
Embedding []float32 `json:"embedding"`
Dimension int `json:"dimension"`
}
EmbeddingResult is the JSON shape returned by embed helpers.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is an open Cortext engine instance.
func New ¶
New opens a Cortext instance at dbPath (file path or ":memory:"). cfg may be nil for all native defaults.
The native library is loaded via EnsureAssets (augmem/cortext.cpp release tarball). Release natives embed AIST and assemble it on first create. Set CORTEXT_AIST_MODEL_PATH only to force a specific external GGUF file. Engines from v5 on also require the late-interaction reranker (AIST-87M-LI.gguf) whenever AIST resolves: it is found through CORTEXT_LI_MODEL_PATH, beside the AIST file, or linked into the library, and New fails if none resolves.
func (*Handle) Close ¶
func (h *Handle) Close()
Close frees the native handle. Safe to call multiple times.
func (*Handle) ConsolidateJSON ¶
func (*Handle) EmbedImage ¶
func (*Handle) EmbedImageJSON ¶
func (*Handle) ProcessAudio ¶
func (*Handle) ProcessAudioJSON ¶
func (*Handle) ProcessAudioJSONWithOptions ¶
func (*Handle) ProcessAudioWithMedia ¶
func (*Handle) ProcessAudioWithMediaAndOptions ¶
func (*Handle) ProcessAudioWithMediaJSON ¶
func (*Handle) ProcessAudioWithMediaJSONWithOptions ¶
func (*Handle) ProcessAudioWithOptions ¶
func (*Handle) ProcessImage ¶
func (*Handle) ProcessImageJSON ¶
func (*Handle) ProcessImageJSONWithOptions ¶
func (*Handle) ProcessImageWithMedia ¶
func (*Handle) ProcessImageWithMediaAndOptions ¶
func (*Handle) ProcessImageWithMediaJSON ¶
func (*Handle) ProcessImageWithMediaJSONWithOptions ¶
func (*Handle) ProcessImageWithOptions ¶
func (*Handle) ProcessText ¶
func (*Handle) ProcessTextJSON ¶
func (*Handle) ProcessTextJSONWithOptions ¶
func (*Handle) ProcessTextWithMedia ¶
func (h *Handle) ProcessTextWithMedia(text string, sourceID string, media *Media) (map[string]any, error)
ProcessTextWithMedia is ProcessTextWithMediaJSON decoded into a map.
func (*Handle) ProcessTextWithMediaAndOptions ¶
func (h *Handle) ProcessTextWithMediaAndOptions(text string, sourceID string, media *Media, options *ProcessOptions) (map[string]any, error)
ProcessTextWithMediaAndOptions is ProcessTextWithMediaJSONWithOptions decoded into a map.
func (*Handle) ProcessTextWithMediaJSON ¶
func (h *Handle) ProcessTextWithMediaJSON(text string, sourceID string, media *Media) ([]byte, error)
ProcessTextWithMediaJSON processes text and stores media (see Media) as the signal's payload in place of the text. Nil or empty media stores the text.
func (*Handle) ProcessTextWithMediaJSONWithOptions ¶
func (h *Handle) ProcessTextWithMediaJSONWithOptions(text string, sourceID string, media *Media, options *ProcessOptions) ([]byte, error)
ProcessTextWithMediaJSONWithOptions is ProcessTextWithMediaJSON with ProcessOptions (embedding, retention, evidence budget, reference time).
func (*Handle) ProcessTextWithOptions ¶
type Media ¶
Media is caller source media stored as the signal's payload in place of the canonical input (text, PCM or pixels), which is still what the signal is encoded from. Nil or empty Data stores the canonical input. MimeType is required with Data; a text/* payload is used as text (keyword index, standing memories, packet text), any other MIME type is opaque.
type ProcessOptions ¶
type ProcessOptions struct {
OmitEmbedding bool
// Retention is Natural when zero-value / omitted.
Retention Retention
// EvidenceBudgetBytes is the evidence budget for the returned packet, in
// bytes. Zero (omitted) returns recalled memories whole. A positive value
// fits standing_memory plus retrieved_memory (with attached neighbours)
// within it, text counted by its UTF-8 bytes and other payloads as 480
// bytes each; grouped memories keep their members most similar to the
// query, and more distinct memories are kept trimmed before lower-ranked
// ones are left out. Convert a token budget with the reader's tokenizer
// rate (8,000 tokens at 4.35 chars/token is 34,800).
EvidenceBudgetBytes uint64
// ReferenceTime is the query reference time, read only by
// RetentionEphemeral calls. The zero value leaves retrieval unchanged. Set,
// the long-term memories nearest that time (past or future) join the
// retrieval candidates; nothing is dropped for being later unless AsOf is
// set. It is sent at millisecond precision and must not precede the Unix
// epoch.
ReferenceTime time.Time
// AsOf additionally hides memories that start after ReferenceTime (and
// later turns or restatements attached to retrieved ones). It requires a
// non-zero ReferenceTime.
AsOf bool
}
ProcessOptions configures JSON process result payloads.