feat(EMBEDDINGS-0001): enable local embedder by default and overhaul settings page

- Wire local embedding provider as the default on startup when no profile is configured
- Refactor embedding settings into dedicated service, DTOs, mappers and models
- Rebuild settings page with profile management UI and live test feedback
- Expose index summary (indexed versions + embedding count) on repo endpoints
- Harden indexing pipeline and context search with additional test coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Giancarmine Salucci
2026-03-28 09:28:01 +01:00
parent d1381f7fc0
commit 781d224adc
30 changed files with 1419 additions and 313 deletions

View File

@@ -9,13 +9,13 @@
import { initializeDatabase } from '$lib/server/db/index.js';
import { getClient } from '$lib/server/db/client.js';
import { initializePipeline } from '$lib/server/pipeline/startup.js';
import {
EMBEDDING_CONFIG_KEY,
createProviderFromConfig,
defaultEmbeddingConfig
} from '$lib/server/embeddings/factory.js';
import { createProviderFromProfile } from '$lib/server/embeddings/registry.js';
import { EmbeddingService } from '$lib/server/embeddings/embedding.service.js';
import type { EmbeddingConfig } from '$lib/server/embeddings/factory.js';
import {
EmbeddingProfileEntity,
type EmbeddingProfileEntityProps
} from '$lib/server/models/embedding-profile.js';
import { EmbeddingProfileMapper } from '$lib/server/mappers/embedding-profile.mapper.js';
import type { Handle } from '@sveltejs/kit';
// ---------------------------------------------------------------------------
@@ -26,37 +26,20 @@ try {
initializeDatabase();
const db = getClient();
// Load persisted embedding configuration (if any).
const configRow = db
.prepare<[string], { value: string }>(`SELECT value FROM settings WHERE key = ?`)
.get(EMBEDDING_CONFIG_KEY);
const activeProfileRow = db
.prepare<[], EmbeddingProfileEntityProps>(
'SELECT * FROM embedding_profiles WHERE is_default = 1 AND enabled = 1 LIMIT 1'
)
.get();
let embeddingService: EmbeddingService | null = null;
if (configRow) {
try {
const config: EmbeddingConfig =
typeof configRow.value === 'string'
? JSON.parse(configRow.value)
: (configRow.value as EmbeddingConfig);
if (config.provider !== 'none') {
const provider = createProviderFromConfig(config);
embeddingService = new EmbeddingService(db, provider);
}
} catch (err) {
console.warn(
`[hooks.server] Could not load embedding config: ${err instanceof Error ? err.message : String(err)}`
);
}
} else {
// Use the default (noop) config so the pipeline is still wired up.
const config = defaultEmbeddingConfig();
if (config.provider !== 'none') {
const provider = createProviderFromConfig(config);
embeddingService = new EmbeddingService(db, provider);
}
if (activeProfileRow) {
const activeProfile = EmbeddingProfileMapper.fromEntity(
new EmbeddingProfileEntity(activeProfileRow)
);
const provider = createProviderFromProfile(activeProfile);
embeddingService = new EmbeddingService(db, provider, activeProfile.id);
}
initializePipeline(db, embeddingService);