knowledge bases: benannte Sammlungen von Seiten, wie Erinnerungen mit Vektor
Acht Werkzeuge (kb_create, kb_list, kb_write, kb_read, kb_search, kb_entries, kb_delete,
kb_drop). Eine Basis ist ein Name mit einem Verzeichnis darunter; darin liegen Seiten wie
Erinnerungen: Titel, Text, Vektor. Der Zweck unterscheidet sie: Erinnerungen sind das, was
ein Agent beiläufig behält — eine Wissensbasis ist das, was ein Mensch aufgeschrieben hat,
damit es nachgelesen wird.
Zwei Entscheidungen, die den Unterschied zu einem Dateiordner ausmachen: derselbe Titel
aktualisiert die Seite, statt sie zu verdoppeln, und die vorherige Fassung wandert in die
Historie (fünf Versionen) — die Antwort sagt beides. Und die Suche sortiert über alle
Basen gemeinsam, sonst gewinnt die beste Seite je Basis statt der besten Seite.
Namen werden zu Verzeichnisnamen ("Olivia Technik" → olivia-technik), angesprochen wird
die Basis aber über den Namen; wer den Slug kennt, darf ihn auch schreiben.
Ein Fehler auf dem Weg, der die Suite zum Absturz brachte: in der Aktualisierung zeigten
zwei Variablen auf dieselbe Kennung (die gefundene Seite und die neue Seite), und am Ende
wurde beide freigegeben — free(): double free. Jetzt gibt es genau einen Besitzer der
Kennung; die alte Fassung wird einmal gelesen und danach in die Historie kopiert.
Tests: 30 Prüfungen (vorher 16). Neu: Slug aus dem Namen, Aktualisierung statt Dublette,
Historie bleibt lesbar, Basis über den Namen ansprechbar, Suche über alle Basen und
innerhalb einer, Liste mit Seitenzahl, Löschen einer Seite, confirm-Pflicht beim Verwerfen
einer ganzen Basis. make test: PASS.
This commit is contained in:
1 parent
5108636d84
commit
d0bd1efe54
3 files changed
+1135
-5
No files matched your search
@@ -43,6 +43,38 @@ itself plus its children, so `van` covers `van/technik` — the same rule as tas
|
||||
| `memory_delete` | remove what is wrong or obsolete |
|
||||
| `memory_scopes` | which scopes exist, how many memories each |
|
||||
|
||||
## Knowledge bases — a wiki next to the memories
|
||||
|
||||
A knowledge base is a named collection of pages. Same mechanics as a memory (title, text,
|
||||
embedding, searchable by meaning), different purpose: memories are what an agent picked up
|
||||
along the way, a knowledge base is what a human wrote down to be read again.
|
||||
|
||||
```
|
||||
$MEMORYDIR/kb/<slug>/kb.json {"name","slug","description","created"}
|
||||
$MEMORYDIR/kb/<slug>/e00001.json {"id","title","text","tags","source",
|
||||
"created","updated","model","embedding",
|
||||
"history":[{"text","updated"}]}
|
||||
```
|
||||
|
||||
| tool | what it is for |
|
||||
|---|---|
|
||||
| `kb_create` | a base per subject area (`olivia-technik`, `fleet-junction`); `"Olivia Technik"` becomes the slug `olivia-technik` |
|
||||
| `kb_list` | which bases exist, how many pages, what they are for |
|
||||
| `kb_write` | a page; **the same title updates it** instead of duplicating |
|
||||
| `kb_read` | one page in full, optionally with its earlier versions |
|
||||
| `kb_search` | by meaning; without `kb` it searches all bases and ranks globally |
|
||||
| `kb_entries` | what a base already covers |
|
||||
| `kb_delete` | one page |
|
||||
| `kb_drop` | a whole base — needs `confirm="yes"`, otherwise it only says what would be lost |
|
||||
|
||||
Two decisions that matter:
|
||||
|
||||
- **Same title = update, with history.** The previous text moves into `history` (five
|
||||
versions), and the answer says `updated … earlier version kept in history`. A wiki that
|
||||
silently overwrites is not a wiki.
|
||||
- **Search ranks globally** across bases unless one is named — the best page wins, not the
|
||||
best page per base.
|
||||
|
||||
## The embedder
|
||||
|
||||
OpenAI-compatible `/v1/embeddings`, `EMBED_URL` (default
|
||||
|
||||
+98
-5
@@ -97,8 +97,10 @@ class Mcp:
|
||||
return self._post({"jsonrpc": "2.0", "id": self.n, "method": method,
|
||||
"params": params or {}})
|
||||
|
||||
def tool(self, name, **args):
|
||||
r = self.call("tools/call", {"name": name, "arguments": args})
|
||||
def tool(self, _tool_name, **args):
|
||||
# Der Parameter heißt nicht `name`, weil ein Werkzeug selbst ein Argument `name`
|
||||
# haben darf (kb_create) — sonst kollidieren Signatur und Aufruf.
|
||||
r = self.call("tools/call", {"name": _tool_name, "arguments": args})
|
||||
res = r.get("result", {})
|
||||
content = res.get("content") or []
|
||||
text = content[0].get("text", "") if content else json.dumps(res)
|
||||
@@ -146,10 +148,11 @@ def main():
|
||||
|
||||
tools = c.call("tools/list").get("result", {}).get("tools", [])
|
||||
names = sorted(t["name"] for t in tools)
|
||||
want = ["memory_add", "memory_delete", "memory_get", "memory_list",
|
||||
"memory_scopes", "memory_search", "memory_update"]
|
||||
want = ["kb_create", "kb_delete", "kb_drop", "kb_entries", "kb_list", "kb_read",
|
||||
"kb_search", "kb_write", "memory_add", "memory_delete", "memory_get",
|
||||
"memory_list", "memory_scopes", "memory_search", "memory_update"]
|
||||
if names == want:
|
||||
ok("seven tools, the expected ones")
|
||||
ok("fifteen tools: seven for memories, eight for knowledge bases")
|
||||
else:
|
||||
bad("tools are %s" % names)
|
||||
|
||||
@@ -214,6 +217,96 @@ def main():
|
||||
else:
|
||||
bad("memory_scopes: %s" % t[:160])
|
||||
|
||||
# ---- Wissensbasis: benannte Sammlungen, Seiten wie Erinnerungen ----
|
||||
t, err = c.tool("kb_create", name="Olivia Technik",
|
||||
description="was am Fahrzeug gemessen und entschieden wurde")
|
||||
if not err and "created" in t and "olivia-technik" in t:
|
||||
ok("a knowledge base gets a readable slug (Olivia Technik → olivia-technik)")
|
||||
else:
|
||||
bad("kb_create: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_write", kb="olivia-technik", title="Frostschutz",
|
||||
text="G12+ blau, Mischung 50:50, geprüft bei -25 Grad.",
|
||||
tags="kühlmittel")
|
||||
if not err and "created" in t:
|
||||
ok("a page is created in the base")
|
||||
else:
|
||||
bad("kb_write: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_write", kb="olivia-technik", title="Frostschutz",
|
||||
text="G12+ blau, Mischung 60:40, geprüft bei -32 Grad.")
|
||||
if not err and "updated" in t and "e00001" in t:
|
||||
ok("the same title updates the page instead of duplicating it")
|
||||
else:
|
||||
bad("second write: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_read", kb="olivia-technik", title="Frostschutz", history=True)
|
||||
if not err and "-32 Grad" in t and "-25 Grad" in t and "earlier version" in t:
|
||||
ok("the earlier version survives in the page history")
|
||||
else:
|
||||
bad("kb_read with history: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_write", kb="Olivia Technik", title="Ölwechsel",
|
||||
text="OM 364 A: 12 Liter 15W-40, Filter alle 10 000 km.")
|
||||
if not err:
|
||||
ok("the base is addressed by name, not by slug")
|
||||
else:
|
||||
bad("write by display name: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_search", query="wie viel öl braucht der motor", limit=2)
|
||||
if not err and "Ölwechsel" in t and "score=" in t:
|
||||
ok("search finds the right page by meaning across bases")
|
||||
else:
|
||||
bad("kb_search: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_search", query="öl", kb="olivia-technik")
|
||||
if not err and "Ölwechsel" in t and "Frostschutz" not in t.split("\n")[0]:
|
||||
ok("restricting to one base keeps the others out")
|
||||
else:
|
||||
bad("kb_search with kb: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_entries", kb="olivia-technik")
|
||||
if not err and "Frostschutz" in t and "Ölwechsel" in t and "2 entries" in t:
|
||||
ok("kb_entries lists both pages")
|
||||
else:
|
||||
bad("kb_entries: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_list")
|
||||
if not err and "olivia-technik" in t and "2 entries" in t:
|
||||
ok("kb_list shows the base with its page count")
|
||||
else:
|
||||
bad("kb_list: %s" % t[:200])
|
||||
|
||||
t, err = c.tool("kb_drop", kb="olivia-technik")
|
||||
if not err and "not deleting" in t and "confirm" in t:
|
||||
ok("dropping a base needs an explicit yes")
|
||||
else:
|
||||
bad("kb_drop without confirm: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_delete", kb="olivia-technik", title="Frostschutz")
|
||||
if not err and "deleted" in t:
|
||||
ok("a single page can be deleted")
|
||||
else:
|
||||
bad("kb_delete: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_read", kb="olivia-technik", title="Frostschutz")
|
||||
if err or "no page" in t:
|
||||
ok("the deleted page is gone")
|
||||
else:
|
||||
bad("the page is still there: %s" % t[:120])
|
||||
|
||||
t, err = c.tool("kb_drop", kb="olivia-technik", confirm="yes")
|
||||
if not err and "dropped" in t:
|
||||
ok("dropping with confirm removes the base")
|
||||
else:
|
||||
bad("kb_drop with confirm: %s" % t[:160])
|
||||
|
||||
t, err = c.tool("kb_list")
|
||||
if "no knowledge bases" in t:
|
||||
ok("and it is no longer listed")
|
||||
else:
|
||||
bad("the base is still listed: %s" % t[:120])
|
||||
|
||||
# Ohne Embedder: speichern geht weiter, die Suche sagt, was sie tut.
|
||||
stub.shutdown()
|
||||
t, err = c.tool("memory_add", text="Die Pumpe läuft seit März leise.", scope="van/technik")
|
||||
|
||||
Reference in new issue
Block a user