mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
add dimension mismatch detection and version injection to memory plugin
This commit is contained in:
1 parent
be871aa5b2
commit
d681ee5c29
7 files changed
+111
-17
No files matched your search
@@ -1,5 +1,7 @@
|
||||
export { initializeDatabase, closeDatabase, resolveDataDir, resolveLogPath } from './database'
|
||||
export { createVecService } from './vec'
|
||||
export { getTableDimensions, recreateVecTable } from './vec-utils'
|
||||
export type { TableDimensionsResult } from './vec-utils'
|
||||
export type { VecService, VecSearchResult } from './vec-types'
|
||||
export { createMemoryQuery } from './memory-queries'
|
||||
export { createSessionStateQueries } from './session-state-queries'
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Database } from 'bun:sqlite'
|
||||
|
||||
export type TableDimensionsResult =
|
||||
| { exists: false }
|
||||
| { exists: true; dimensions: number | null }
|
||||
|
||||
export function getTableDimensions(db: Database): TableDimensionsResult {
|
||||
const row = db.prepare(
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='memory_embeddings'"
|
||||
).get() as { sql: string } | undefined
|
||||
|
||||
if (!row) return { exists: false }
|
||||
|
||||
const match = row.sql.match(/float\[(\d+)\]/i)
|
||||
return { exists: true, dimensions: match ? parseInt(match[1]!, 10) : null }
|
||||
}
|
||||
|
||||
export function recreateVecTable(db: Database, dimensions: number): void {
|
||||
db.run('DROP TABLE IF EXISTS memory_embeddings')
|
||||
db.run(`
|
||||
CREATE VIRTUAL TABLE memory_embeddings USING vec0(
|
||||
embedding float[${dimensions}],
|
||||
+memory_id INTEGER,
|
||||
+project_id TEXT
|
||||
)
|
||||
`)
|
||||
}
|
||||
Reference in new issue
Block a user