All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 35s
CI / test-python-backend-compliance (push) Successful in 26s
CI / test-python-document-crawler (push) Successful in 22s
CI / test-python-dsms-gateway (push) Successful in 19s
Add legal context enrichment from Qdrant vector corpus to the two highest-priority modules (Requirements AI assistant and DSFA drafting engine). Go SDK: - Add SearchCollection() with collection override + whitelist validation - Refactor Search() to delegate to shared searchInternal() Python backend: - New ComplianceRAGClient proxying POST /sdk/v1/rag/search (error-tolerant) - AI assistant: enrich interpret_requirement() and suggest_controls() with RAG - Requirements API: add ?include_legal_context=true query parameter Admin (Next.js): - Extract shared queryRAG() utility from chat route - Inject RAG legal context into v1 and v2 draft pipelines Tests for all three layers (Go, Python, TypeScript shared utility). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
/**
|
|
* Shared RAG query utility for the Drafting Engine.
|
|
*
|
|
* Queries the DSFA RAG corpus via klausur-service for relevant legal context.
|
|
* Used by both chat and draft routes.
|
|
*/
|
|
|
|
const KLAUSUR_SERVICE_URL = process.env.KLAUSUR_SERVICE_URL || 'http://klausur-service:8086'
|
|
|
|
/**
|
|
* Query the RAG corpus for relevant legal documents.
|
|
*
|
|
* @param query - The search query (e.g. "DSFA Art. 35 DSGVO")
|
|
* @param topK - Number of results to return (default: 3)
|
|
* @returns Formatted string of legal context, or empty string on error
|
|
*/
|
|
export async function queryRAG(query: string, topK = 3): Promise<string> {
|
|
try {
|
|
const url = `${KLAUSUR_SERVICE_URL}/api/v1/dsfa-rag/search?query=${encodeURIComponent(query)}&top_k=${topK}`
|
|
const res = await fetch(url, {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
signal: AbortSignal.timeout(10000),
|
|
})
|
|
|
|
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 ''
|
|
} catch {
|
|
return ''
|
|
}
|
|
}
|