fix(drafting): Drafting-Engine auf prod reparieren — RAG via ai-sdk + OVH-LLM-Kaskade
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / iace-gt-coverage (push) Has been skipped
CI / test-python-backend (push) Has been skipped
CI / test-python-document-crawler (push) Has been skipped
CI / test-python-dsms-gateway (push) Has been skipped
CI / detect-changes (push) Successful in 7s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / secret-scan (push) Has been skipped
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / build-sha-integrity (push) Successful in 5s
CI / validate-canonical-controls (push) Successful in 4s
CI / loc-budget (push) Successful in 17s
CI / go-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m2s
CI / test-go (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / iace-gt-coverage (push) Has been skipped
CI / test-python-backend (push) Has been skipped
CI / test-python-document-crawler (push) Has been skipped
CI / test-python-dsms-gateway (push) Has been skipped
CI / detect-changes (push) Successful in 7s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / secret-scan (push) Has been skipped
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / build-sha-integrity (push) Successful in 5s
CI / validate-canonical-controls (push) Successful in 4s
CI / loc-budget (push) Successful in 17s
CI / go-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m2s
CI / test-go (push) Has been skipped
Die Drafting-Engine (Dokument-Entwurf, v2-Pipeline, Validierung, Drafting-Chat, Vendor-Vertragspruefung) war auf prod doppelt tot: - RAG ueber bp-core-rag-service:8097 (existiert auf prod nicht) - LLM ueber OLLAMA_URL/api/chat mit qwen2.5vl (prod = ollama-embed, kein Chat-Modell) Fix (analog zum Compliance-Advisor): - rag-query.ts -> ai-compliance-sdk /sdk/v1/rag/search (bge-m3, prod-erreichbar). - Neue lib/sdk/drafting-engine/llm-cascade.ts: OVH/LiteLLM (gpt-oss-120b) zuerst, Ollama als Dev-Fallback; cascadeComplete (JSON) + cascadeStream. Das Backend nutzt OVH+JSON bereits erfolgreich auf prod (extract-datasheet). - 5 Aufrufstellen (draft-helpers, draft-helpers-v2, validate, chat, vendor-review) auf die Kaskade umgestellt; keine direkten Ollama-Calls mehr. - Tests: llm-cascade + rag-query aktualisiert. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
/**
|
||||
* Shared RAG query utility for the Drafting Engine.
|
||||
*
|
||||
* Queries the bp-core-rag-service for relevant legal context.
|
||||
* Supports multi-collection search via POST /api/v1/search.
|
||||
* Used by both chat and draft routes.
|
||||
* Fragt die ai-compliance-sdk (`/sdk/v1/rag/search`, bge-m3) nach Rechtskontext.
|
||||
* Frueher: bp-core-rag-service:8097 — der existiert auf prod NICHT (nur macmini/dev),
|
||||
* dadurch lieferte die Drafting-Engine dort keinen RAG-Kontext. Die ai-sdk embeddet
|
||||
* mit bge-m3 und ist prod-erreichbar. Genutzt von draft-, chat- und vendor-review-Routes.
|
||||
*/
|
||||
|
||||
const RAG_SERVICE_URL = process.env.RAG_SERVICE_URL || 'http://bp-core-rag-service:8097'
|
||||
const SDK_URL =
|
||||
process.env.SDK_API_URL || process.env.SDK_URL || 'http://ai-compliance-sdk:8090'
|
||||
const DEFAULT_USER = '00000000-0000-0000-0000-000000000001'
|
||||
const DEFAULT_TENANT =
|
||||
process.env.DEFAULT_TENANT_ID || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e'
|
||||
|
||||
interface SdkRagResult {
|
||||
text?: string
|
||||
regulation_code?: string
|
||||
regulation_name?: string
|
||||
regulation_short?: string
|
||||
// Rueckwaerts-kompatibel, falls eine Quelle noch das alte rag-service-Format liefert:
|
||||
content?: string
|
||||
source_name?: string
|
||||
source_code?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the RAG corpus for relevant legal documents.
|
||||
@@ -18,17 +34,16 @@ const RAG_SERVICE_URL = process.env.RAG_SERVICE_URL || 'http://bp-core-rag-servi
|
||||
*/
|
||||
export async function queryRAG(query: string, topK = 3, collection?: string): Promise<string> {
|
||||
try {
|
||||
const body: Record<string, unknown> = {
|
||||
query,
|
||||
top_k: topK,
|
||||
}
|
||||
if (collection) {
|
||||
body.collection = collection
|
||||
}
|
||||
const body: Record<string, unknown> = { query, top_k: topK }
|
||||
if (collection) body.collection = collection
|
||||
|
||||
const res = await fetch(`${RAG_SERVICE_URL}/api/v1/search`, {
|
||||
const res = await fetch(`${SDK_URL}/sdk/v1/rag/search`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-User-ID': DEFAULT_USER,
|
||||
'X-Tenant-ID': DEFAULT_TENANT,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
})
|
||||
@@ -36,15 +51,22 @@ export async function queryRAG(query: string, topK = 3, collection?: string): Pr
|
||||
if (!res.ok) return ''
|
||||
|
||||
const data = await res.json()
|
||||
if (data.results?.length > 0) {
|
||||
return data.results
|
||||
.map(
|
||||
(r: { source_name?: string; source_code?: string; content?: string }, i: number) =>
|
||||
`[Quelle ${i + 1}: ${r.source_name || r.source_code || 'Unbekannt'}]\n${r.content || ''}`
|
||||
)
|
||||
.join('\n\n---\n\n')
|
||||
}
|
||||
return ''
|
||||
const results: SdkRagResult[] = data.results || []
|
||||
if (results.length === 0) return ''
|
||||
|
||||
return results
|
||||
.map((r, i) => {
|
||||
const source =
|
||||
r.regulation_short ||
|
||||
r.regulation_name ||
|
||||
r.regulation_code ||
|
||||
r.source_name ||
|
||||
r.source_code ||
|
||||
'Unbekannt'
|
||||
const content = r.text || r.content || ''
|
||||
return `[Quelle ${i + 1}: ${source}]\n${content}`
|
||||
})
|
||||
.join('\n\n---\n\n')
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user