Cortex

Fabriq Brain

Plug fabriq in as a living brain for cortex agents — recall, rich tools, and a learning loop.

Overview

fabriqbrain (github.com/xraph/cortex/integrations/fabriq) adapts the fabriq data fabric to cortex as a plug-n-play brain. With one wiring call your agents gain fabriq-backed:

  • Recall — multi-channel retrieval (vector + full-text + graph, RRF-fused, distillation-aware) via the engine's knowledge_search tool.
  • Rich toolsgraph_traverse, guarded remember, and the distillation tools map/digest/resolve, registered as native cortex tools.
  • Learning loop — a plugin that writes each run back into the fabric, where fabriq's embed + distillation workers turn it into future recall material.

Wiring

import (
	"github.com/xraph/cortex/engine"
	fabriqbrain "github.com/xraph/cortex/integrations/fabriq"
	"github.com/xraph/fabriq/core/agent"
	"github.com/xraph/fabriq/core/command"
)

eng, err := engine.New(append(
	[]engine.Option{engine.WithStore(store), engine.WithLLM(client)},
	fabriqbrain.EngineOptions(container,
		fabriqbrain.WithEmbedder(emb),
		fabriqbrain.WithEntities("doc", "note", "agent_memory"),
		fabriqbrain.WithWritePolicy(agent.WritePolicy{
			Allow: map[string][]command.Op{"agent_memory": {command.OpCreate}},
		}),
	)...,
)...)

EngineOptions auto-discovers the *fabriq.Fabriq facade from the DI container (provided by fabriq's Forge extension). If no facade is present it returns nil, so the call is always safe to include. Use EngineOption (singular) to wire only the knowledge provider, mirroring the weave adapter.

Options

OptionPurpose
WithEmbedder(agent.Embedder)Embedding model for recall's vector channel. Must match the embedder fabriq indexed with.
WithEntities(...string)Entity types recall searches and ListCollections reports.
WithBudget(int)Token budget per recall (default 4096).
WithMemoryEntity(string)Entity the learning loop writes to (default agent_memory).
WithWritePolicy(agent.WritePolicy)Allowlist for the remember tool and learning-loop writes (deny-by-default).
WithTenantMapper(func(ctx) ctx)Translate cortex request context to fabriq scope (default identity).
WithRenderer(func(agent.ContextItem) string)Override how a recalled row becomes chunk text.

Learning loop setup

To turn run activity into recall material, use the turnkey helpers in your setup:

import fabriqbrain "github.com/xraph/cortex/integrations/fabriq"

// 1. Register the memory entity (dynamic, content vector-indexed).
reg.MustRegister(fabriqbrain.MemorySpec("agent_memory"))

// 2. Provision its table once (migration, or postgres.Adapter.EnsureDynamic
//    in setup) — fabriq.Open does not auto-create dynamic tables.

// 3. Allow writes to it. Pass WithMemoryEntity explicitly — it must match the
//    name used in MemorySpec above. Hosts using a non-default entity name MUST
//    pass WithMemoryEntity; the default is "agent_memory".
opts := fabriqbrain.EngineOptions(container,
	fabriqbrain.WithEmbedder(emb),
	fabriqbrain.WithEntities("agent_memory"),
	fabriqbrain.WithMemoryEntity("agent_memory"),
	fabriqbrain.WithWritePolicy(fabriqbrain.MemoryWritePolicy("agent_memory")),
)

The plugin writes {content, meta} rows to the registered entity; fabriq's proj:embed worker vectorizes content, and distillation rolls them up so future recall surfaces them. As the memory corpus grows, distillation keeps recall within budget by summarizing historical context.

On this page