feat(insights): fix DBSCAN, Persian embeddings crash, D3 physics layouts, and D3 node not found runtime error
This commit is contained in:
@@ -7,6 +7,7 @@ import { auth } from '@/auth'
|
||||
import { getAIProvider } from '@/lib/ai/factory'
|
||||
import { parseNote, getHashColor } from '@/lib/utils'
|
||||
import { upsertNoteEmbedding } from '@/lib/embeddings'
|
||||
import { embeddingService } from '@/lib/ai/services/embedding.service'
|
||||
import { syncNoteLinksForNote } from '@/lib/notes/sync-note-links'
|
||||
import { getSystemConfig, getConfigNumber, getConfigBoolean, SEARCH_DEFAULTS } from '@/lib/config'
|
||||
import { contextualAutoTagService } from '@/lib/ai/services/contextual-auto-tag.service'
|
||||
@@ -122,7 +123,7 @@ async function syncLabels(userId: string, noteLabels: string[] = [], notebookId?
|
||||
|
||||
/** Sync both Note.labels (JSON) AND labelRelations for a single note.
|
||||
* Also cleans up orphan labels in the same notebook scope. */
|
||||
async function syncNoteLabels(noteId: string, labelNames: string[], notebookId: string | null, userId: string) {
|
||||
export async function syncNoteLabels(noteId: string, labelNames: string[], notebookId: string | null, userId: string) {
|
||||
const uniqueNames = [...new Set(labelNames.map(n => n.trim()).filter(Boolean))]
|
||||
const labelRows = await syncLabels(userId, uniqueNames, notebookId)
|
||||
const labelIds = labelRows.map(l => l.id)
|
||||
@@ -444,9 +445,7 @@ export async function createNote(data: {
|
||||
// Use setImmediate-like pattern to not block the response
|
||||
; (async () => {
|
||||
try {
|
||||
const bgConfig = await getSystemConfig()
|
||||
const provider = getAIProvider(bgConfig)
|
||||
const embedding = await provider.getEmbeddings(content)
|
||||
const { embedding } = await embeddingService.generateNoteEmbedding(data.title, content)
|
||||
if (embedding) {
|
||||
await upsertNoteEmbedding(noteId, embedding)
|
||||
}
|
||||
@@ -574,10 +573,10 @@ export async function updateNote(id: string, data: {
|
||||
if (data.content !== undefined) {
|
||||
const noteId = id
|
||||
const content = data.content;
|
||||
const title = data.title !== undefined ? data.title : oldNote?.title ?? null;
|
||||
(async () => {
|
||||
try {
|
||||
const provider = getAIProvider(await getSystemConfig());
|
||||
const embedding = await provider.getEmbeddings(content);
|
||||
const { embedding } = await embeddingService.generateNoteEmbedding(title, content)
|
||||
if (embedding) {
|
||||
await upsertNoteEmbedding(noteId, embedding);
|
||||
}
|
||||
@@ -928,11 +927,10 @@ export async function syncAllEmbeddings() {
|
||||
noteEmbedding: { is: null }
|
||||
}
|
||||
})
|
||||
const provider = getAIProvider(await getSystemConfig());
|
||||
for (const note of notesToSync) {
|
||||
if (!note.content) continue;
|
||||
try {
|
||||
const embedding = await provider.getEmbeddings(note.content);
|
||||
const { embedding } = await embeddingService.generateNoteEmbedding(note.title, note.content)
|
||||
if (embedding) {
|
||||
await upsertNoteEmbedding(note.id, embedding)
|
||||
updatedCount++;
|
||||
|
||||
Reference in New Issue
Block a user