90a70c8404
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>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
/**
|
|
* Shared RAG query utility for the Drafting Engine.
|
|
*
|
|
* 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 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.
|
|
*
|
|
* @param query - The search query (e.g. "Art. 35 DSGVO Risikobewertung")
|
|
* @param topK - Number of results to return (default: 3)
|
|
* @param collection - Optional RAG collection name (e.g. "bp_dsfa_corpus")
|
|
* @returns Formatted string of legal context, or empty string on error
|
|
*/
|
|
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 res = await fetch(`${SDK_URL}/sdk/v1/rag/search`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-User-ID': DEFAULT_USER,
|
|
'X-Tenant-ID': DEFAULT_TENANT,
|
|
},
|
|
body: JSON.stringify(body),
|
|
signal: AbortSignal.timeout(10000),
|
|
})
|
|
|
|
if (!res.ok) return ''
|
|
|
|
const data = await res.json()
|
|
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 ''
|
|
}
|
|
}
|