Xpersona
B

BrainX V5 — The First Brain for OpenClaw

CLAWHUB · Unverified

Vector memory engine with PostgreSQL + pgvector + OpenAI embeddings. Stores, searches, and injects contextual memories into LLM prompts. Includes auto-inject...

62
Rank
84
Safety
1.7k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.7K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s17e9m2a6jyf8wwa3cagk4n4s983hdj3:brainx
  1. Install using `clawhub skill install s17e9m2a6jyf8wwa3cagk4n4s983hdj3:brainx` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/mdx2025/brainx before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-mdx2025-brainx/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

155,507 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: "BrainX V5 — The First Brain for OpenClaw"
description: |
  Vector memory engine with PostgreSQL + pgvector + OpenAI embeddings.
  Stores, searches, and injects contextual memories into LLM prompts.
  Includes auto-injection hook for OpenClaw and full backup/recovery system.
metadata:
  openclaw:
    emoji: "🧠"
    requires:
      bins: ["psql"]
      env: ["DATABASE_URL", "OPENAI_API_KEY"]
    primaryEnv: "DATABASE_URL"
    hooks:
      - name: brainx-auto-inject
        event: agent:bootstrap
        description: Auto-injects relevant memories at session start
user-invocable: true
---

# BrainX V5 — The First Brain for OpenClaw

Persistent memory system using vector embeddings for contextual retrieval in AI agents.

## 37 Features

| # | Feature | Description |
|---|---------|-------------|
| 1 | ✅ **Production** | Active on 32 agent profiles with centralized shared memory (2,400+ memories) |
| 2 | 🧠 **Auto-Learning** | Learns on its own from every conversation without human intervention |
| 3 | 💾 **Persistent Memory** | Remembers across sessions — PostgreSQL + pgvector |
| 4 | 🤝 **Shared Memory** | All agents share the same knowledge pool |
| 5 | 💉 **Automatic Briefing** | Personalized context injection at each agent startup |
| 6 | 🔎 **Semantic Search** | Searches by meaning, not exact keywords |
| 7 | 🏷️ **Intelligent Classification** | Auto-typed: facts, decisions, learnings, gotchas, notes |
| 8 | 📊 **Usage-Based Prioritization** | Hot/warm/cold tiers — automatic promote/degrade based on access |
| 9 | 🤝 **Cross-Agent Learning** | Propagates important gotchas and learnings across all agents |
| 10 | 🔄 **Anti-Duplicates** | Semantic deduplication by cosine similarity with intelligent merge |
| 11 | ⚡ **Anti-Contradictions** | Detects contradictory memories and supersedes the obsolete one |
| 12 | 📋 **Session Indexing** | Searches past conversations (30-day retention) |
| 13 | 🔒 **PII Scrubbing** | Automatic redaction of sensitive data before storage |
| 14 | 🔮 **Pattern Detection** | Detects recurring patterns and promotes them automatically |
| 15 | 🛡️ **Disaster Recovery** | Full backup/restore (DB + configs + hooks + workspaces) |
| 16 | ⭐ **Quality Scoring** | Evaluates memory quality and promotes only what deserves to persist |
| 17 | ⚙️ **Fact Extraction** | Regex + LLM pipelines capture both operational facts and nuanced learnings |
| 18 | 📦 **Context Packs** | Weekly project packs and bootstrap topic files for fast situational awareness |
| 19 | 📈 **Telemetry** | Query logs, injection metrics, and health monitoring built in |
| 20 | 🧵 **Supersede Chains** | Old memories can be replaced cleanly without losing history |
| 21 | 🌀 **Memory Distillation** | Consolidates raw logs into higher-signal memories over time |
| 22 | 🛡️ **Pre-Action Advisory** | Queries past mistakes before high-risk tool execution |
| 23 | 👤 **Agent Profiles** | Per-agent hook injection: boosts/filters memories by agent role |
| 24 

README.md

# 🧠 BrainX V5 — The First Brain for OpenClaw

![BrainX Banner](assets/brainx-banner.png)

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![OpenClaw Compatible](https://img.shields.io/badge/OpenClaw-Compatible-blue.svg)](https://openclaw.ai)
[![Version](https://img.shields.io/badge/version-0.3.1-green.svg)](https://github.com/Mdx2025/brainx-v5)

BrainX V5 is a **persistent memory and vector database system** for AI agents, built on PostgreSQL + pgvector + OpenAI embeddings. It gives every OpenClaw agent the ability to remember, learn, and share knowledge across sessions — delivering true **AI agent memory**, **cross-agent learning**, and **semantic search** at production scale.

> **Production-tested · 30+ agent profiles supported · 18/18 doctor checks · Version 0.3.1**

| # | Feature | Description |
|---|---------|-------------|
| 1 | ✅ **Production** | Active with centralized shared memory across all agents |
| 2 | 🧠 **Auto-Learning** | Learns on its own from every conversation without human intervention |
| 3 | 💾 **Persistent Memory** | Remembers across sessions — PostgreSQL + pgvector vector database |
| 4 | 🤝 **Shared Memory** | All agents share the same knowledge management pool |
| 5 | 💉 **Automatic Briefing** | Personalized context injection at each agent startup |
| 6 | 🔎 **Semantic Search** | Searches by meaning, not exact keywords — pgvector cosine similarity |
| 7 | 🏷️ **Intelligent Classification** | Auto-typed: facts, decisions, learnings, gotchas, notes |
| 8 | 📊 **Usage-Based Prioritization** | Hot/warm/cold tiers — automatic promote/degrade based on access |
| 9 | 🤝 **Cross-Agent Learning** | Propagates important gotchas and learnings across all agents |
| 10 | 🔄 **Anti-Duplicates** | Semantic deduplication by cosine similarity with intelligent merge |
| 11 | ⚡ **Anti-Contradictions** | Detects contradictory memories and supersedes the obsolete one |
| 12 | 📋 **Session Indexing** | Searches past conversations (30-day retention) |
| 13 | 🔒 **PII Scrubbing** | Automatic redaction of sensitive data before storage |
| 14 | 🔮 **Pattern Detection** | Detects recurring patterns and promotes them automatically |
| 15 | 🛡️ **Disaster Recovery** | Full backup/restore (DB + configs + hooks + workspaces) |
| 16 | ⭐ **Quality Scoring** | Evaluates memory quality and promotes only what deserves to persist |
| 17 | ⚙️ **Fact Extraction** | Regex + LLM pipelines capture both operational facts and nuanced learnings |
| 18 | 📦 **Context Packs** | Weekly project packs and bootstrap topic files for fast situational awareness |
| 19 | 📈 **Telemetry** | Query logs, injection metrics, and health monitoring built in |
| 20 | 🧵 **Supersede Chains** | Old memories can be replaced cleanly without losing history |
| 21 | 🌀 **Memory Distillation** | Consolidates raw logs into higher-signal memories over time |
| 22 | 🛡️ **Pre-Action Advisory** | Queries past mistakes before high-

_meta.json

{
  "ownerId": "kn76kq57v0tk0339j89hkza6a5812f6k",
  "slug": "brainx",
  "version": "0.3.5",
  "publishedAt": 1774360741816
}

docs/ARCHITECTURE.md

# Architecture (BrainX V5)

BrainX V5 is a lightweight memory service implemented as:

- **PostgreSQL** for storage + metadata filters
- **pgvector** for vector similarity search
- **OpenAI embeddings API** to generate vectors
- A small **Node.js CLI** to write/search/inject memory into prompts

This repo is intentionally minimal: it can be embedded into larger systems (e.g. OpenClaw) without running a dedicated HTTP service.

## High-level components

### 1) CLI entrypoints

- `./brainx-v5` (bash wrapper)
  - `health` → runs `tests/smoke.js`
  - `add|search|inject` → runs `lib/cli.js`

### 2) CLI implementation

- `lib/cli.js`
  - `add`: validates input, generates an id, calls `openai-rag.storeMemory()`
  - `search`: calls `openai-rag.search()` and prints JSON
  - `inject`: calls `search()` and prints a **prompt-ready text block** with metadata headers per item

### 3) Storage + vector search

- `lib/openai-rag.js`
  - `embed(text)` → calls `POST https://api.openai.com/v1/embeddings`
  - `storeMemory(memory)` → inserts/updates `brainx_memories` (with `embedding`)
  - `search(query, opts)` → embeds query, runs SQL with pgvector distance operator, applies filters, orders by `score`

### 4) Database layer

- `lib/db.js`
  - wraps a `pg.Pool`
  - exposes `query()` and `health()`

## Execution flow

### Add

1. CLI receives `--type`, `--content`, etc.
2. `openai-rag.storeMemory()`:
   - builds an embedding input string: `"${type}: ${content} [context: ${context}]"`
   - calls OpenAI embeddings
   - upserts into `brainx_memories`

### Search

1. `openai-rag.search()` embeds the query
2. SQL ranks candidates using:
   - cosine similarity (via `1 - (embedding <=> query_embedding)`)
   - importance boost
   - tier boost/penalty
3. Results are returned (and filtered by `minSimilarity` in JS)
4. Access tracking updates `last_accessed` and increments `access_count`

### Inject

Same as search, but output is formatted for direct prompt injection:

- Each memory is printed as:

```
[sim:0.62 imp:9 tier:hot type:decision agent:coder ctx:openclaw]
<content...>
```

## Filters and ranking

### Filters

`search()` supports:

- `minImportance`
- `tierFilter` (exact tier)
- `contextFilter` (exact context)
- excludes superseded memories: `superseded_by IS NULL`

### Ranking

Current SQL uses a composite score:

- base: similarity
- plus: `(importance/10) * 0.25`
- plus: tier adjustment:
  - hot +0.15
  - warm +0.05
  - cold -0.05
  - archive -0.10

This is intentionally simple and easy to tune.

## Environment

Common env vars (see `.env.example`):

- `DATABASE_URL`
- `OPENAI_API_KEY`
- `OPENAI_EMBEDDING_MODEL`
- `OPENAI_EMBEDDING_DIMENSIONS` (must match schema vector dim)

Optional:

- `BRAINX_ENV` path to an env file to load from multiple processes
- `BRAINX_INJECT_DEFAULT_TIER` (`warm_or_hot` by default)
- `BRAINX_INJECT_MAX_CHARS_PER_ITEM`
- `BRAINX_INJECT_MAX_LINES_PER_ITEM`

## Design notes / tradeoffs

- No HTTP service by default: easier to run locally, in c

docs/CLI.md

# CLI Reference (brainx-v5)

Entry point: `./brainx-v5`

Internally it delegates to `lib/cli.js`.

## Global help

```bash
./brainx-v5 --help
```

## `health`

Runs a database smoke test:

```bash
./brainx-v5 health
```

Checks:

- DB connectivity (`select 1`)
- pgvector installed
- `brainx_*` tables exist

## `add`

Store (upsert) a memory item.

```bash
./brainx-v5 add \
  --type <type> \
  --content <text> \
  [--context <ctx>] \
  [--tier <hot|warm|cold|archive>] \
  [--importance <1-10>] \
  [--tags a,b,c] \
  [--agent <name>] \
  [--id <id>] \
  [--status <pending|in_progress|resolved|promoted|wont_fix>] \
  [--category <learning|error|feature_request|correction|knowledge_gap|best_practice>] \
  [--patternKey <key>] \
  [--recurrenceCount <n>] \
  [--firstSeen <iso>] \
  [--lastSeen <iso>] \
  [--resolvedAt <iso>] \
  [--promotedTo <target>] \
  [--resolutionNotes <text>]
```

Notes:

- If `--id` is omitted, an id like `m_<timestamp>_<rand>` is generated.
- Embedding input is built as:
  - `${type}: ${content} [context: ${context}]`
- Phase 2 store pipeline adds:
  - optional PII scrubbing before embedding/storage (`BRAINX_PII_SCRUB_ENABLED`, `BRAINX_PII_SCRUB_REPLACEMENT`)
  - semantic dedupe merge in recent same `context`/`category` (`BRAINX_DEDUPE_SIM_THRESHOLD`)
  - redaction metadata tags like `pii:redacted`, `pii:email`

## `search`

Semantic search returning JSON.

```bash
./brainx-v5 search \
  --query <text> \
  [--limit <n>] \
  [--minSimilarity <0-1>] \
  [--context <ctx>] \
  [--tier <tier>] \
  [--minImportance <n>]
```

Returned fields include:

- all table columns
- `similarity`
- `score`

## `inject`

Semantic search formatted as a prompt-ready block (plain text).

```bash
./brainx-v5 inject \
  --query <text> \
  [--limit <n>] \
  [--context <ctx>] \
  [--tier <tier>] \
  [--minImportance <n>] \
  [--minScore <n>] \
  [--maxTotalChars <n>] \
  [--maxCharsPerItem <n>] \
  [--maxLinesPerItem <n>]
```

Defaults:

- `BRAINX_INJECT_DEFAULT_TIER=warm_or_hot`
  - if you don’t pass `--tier`, inject searches hot then warm and merges unique ids.
- `BRAINX_INJECT_MIN_SCORE=0.25`
- `BRAINX_INJECT_MAX_TOTAL_CHARS=12000`

Output format:

```
[sim:0.62 imp:9 tier:hot type:decision agent:coder ctx:openclaw]
<content>

---

[sim:0.41 imp:6 tier:warm type:note agent:system ctx:emailbot]
<content>
```

## Environment variables

Required:

- `DATABASE_URL`
- `OPENAI_API_KEY`

Optional:

- `BRAINX_ENV` — load a shared env file from a specific path
- `OPENAI_EMBEDDING_MODEL`
- `OPENAI_EMBEDDING_DIMENSIONS`
- `BRAINX_INJECT_DEFAULT_TIER`
- `BRAINX_INJECT_MAX_CHARS_PER_ITEM`
- `BRAINX_INJECT_MAX_LINES_PER_ITEM`
- `BRAINX_INJECT_MAX_TOTAL_CHARS`
- `BRAINX_INJECT_MIN_SCORE`
- `BRAINX_PII_SCRUB_ENABLED` (default `true`)
- `BRAINX_PII_SCRUB_REPLACEMENT` (default `[REDACTED]`)
- `BRAINX_PII_SCRUB_ALLOWLIST_CONTEXTS` (csv; contexts que NO se redactan)
- `BRAINX_DEDUPE_SIM_THRESHOLD` (default `0.92`)
- `BRAINX_DEDUPE_RECENT_DAYS` (default `30`)
- `BRAINX

Sponsored

Ads related to BrainX V5 — The First Brain for OpenClaw and adjacent AI workflows.