You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-44Lines changed: 38 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,66 +115,57 @@ Gating plugs in before narrative, pheromone, and MMR scoring—so downstream mem
115
115
116
116
---
117
117
118
-
## Integrations & interfaces
118
+
## Multi-tenancy & namespaces
119
119
120
-
-**REST API** (`uvicorn neuralcache.api.server:app`) with `/rerank`, `/feedback`, `/metrics`, and `/healthz` endpoints.
121
-
-**Plus API** (`uvicorn neuralcache.api.server_plus:app`) adds `/rerank/batch`, Prometheus `/metrics`, and mounts the legacy routes under `/v1`.
122
-
- All responses include `X-NeuralCache-API-Version` (and temporary alias `X-API-Version`) so clients can log and assert expected contract versions. See `docs/VERSIONING.md` for the policy.
123
-
-**CLI** (`neuralcache "<query>" docs.jsonl --top-k 5`) for quick experiments and scripting.
NeuralCache now supports lightweight logical isolation using a namespace header:
126
121
127
-
See [`examples/quickstart.py`](examples/quickstart.py) for an end-to-end script.
128
-
129
-
---
122
+
```
123
+
X-NeuralCache-Namespace: tenantA
124
+
```
130
125
131
-
## Feedback API: closing the loop
126
+
If omitted, the `default` namespace is used. Narrative + pheromone feedback effects do not bleed across namespaces. See `MULTITENANCY.md` for details, limitations (no eviction yet, shared persistence), and roadmap.
132
127
133
-
Send successful reranks back to NeuralCache so the narrative EMA and pheromone
134
-
signals keep learning:
128
+
| Setting | Purpose | Default |
129
+
|---------|---------|---------|
130
+
|`NEURALCACHE_NAMESPACE_HEADER`| Header key to read namespace |`X-NeuralCache-Namespace`|
131
+
|`NEURALCACHE_DEFAULT_NAMESPACE`| Fallback namespace when header missing |`default`|
132
+
|`NEURALCACHE_NAMESPACE_PATTERN`| Validation regex (400 on mismatch) |`^[a-zA-Z0-9_.-]{1,64}$`|
135
133
136
-
```http
137
-
POST /feedback
138
-
Content-Type: application/json
134
+
Invalid namespaces return a standardized error envelope:
139
135
136
+
```json
140
137
{
141
-
"query": "How do I rotate API keys?",
142
-
"selected_ids": ["doc-42", "doc-71"],
143
-
"success": 0.9,
144
-
"best_doc_text": "Rotate keys via the dashboard > API tokens",
145
-
"best_doc_embedding": [0.01, 0.32, -0.55, ...]
138
+
"error": {
139
+
"code": "BAD_REQUEST",
140
+
"message": "Invalid namespace",
141
+
"detail": null
142
+
}
146
143
}
147
144
```
148
145
149
-
-`selected_ids`**must** match the `id` values returned by `/rerank`. The API
150
-
rejects unknown IDs to prevent stale writes.
151
-
-`success` scores the overall outcome (`1.0` for complete resolution, `0.0`
152
-
for failure). Values below `settings.narrative_success_gate` are ignored for
153
-
narrative updates but still count toward pheromone decay.
154
-
-`best_doc_text`/`best_doc_embedding` are optional hints that let the reranker
155
-
update the narrative vector even when a caller reformats the answer before
156
-
returning it to the user.
146
+
---
157
147
158
-
On success the endpoint responds with `{"status": "ok"}`.
148
+
## Standardized error envelopes
159
149
160
-
Tip: throttle feedback submissions with a short debounce window (e.g., only send
161
-
feedback after end-users click “helpful”) to avoid promoting documents for noisy
162
-
sessions.
150
+
All errors (including validation) resolve to a stable shape documented in `docs/ERROR_ENVELOPES.md`:
Common codes: `BAD_REQUEST`, `UNAUTHORIZED`, `NOT_FOUND`, `ENTITY_TOO_LARGE`, `VALIDATION_ERROR`, `RATE_LIMITED`, `INTERNAL_ERROR`.
165
163
166
-
## Privacy & retention tips
164
+
---
167
165
168
-
- Set `NEURALCACHE_STORAGE_PERSISTENCE_ENABLED=false` to run fully in-memory. Narrative
169
-
vectors and pheromones reset on process restart and never touch disk.
170
-
- Configure `NEURALCACHE_STORAGE_RETENTION_DAYS` (e.g., `7`) to purge pheromones and
171
-
narrative state older than the retention window on startup. SQLite purges directly
172
-
via `metadata`/`pheromones`, and the JSON fallback trims files in place.
173
-
- Rotate SQLite files regularly or place them on encrypted storage. Review
174
-
[`SECURITY.md`](SECURITY.md) for reporting procedures and deployment guardrails.
166
+
## Privacy & data handling
175
167
176
-
These controls let you scope how long user-derived signals persist while still
177
-
benefiting from adaptive reranking.
168
+
A concise operator playbook for data classification, retention, and namespace isolation is available in `PRIVACY.md`. Before production, review both `PRIVACY.md` and `SECURITY.md` and set appropriate retention and auth settings.
178
169
179
170
---
180
171
@@ -201,6 +192,9 @@ benefiting from adaptive reranking.
201
192
|`NEURALCACHE_DETERMINISTIC_SEED`| Seed used when deterministic mode is enabled |`1337`|
202
193
|`NEURALCACHE_EPSILON`| Override ε-greedy exploration rate (0-1). Ignored when deterministic. |_unset_|
203
194
|`NEURALCACHE_MMR_LAMBDA_DEFAULT`| Default MMR lambda when request omits/nulls `mmr_lambda`|`0.5`|
195
+
|`NEURALCACHE_NAMESPACE_HEADER`| Header key to read namespace |`X-NeuralCache-Namespace`|
196
+
|`NEURALCACHE_DEFAULT_NAMESPACE`| Fallback namespace when header missing |`default`|
197
+
|`NEURALCACHE_NAMESPACE_PATTERN`| Validation regex (400 on mismatch) |`^[a-zA-Z0-9_.-]{1,64}$`|
204
198
205
199
Adjust everything via `.env`, environment variables, or direct `Settings(...)` instantiation. `NEURALCACHE_EPSILON` (when set) takes precedence over `epsilon_greedy` setting unless deterministic mode is active. `NEURALCACHE_MMR_LAMBDA_DEFAULT` supplies fallback diversity weighting when omitted.
0 commit comments