mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-22 11:51:01 +02:00
fix(cli): resolve embedding provider explicitly and surface lane status in sl search (#192)
* feat(cli): add tryUseManagedLocalEmbeddingsDaemon for read-only callers * feat(cli): add resolveProjectEmbeddingProvider helper * fix(cli): wire sl search through resolveProjectEmbeddingProvider so semantic lane works * fix(cli): wire wiki/knowledge search through resolveProjectEmbeddingProvider * feat(cli): surface embeddings-unavailable status when sl search returns empty * refactor(cli): route admin reindex through resolveProjectEmbeddingProvider * refactor: pass embeddingProvider into ingest/scan instead of resolving inside @ktx/context * refactor(mcp): resolve embedding provider in CLI factory, pass into context ports * refactor(context): delete MANAGED_SENTENCE_TRANSFORMERS_BASE_URL sentinel * refactor(cli): delete sentinel-based managed-embeddings indirection * chore: scrub stale managed-embeddings sentinel references from tests and smoke script * chore: unexport unused EmbeddingResolutionMode alias * fix(cli): force pathPrefix="" when targeting the managed embeddings daemon The managed daemon serves /embeddings/compute directly. The default pathPrefix in @ktx/llm is /api, so omitting sentenceTransformers from ktx.yaml produced /api/embeddings/compute -> 404. The resolver now sets pathPrefix='' explicitly when wiring the managed daemon URL, matching what the daemon actually exposes.
This commit is contained in:
parent
56a967278a
commit
9d92c79988
36 changed files with 750 additions and 442 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { MANAGED_SENTENCE_TRANSFORMERS_BASE_URL } from '@ktx/context';
|
||||
import {
|
||||
ensureManagedLocalEmbeddingsDaemon,
|
||||
managedLocalEmbeddingHealthConfig,
|
||||
managedLocalEmbeddingProjectConfig,
|
||||
tryUseManagedLocalEmbeddingsDaemon,
|
||||
} from './managed-local-embeddings.js';
|
||||
import type { ManagedPythonCommandRuntime } from './managed-python-command.js';
|
||||
import type { ManagedPythonDaemonStartResult } from './managed-python-daemon.js';
|
||||
import type { ManagedPythonDaemonLayout } from './managed-python-runtime.js';
|
||||
|
||||
function makeIo() {
|
||||
let stdout = '';
|
||||
|
|
@ -94,25 +94,6 @@ function daemonResult(status: 'started' | 'reused' = 'reused'): ManagedPythonDae
|
|||
};
|
||||
}
|
||||
|
||||
describe('managedLocalEmbeddingProjectConfig', () => {
|
||||
it('uses a stable managed runtime marker instead of a random daemon port', () => {
|
||||
expect(
|
||||
managedLocalEmbeddingProjectConfig({
|
||||
model: 'all-MiniLM-L6-v2',
|
||||
dimensions: 384,
|
||||
}),
|
||||
).toEqual({
|
||||
backend: 'sentence-transformers',
|
||||
model: 'all-MiniLM-L6-v2',
|
||||
dimensions: 384,
|
||||
sentenceTransformers: {
|
||||
base_url: MANAGED_SENTENCE_TRANSFORMERS_BASE_URL,
|
||||
pathPrefix: '',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('managedLocalEmbeddingHealthConfig', () => {
|
||||
it('uses the active KTX daemon URL for the immediate health check', () => {
|
||||
expect(
|
||||
|
|
@ -181,3 +162,93 @@ describe('ensureManagedLocalEmbeddingsDaemon', () => {
|
|||
expect(io.stderr()).toContain('Using KTX daemon: http://127.0.0.1:61234');
|
||||
});
|
||||
});
|
||||
|
||||
describe('tryUseManagedLocalEmbeddingsDaemon', () => {
|
||||
it('returns the daemon when one is running and healthy', async () => {
|
||||
const readStatus = vi.fn(async () => ({
|
||||
kind: 'running' as const,
|
||||
detail: 'ok',
|
||||
layout: {} as ManagedPythonDaemonLayout,
|
||||
state: {
|
||||
schemaVersion: 1 as const,
|
||||
pid: 123,
|
||||
host: '127.0.0.1' as const,
|
||||
port: 4321,
|
||||
version: '0.5.0',
|
||||
features: ['local-embeddings' as const],
|
||||
startedAt: '2026-05-21T00:00:00Z',
|
||||
stdoutLog: '/tmp/stdout.log',
|
||||
stderrLog: '/tmp/stderr.log',
|
||||
},
|
||||
baseUrl: 'http://127.0.0.1:4321',
|
||||
}));
|
||||
const result = await tryUseManagedLocalEmbeddingsDaemon({
|
||||
cliVersion: '0.5.0',
|
||||
projectDir: '/work/proj',
|
||||
readStatus,
|
||||
});
|
||||
expect(result).toEqual({
|
||||
baseUrl: 'http://127.0.0.1:4321',
|
||||
stdoutLog: '/tmp/stdout.log',
|
||||
stderrLog: '/tmp/stderr.log',
|
||||
});
|
||||
expect(readStatus).toHaveBeenCalledWith({
|
||||
cliVersion: '0.5.0',
|
||||
projectDir: '/work/proj',
|
||||
});
|
||||
});
|
||||
|
||||
it('returns null when no daemon state exists', async () => {
|
||||
const readStatus = vi.fn(async () => ({
|
||||
kind: 'stopped' as const,
|
||||
detail: 'no state',
|
||||
layout: {} as ManagedPythonDaemonLayout,
|
||||
}));
|
||||
const result = await tryUseManagedLocalEmbeddingsDaemon({
|
||||
cliVersion: '0.5.0',
|
||||
projectDir: '/work/proj',
|
||||
readStatus,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when daemon is stale', async () => {
|
||||
const readStatus = vi.fn(async () => ({
|
||||
kind: 'stale' as const,
|
||||
detail: 'process gone',
|
||||
layout: {} as ManagedPythonDaemonLayout,
|
||||
}));
|
||||
const result = await tryUseManagedLocalEmbeddingsDaemon({
|
||||
cliVersion: '0.5.0',
|
||||
projectDir: '/work/proj',
|
||||
readStatus,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('rejects daemons that do not advertise local-embeddings', async () => {
|
||||
const readStatus = vi.fn(async () => ({
|
||||
kind: 'running' as const,
|
||||
detail: 'ok',
|
||||
layout: {} as ManagedPythonDaemonLayout,
|
||||
state: {
|
||||
schemaVersion: 1 as const,
|
||||
pid: 123,
|
||||
host: '127.0.0.1' as const,
|
||||
port: 4321,
|
||||
version: '0.5.0',
|
||||
features: ['core' as const],
|
||||
startedAt: '2026-05-21T00:00:00Z',
|
||||
stdoutLog: '/tmp/stdout.log',
|
||||
stderrLog: '/tmp/stderr.log',
|
||||
},
|
||||
baseUrl: 'http://127.0.0.1:4321',
|
||||
}));
|
||||
const result = await tryUseManagedLocalEmbeddingsDaemon({
|
||||
cliVersion: '0.5.0',
|
||||
projectDir: '/work/proj',
|
||||
readStatus,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue