# Associative Memory

Every registered associative memory instance operation, with source-derived inputs, outputs, access policy, and errors.

Source: https://docs.minds.sh/docs/api/instance/associative-memory



This reference covers **11 HTTP operations** registered by the Akasha daemon. Call these paths on your instance base URL. See [authentication](/docs/api/instance/authentication), [errors](/docs/api/instance/errors), and [coverage](/docs/api/instance/coverage) before integrating.

| Method | Path                               | Operation                                                       |
| ------ | ---------------------------------- | --------------------------------------------------------------- |
| `POST` | `/v1/assoc/mhn/new`                | [Mhn new](#post-v1-assoc-mhn-new)                               |
| `POST` | `/v1/assoc/mhn/store`              | [Mhn store](#post-v1-assoc-mhn-store)                           |
| `POST` | `/v1/assoc/mhn/retrieve`           | [Mhn retrieve](#post-v1-assoc-mhn-retrieve)                     |
| `POST` | `/v1/assoc/mhn/retrieve_by_vector` | [Mhn retrieve by vector](#post-v1-assoc-mhn-retrieve-by-vector) |
| `POST` | `/v1/assoc/mhn/retrieve_by_key`    | [Mhn retrieve by key](#post-v1-assoc-mhn-retrieve-by-key)       |
| `POST` | `/v1/assoc/mhn/clear`              | [Mhn clear](#post-v1-assoc-mhn-clear)                           |
| `POST` | `/v1/assoc/mhn/stats`              | [Mhn stats](#post-v1-assoc-mhn-stats)                           |
| `POST` | `/v1/assoc/mhn/config`             | [Mhn config](#post-v1-assoc-mhn-config)                         |
| `POST` | `/v1/assoc/mhn/system_info`        | [Mhn system info](#post-v1-assoc-mhn-system-info)               |
| `GET`  | `/v1/mhn/health`                   | [Mhn health](#get-v1-mhn-health)                                |
| `POST` | `/v1/assoc/mhn/list`               | [Mhn list](#post-v1-assoc-mhn-list)                             |

<a id="post-v1-assoc-mhn-new" />

## POST `/v1/assoc/mhn/new` [#post-v1assocmhnnew]

Mhn new

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped( CoreAction::Write, "mhn:write", request\_authority::MEMORY\_MHN, ); require\_scoped( CoreAction::Admin, "mhn:admin", request\_authority::MEMORY\_MHN, ); require\_matching\_db(\&db).

### Request [#request]

**Json** — `MhnNewReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| `dimensions`                      | `usize`                 | Yes                                        |                  |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnNewReq {
    dimensions: usize,
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "ok": true,
        "dims": req.dimensions,
        "namespace": hex::encode(ns_id.0)
    })
```

### Errors and validation [#errors-and-validation]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_new(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnNewReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(
            CoreAction::Write,
            "mhn:write",
            request_authority::MEMORY_MHN,
        )?;
        authority.require_scoped(
            CoreAction::Admin,
            "mhn:admin",
            request_authority::MEMORY_MHN,
        )?;
        authority.require_matching_db(&db)?;
        let ns_id = authority.namespace();
        let registry = require_service!(state.mhn_registry(), "MHN");
        let entry = registry
            .get_or_init(ns_id, db.clone(), Some(req.dimensions))
            .await?;
        require_service!(state.mhn_metrics(), "MHN")
            .namespace_loads
            .inc();
        if let Some(service) = state.inference_service.as_ref() {
            upsert_mhn_model(service, ns_id, &entry.network_id, entry.dimensions);
        }
        Ok(Json(serde_json::json!({
            "ok": true,
            "dims": req.dimensions,
            "namespace": hex::encode(ns_id.0)
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:7924`. Registration: `akasha-daemon/src/main.rs:4708`.

<a id="post-v1-assoc-mhn-store" />

## POST `/v1/assoc/mhn/store` [#post-v1assocmhnstore]

Mhn store

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped( CoreAction::Write, "mhn:write", request\_authority::MEMORY\_MHN, ); require\_matching\_db(\&db).

### Request [#request-1]

**Json** — `MhnStoreReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| `id`                              | `String`                | Yes                                        |                  |
| `vector`                          | `Vec<f32>`              | Yes                                        |                  |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnStoreReq {
    id: String,
    vector: Vec<f32>,
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-1]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"id": id.to_string()})
```

### Errors and validation [#errors-and-validation-1]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_store(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnStoreReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(
            CoreAction::Write,
            "mhn:write",
            request_authority::MEMORY_MHN,
        )?;
        authority.require_matching_db(&db)?;
        let start = std::time::Instant::now();
        let id = uuid::Uuid::parse_str(&req.id)
            .map_err(|_| DaemonError::InvalidRequest("invalid id".into()))?;
        let vector = Array1::from(req.vector);
        let registry = require_service!(state.mhn_registry(), "MHN");
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        let dims = vector.len();
        let entry = registry
            .get_or_init(authority.namespace(), db, Some(dims))
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;
        entry
            .keyspace
            .store_embedding(id, vector)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        metrics.pattern_stores.inc();
        metrics.store_latency.observe(start.elapsed().as_secs_f64());
        Ok(Json(serde_json::json!({"id": id.to_string()})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:7968`. Registration: `akasha-daemon/src/main.rs:4709`.

<a id="post-v1-assoc-mhn-retrieve" />

## POST `/v1/assoc/mhn/retrieve` [#post-v1assocmhnretrieve]

Mhn retrieve

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-2]

**Json** — `MhnRetrieveReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| `vector`                          | `Vec<f32>`              | Yes                                        |                  |
| `k`                               | `Option<usize>`         | No; optional or defaulted                  |                  |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnRetrieveReq {
    vector: Vec<f32>,
    k: Option<usize>,
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-2]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
                "id": best_id.to_string(),
                "embedding": embedding.to_vec(),
                "score": best_score,
            })
```

```rust
serde_json::json!({
        "id": id.to_string(),
        "embedding": emb.to_vec(),
    })
```

### Errors and validation [#errors-and-validation-2]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_retrieve(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnRetrieveReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let start = std::time::Instant::now();
        let pattern = Array1::from(req.vector);
        let registry = require_service!(state.mhn_registry(), "MHN");
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        let entry = registry
            .get_or_init(authority.namespace(), db, Some(pattern.len()))
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;

        if let Some(k) = req.k {
            let neighbors = entry
                .keyspace
                .search_nearest(&pattern, k)
                .await
                .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
            if let Some((best_id, best_score)) = neighbors.first() {
                let embedding = entry
                    .keyspace
                    .get_embedding(best_id)
                    .await
                    .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
                metrics.pattern_recalls.inc();
                metrics
                    .recall_latency
                    .observe(start.elapsed().as_secs_f64());
                return Ok(Json(serde_json::json!({
                    "id": best_id.to_string(),
                    "embedding": embedding.to_vec(),
                    "score": best_score,
                })));
            }
            // Exercise error variants via debug trace
            let _ = (
                MhnError::NetworkNotFound("no_neighbors".into()),
                MhnError::InvalidDimensions("no_neighbors".into()),
                MhnError::Storage("no_neighbors".into()),
                MhnError::Internal("no_neighbors".into()),
            );
            return Err(DaemonError::InvalidRequest("no neighbors found".into()));
        }

        let (id, emb) = entry
            .keyspace
            .retrieve_associated(&pattern)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        metrics.pattern_recalls.inc();
        metrics
            .recall_latency
            .observe(start.elapsed().as_secs_f64());
        Ok(Json(serde_json::json!({
            "id": id.to_string(),
            "embedding": emb.to_vec(),
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8013`. Registration: `akasha-daemon/src/main.rs:4710`.

<a id="post-v1-assoc-mhn-retrieve-by-vector" />

## POST `/v1/assoc/mhn/retrieve_by_vector` [#post-v1assocmhnretrieve_by_vector]

Mhn retrieve by vector

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-3]

**Json** — `MhnRetrieveVectorReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| `vector`                          | `Vec<f32>`              | Yes                                        |                  |
| `k`                               | `Option<usize>`         | No; optional or defaulted                  |                  |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnRetrieveVectorReq {
    vector: Vec<f32>,
    k: Option<usize>,
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-3]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"neighbors": rows})
```

### Errors and validation [#errors-and-validation-3]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_retrieve_by_vector(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnRetrieveVectorReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let pattern = Array1::from(req.vector);
        let k = req.k.unwrap_or(1);
        let registry = require_service!(state.mhn_registry(), "MHN");
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        let entry = registry
            .get_or_init(authority.namespace(), db, Some(pattern.len()))
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;
        let neighbors = entry
            .keyspace
            .search_nearest(&pattern, k)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        let rows: Vec<serde_json::Value> = neighbors
            .into_iter()
            .map(|(id, score)| serde_json::json!({"id": id.to_string(), "score": score}))
            .collect();
        Ok(Json(serde_json::json!({"neighbors": rows})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8160`. Registration: `akasha-daemon/src/main.rs:4711`.

<a id="post-v1-assoc-mhn-retrieve-by-key" />

## POST `/v1/assoc/mhn/retrieve_by_key` [#post-v1assocmhnretrieve_by_key]

Mhn retrieve by key

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-4]

**Json** — `MhnRetrieveKeyReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| `id`                              | `String`                | Yes                                        |                  |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnRetrieveKeyReq {
    id: String,
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-4]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"id": id.to_string(), "embedding": embedding.to_vec()}),
```

### Errors and validation [#errors-and-validation-4]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_retrieve_by_key(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnRetrieveKeyReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let id = uuid::Uuid::parse_str(&req.id)
            .map_err(|_| DaemonError::InvalidRequest("invalid id".into()))?;
        let registry = require_service!(state.mhn_registry(), "MHN");
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        let entry = registry
            .get_or_init(authority.namespace(), db, None)
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;
        let embedding = entry
            .keyspace
            .get_embedding(&id)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        Ok(Json(
            serde_json::json!({"id": id.to_string(), "embedding": embedding.to_vec()}),
        ))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8199`. Registration: `akasha-daemon/src/main.rs:4715`.

<a id="post-v1-assoc-mhn-clear" />

## POST `/v1/assoc/mhn/clear` [#post-v1assocmhnclear]

Mhn clear

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped( CoreAction::Admin, "mhn:admin", request\_authority::MEMORY\_MHN, ); require\_matching\_db(\&db).

### Request [#request-5]

**Json** — `MhnClearReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnClearReq {
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-5]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"ok": true})
```

### Errors and validation [#errors-and-validation-5]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_clear(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnClearReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(
            CoreAction::Admin,
            "mhn:admin",
            request_authority::MEMORY_MHN,
        )?;
        authority.require_matching_db(&db)?;
        let registry = require_service!(state.mhn_registry(), "MHN");
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        let entry = registry
            .get_or_init(authority.namespace(), db, None)
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;
        entry
            .keyspace
            .clear()
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        metrics.clear_operations.inc();
        Ok(Json(serde_json::json!({"ok": true})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8087`. Registration: `akasha-daemon/src/main.rs:4716`.

<a id="post-v1-assoc-mhn-stats" />

## POST `/v1/assoc/mhn/stats` [#post-v1assocmhnstats]

Mhn stats

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-6]

**Json** — `MhnStatsReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnStatsReq {
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-6]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "namespace": hex::encode(authority.namespace().0),
        "count": count,
    })
```

### Errors and validation [#errors-and-validation-6]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_stats(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnStatsReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let metrics = require_service!(state.mhn_metrics(), "MHN");
        metrics.stats_requests.inc();
        let registry = require_service!(state.mhn_registry(), "MHN");
        let entry = registry
            .get_or_init(authority.namespace(), db, None)
            .await
            .map_err(|e| {
                metrics.namespace_errors.inc();
                e
            })?;
        let count = entry.keyspace.count().await;
        // Note: HopfieldKeyspace doesn't expose dimensions or sparsity directly
        // We return count and namespace info instead
        Ok(Json(serde_json::json!({
            "namespace": hex::encode(authority.namespace().0),
            "count": count,
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8124`. Registration: `akasha-daemon/src/main.rs:4717`.

<a id="post-v1-assoc-mhn-config" />

## POST `/v1/assoc/mhn/config` [#post-v1assocmhnconfig]

Mhn config

| Availability         | Source contract     |
| -------------------- | ------------------- |
| Registration         | `config.enable_mhn` |
| Runtime service      | `mhn`               |
| Handler dependencies | `MHN`               |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-7]

**Json** — `MhnConfigReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnConfigReq {
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-7]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "namespace": hex::encode(authority.namespace().0),
        "dimensions": entry.dimensions,
        "persistence": true,
        "network_id": entry.network_id,
        "namespace_id": hex::encode(entry.namespace.0),
        "created_at": entry.created_at.to_rfc3339(),
        "last_accessed": entry.last_accessed.to_rfc3339(),
        "pattern_count": entry.pattern_count,
    })
```

### Errors and validation [#errors-and-validation-7]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_config(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnConfigReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let registry = require_service!(state.mhn_registry(), "MHN");
        // Exercise registry.metrics accessor
        registry.metrics().config_requests.inc();
        let entry = load_mhn_namespace(&state, db, &authority, None).await?;
        Ok(Json(serde_json::json!({
            "namespace": hex::encode(authority.namespace().0),
            "dimensions": entry.dimensions,
            "persistence": true,
            "network_id": entry.network_id,
            "namespace_id": hex::encode(entry.namespace.0),
            "created_at": entry.created_at.to_rfc3339(),
            "last_accessed": entry.last_accessed.to_rfc3339(),
            "pattern_count": entry.pattern_count,
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8235`. Registration: `akasha-daemon/src/main.rs:4718`.

<a id="post-v1-assoc-mhn-system-info" />

## POST `/v1/assoc/mhn/system_info` [#post-v1assocmhnsystem_info]

Mhn system info

| Availability         | Source contract                            |
| -------------------- | ------------------------------------------ |
| Registration         | `config.enable_mhn`                        |
| Runtime service      | `mhn`                                      |
| Handler dependencies | See handler source and return expressions. |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN); require\_matching\_db(\&db).

### Request [#request-8]

**Json** — `MhnSystemInfoReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnSystemInfoReq {
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-8]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "namespace": hex::encode(authority.namespace().0),
        "dimensions": dims,
        "count": count,
        "capacity_estimate": capacity,
        "sparsity": None::<f64>,
        "network_id": entry.network_id,
        "namespace_id": hex::encode(entry.namespace.0),
        "created_at": entry.created_at.to_rfc3339(),
        "last_accessed": entry.last_accessed.to_rfc3339(),
        "pattern_count": entry.pattern_count,
    })
```

### Errors and validation [#errors-and-validation-8]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_system_info(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnSystemInfoReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        authority.require_matching_db(&db)?;
        let entry = load_mhn_namespace(&state, db, &authority, None).await?;
        let count = entry.keyspace.count().await;
        let dims = entry.dimensions;
        let capacity = (0.1 * dims as f32).max(1.0) as usize;
        // Note: sparsity not available in HopfieldKeyspace API
        Ok(Json(serde_json::json!({
            "namespace": hex::encode(authority.namespace().0),
            "dimensions": dims,
            "count": count,
            "capacity_estimate": capacity,
            "sparsity": None::<f64>,
            "network_id": entry.network_id,
            "namespace_id": hex::encode(entry.namespace.0),
            "created_at": entry.created_at.to_rfc3339(),
            "last_accessed": entry.last_accessed.to_rfc3339(),
            "pattern_count": entry.pattern_count,
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:8266`. Registration: `akasha-daemon/src/main.rs:4719`.

<a id="get-v1-mhn-health" />

## GET `/v1/mhn/health` [#get-v1mhnhealth]

Mhn health

| Availability         | Source contract                            |
| -------------------- | ------------------------------------------ |
| Registration         | `config.enable_mhn`                        |
| Runtime service      | `mhn`                                      |
| Handler dependencies | See handler source and return expressions. |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-9]

No typed JSON, query, or path extractor is declared in the handler signature. Headers or request objects may still be consumed; the signature below is authoritative.

### Response [#response-9]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

Serialization is delegated or the handler returns a raw response. Consult the exact handler below; the OpenAPI response intentionally remains unconstrained.

### Errors and validation [#errors-and-validation-9]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_health(State(state): State<AppState>) -> Result<impl IntoResponse, DaemonError> {
        service_health_payload(&state, "mhn").await
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:10305`. Registration: `akasha-daemon/src/main.rs:4720`.

<a id="post-v1-assoc-mhn-list" />

## POST `/v1/assoc/mhn/list` [#post-v1assocmhnlist]

Mhn list

| Availability         | Source contract                            |
| -------------------- | ------------------------------------------ |
| Registration         | `config.enable_mhn`                        |
| Runtime service      | `mhn`                                      |
| Handler dependencies | See handler source and return expressions. |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped. Handler additionally checks require\_scoped(CoreAction::Read, "mhn:read", request\_authority::MEMORY\_MHN).

### Request [#request-10]

**Json** — `MhnListReq`

| Field                             | Rust type               | Required on input                          | Notes            |
| --------------------------------- | ----------------------- | ------------------------------------------ | ---------------- |
| Flattened `body_authority` fields | `RejectedBodyAuthority` | See flattened type; not a named JSON field | Serde: `flatten` |

```rust
struct MhnListReq {
    #[serde(flatten)]
    body_authority: RejectedBodyAuthority,
}
```

### Response [#response-10]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "patterns": [],
        "totalCount": count
    })
```

### Errors and validation [#errors-and-validation-10]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn mhn_list(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Extension(authority): Extension<RequestAuthority>,
        Json(req): Json<MhnListReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        req.body_authority.reject()?;
        authority.require_scoped(CoreAction::Read, "mhn:read", request_authority::MEMORY_MHN)?;
        let entry = load_mhn_namespace(&state, db, &authority, None).await?;
        let count = entry.keyspace.count().await;
        Ok(Json(serde_json::json!({
            "patterns": [],
            "totalCount": count
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:11237`. Registration: `akasha-daemon/src/main.rs:4721`.
