feat(db): extraction des embeddings + mode WAL + config DB provider-agnostic

- Ajout de la table de relation 1-1 NoteEmbedding pour alléger Model Note
- Refactor complet des actions IA sémantique et Memory Echo pour utiliser la jointure
- Migration propre des 85 embeddings locaux existants
- Ajout PRAGMA journal_mode=WAL pour la concurrence au sein de lib/prisma
- Ajout npm run db:switch pour configuration auto SQLite / PostgreSQL
- Fix du compilateur Turbopack et Next-PWA
This commit is contained in:
Sepehr Ramezani
2026-04-17 22:05:19 +02:00
parent a57c277168
commit 3ef5915062
10 changed files with 180 additions and 36 deletions

View File

@@ -177,12 +177,12 @@ export class SemanticSearchService {
const notes = await prisma.note.findMany({
where: {
...(userId ? { userId } : {}),
...(notebookId !== undefined ? { notebookId } : {}), // NEW: Notebook filter
embedding: { not: null }
...(notebookId !== undefined ? { notebookId } : {}),
noteEmbedding: { isNot: null }
},
select: {
id: true,
embedding: true
noteEmbedding: true
}
})
@@ -192,7 +192,7 @@ export class SemanticSearchService {
// Calculate similarities for all notes
const similarities = notes.map(note => {
const noteEmbedding = note.embedding ? JSON.parse(note.embedding) as number[] : []
const noteEmbedding = note.noteEmbedding?.embedding ? JSON.parse(note.noteEmbedding.embedding) as number[] : []
const similarity = embeddingService.calculateCosineSimilarity(
queryEmbedding,
noteEmbedding
@@ -273,7 +273,7 @@ export class SemanticSearchService {
try {
const note = await prisma.note.findUnique({
where: { id: noteId },
select: { content: true, embedding: true, lastAiAnalysis: true }
select: { content: true, noteEmbedding: true, lastAiAnalysis: true }
})
if (!note) {
@@ -283,7 +283,7 @@ export class SemanticSearchService {
// Check if embedding needs regeneration
const shouldRegenerate = embeddingService.shouldRegenerateEmbedding(
note.content,
note.embedding as any,
note.noteEmbedding?.embedding as any,
note.lastAiAnalysis
)
@@ -295,10 +295,14 @@ export class SemanticSearchService {
const { embedding } = await embeddingService.generateEmbedding(note.content)
// Save to database
await prisma.noteEmbedding.upsert({
where: { noteId: noteId },
create: { noteId: noteId, embedding: embeddingService.serialize(embedding) as any },
update: { embedding: embeddingService.serialize(embedding) as any }
})
await prisma.note.update({
where: { id: noteId },
data: {
embedding: embeddingService.serialize(embedding) as any,
lastAiAnalysis: new Date()
}
})