Skip to content

QMD SDK Migration — Phase 1+2: DB init via createStore() + kill deep imports #57

Description

@ashu17706

What

Replace smriti's manual DB setup and deep QMD imports with the stable public SDK.

Phase 1 — DB init via createStore()

Currently initSmriti() manually opens the SQLite database, calls loadSqliteVec(), and runs QMD table setup. Replace with:

```ts
const store = await createStore({ dbPath: QMD_DB_PATH });
// store.internal.db is now the shared Database handle
// QMD handles its own table init and sqlite-vec loading
runSmritiMigrations(store.internal.db);
```

Files: src/db.ts, src/index.ts

Phase 2 — Kill deep imports in memory.ts

Replace every ../qmd/src/ import with InternalStore equivalents:

Current Replacement
insertEmbedding(db, ...) store.insertEmbedding(...)
Manual CREATE VIRTUAL TABLE vectors_vec store.ensureVecTable(dimensions)
getDefaultLlamaCpp() + manual embed loop store.internal.llm
chunkDocumentByTokens() move to smriti util or keep as single import
reciprocalRankFusion() keep as single import (not on InternalStore)
hashContent() replace with Bun.CryptoHasher (SHA256, 3 lines)

Files: src/memory.ts

After this: src/memory.ts has zero ../qmd/src/ deep imports.

Why

Deep imports into ../qmd/src/store.js and ../qmd/src/llm.js break silently on any upstream QMD refactor. Every upstream sync is a potential breakage point. The public InternalStore API is stable and intentional.

Acceptance Criteria

  • src/db.ts uses createStore() for DB init — no manual loadSqliteVec()
  • src/memory.ts has no imports from ../qmd/src/
  • All existing tests pass (no behavior change)
  • smriti status, smriti recall, smriti ingest work correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions