kyp-mem 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/kyp_mem/ui.py CHANGED
@@ -142,6 +142,28 @@ def create_app(vault_path: str = None) -> FastAPI:
142
142
  vault.write_note(path, content, tags, {})
143
143
  return JSONResponse({"ok": True, "path": path})
144
144
 
145
+ @app.get("/api/sessions/search")
146
+ def search_sessions(q: str = "", project: str = ""):
147
+ from .vector import get_session_memory
148
+ mem = get_session_memory()
149
+ if not mem or not q:
150
+ return JSONResponse([])
151
+ results = mem.search_sessions(q, project=project or None, n_results=10)
152
+ if not results or not results.get("ids") or not results["ids"][0]:
153
+ return JSONResponse([])
154
+ items = []
155
+ for i, path in enumerate(results["ids"][0]):
156
+ doc = results["documents"][0][i]
157
+ dist = results["distances"][0][i]
158
+ note = vault.index.notes.get(path)
159
+ items.append({
160
+ "path": path,
161
+ "title": note.title if note else path,
162
+ "distance": dist,
163
+ "snippet": doc[:300],
164
+ })
165
+ return JSONResponse(items)
166
+
145
167
  @app.get("/api/sessions")
146
168
  def list_sessions(project: str = ""):
147
169
  sessions = {}
package/kyp_mem/vault.py CHANGED
@@ -200,12 +200,23 @@ class Index:
200
200
  return results[:15]
201
201
 
202
202
 
203
+ from .vector import init_vector_db, get_session_memory
204
+
203
205
  class Vault:
204
206
  def __init__(self, vault_path: str):
205
207
  self.root = Path(vault_path).expanduser().resolve()
206
208
  self.root.mkdir(parents=True, exist_ok=True)
207
209
  self.index = Index()
210
+ init_vector_db(str(self.root))
208
211
  self._load_all()
212
+ self._sync_vector_db()
213
+
214
+ def _sync_vector_db(self):
215
+ mem = get_session_memory()
216
+ for path, note in self.index.notes.items():
217
+ if "/Sessions/" in path or path.startswith("Sessions/"):
218
+ folder = note.folder
219
+ mem.upsert_session(path, folder, note.content)
209
220
 
210
221
  def _load_all(self):
211
222
  notes = {}
@@ -250,6 +261,8 @@ class Vault:
250
261
 
251
262
  full.write_text(serialize_note(note), encoding="utf-8")
252
263
  self._load_all()
264
+ if "/Sessions/" in path or path.startswith("Sessions/"):
265
+ get_session_memory().upsert_session(path, note.folder, note.content)
253
266
 
254
267
  def delete(self, path: str) -> bool:
255
268
  full = self.root / path
@@ -261,6 +274,8 @@ class Vault:
261
274
  parent.rmdir()
262
275
  parent = parent.parent
263
276
  self._load_all()
277
+ if "/Sessions/" in path or path.startswith("Sessions/"):
278
+ get_session_memory().delete_session(path)
264
279
  return True
265
280
  return False
266
281
 
@@ -0,0 +1,43 @@
1
+ import chromadb
2
+ from pathlib import Path
3
+
4
+ class SessionMemory:
5
+ def __init__(self, vault_path: str):
6
+ self.db_path = Path(vault_path).parent / "chroma"
7
+ self.db_path.mkdir(parents=True, exist_ok=True)
8
+ self.client = chromadb.PersistentClient(path=str(self.db_path))
9
+ self.collection = self.client.get_or_create_collection(name="sessions")
10
+
11
+ def upsert_session(self, path: str, project: str, content: str):
12
+ self.collection.upsert(
13
+ documents=[content],
14
+ metadatas=[{"project": project}],
15
+ ids=[path]
16
+ )
17
+
18
+ def delete_session(self, path: str):
19
+ try:
20
+ self.collection.delete(ids=[path])
21
+ except Exception:
22
+ pass
23
+
24
+ def search_sessions(self, query: str, project: str = None, n_results: int = 5):
25
+ where = {"project": project} if project else None
26
+ try:
27
+ results = self.collection.query(
28
+ query_texts=[query],
29
+ n_results=n_results,
30
+ where=where
31
+ )
32
+ return results
33
+ except Exception:
34
+ return {"ids": [], "documents": [], "metadatas": [], "distances": []}
35
+
36
+ session_memory = None
37
+
38
+ def init_vector_db(vault_path: str):
39
+ global session_memory
40
+ session_memory = SessionMemory(vault_path)
41
+
42
+ def get_session_memory():
43
+ return session_memory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kyp-mem",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Know Your Project — Persistent knowledge base for AI agents. MCP-powered with wikilinks, backlinks, auto-learning, and neon web UI.",
5
5
  "bin": {
6
6
  "kyp-mem": "bin/cli.mjs"
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "kyp-mem"
7
- version = "0.4.0"
7
+ version = "0.4.2"
8
8
  description = "Know Your Project — Persistent knowledge base for AI agents. MCP-powered with wikilinks, backlinks, auto-learning, and neon web UI."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -30,6 +30,7 @@ dependencies = [
30
30
  "pyyaml>=6.0",
31
31
  "fastapi>=0.100.0",
32
32
  "uvicorn>=0.20.0",
33
+ "chromadb>=0.4.0",
33
34
  ]
34
35
 
35
36
  [project.urls]