feat(advisor): Legal-RAG Zitier-Metadaten — ai-sdk + Advisor/Drafting lesen article_label

ai-sdk (legal_rag_client/scroll/types) liest die gepinnten Spec-Felder
article_label/regulation_code/article/paragraph/sub/citation_style/is_recital
mit Fallback auf alt-ingestierte Chunks (regulation_id, section); neuer getBool-Helfer.
Advisor + Drafting-Engine bilden die Quellenzeile primaer aus article_label
("BDSG § 38 Abs. 1"), sonst aus den strukturierten Feldern. 17 Tests gruen, tsc sauber.
Vertrag: docs-src/development/rag_reingest_spec.md (§2/§7). Deploy an den Re-Ingest
gekoppelt — neue Felder sind bis dahin leer (graceful Fallback).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-06-20 14:34:15 +02:00
parent b664d73ffc
commit 017c9b3c12
7 changed files with 198 additions and 7 deletions
@@ -24,6 +24,20 @@ describe('advisor-rag', () => {
expect(out).toEqual([{ content: 'Art. 35 DSGVO ...', source: 'DSGVO', score: 0.91 }])
})
it('haengt article/paragraph an die Quelle an (Fallback ohne article_label)', () => {
const out = mod.mapSdkResults([
{ text: 'Pflicht zur Benennung ...', regulation_short: 'BDSG', article: '§ 38', paragraph: '(1)', score: 0.8 },
])
expect(out).toEqual([{ content: 'Pflicht zur Benennung ...', source: 'BDSG § 38 (1)', score: 0.8 }])
})
it('nutzt article_label direkt, wenn vorhanden (druckbare Fundstelle)', () => {
const out = mod.mapSdkResults([
{ text: 'x', regulation_short: 'BDSG', article: '38', paragraph: '1', sub: 'Satz 2', article_label: 'BDSG § 38 Abs. 1', score: 0.9 },
])
expect(out[0].source).toBe('BDSG § 38 Abs. 1')
})
it('faellt auf regulation_name/code zurueck und filtert leere Inhalte', () => {
const out = mod.mapSdkResults([
{ text: '', regulation_short: 'X' },
+15 -1
View File
@@ -31,6 +31,12 @@ interface SdkRagResult {
regulation_code?: string
regulation_name?: string
regulation_short?: string
article_label?: string
article?: string
paragraph?: string
sub?: string
citation_style?: string
is_recital?: boolean
category?: string
source_url?: string
score?: number
@@ -47,7 +53,15 @@ export function mapSdkResults(results: SdkRagResult[] | undefined): ScoredPassag
return (results || [])
.map((r) => ({
content: r.text || '',
source: r.regulation_short || r.regulation_name || r.regulation_code || 'Unbekannt',
// Fundstelle: article_label ist die fertig formatierte, druckbare Quelle aus der
// Ingestion ("BDSG § 38 Abs. 1"); Fallback baut sie aus den strukturierten Feldern
// (bzw. alt-ingestierte Chunks ohne Legal-Metadaten). Siehe rag_reingest_spec.md §2/§7.
source:
(r.article_label && r.article_label.trim()) ||
[r.regulation_short || r.regulation_name || r.regulation_code, r.article, r.paragraph, r.sub]
.filter(Boolean)
.join(' ') ||
'Unbekannt',
score: typeof r.score === 'number' ? r.score : 0,
}))
.filter((p) => p.content)
@@ -18,6 +18,10 @@ interface SdkRagResult {
regulation_code?: string
regulation_name?: string
regulation_short?: string
article_label?: string
article?: string
paragraph?: string
sub?: string
// Rueckwaerts-kompatibel, falls eine Quelle noch das alte rag-service-Format liefert:
content?: string
source_name?: string
@@ -56,12 +60,13 @@ export async function queryRAG(query: string, topK = 3, collection?: string): Pr
return results
.map((r, i) => {
const base =
r.regulation_short || r.regulation_name || r.regulation_code || r.source_name || r.source_code
// article_label = fertig formatierte Fundstelle aus der Ingestion ("BDSG § 38 Abs. 1");
// Fallback baut sie aus den strukturierten Feldern. Siehe rag_reingest_spec.md §2/§7.
const source =
r.regulation_short ||
r.regulation_name ||
r.regulation_code ||
r.source_name ||
r.source_code ||
(r.article_label && r.article_label.trim()) ||
[base, r.article, r.paragraph, r.sub].filter(Boolean).join(' ') ||
'Unbekannt'
const content = r.text || r.content || ''
return `[Quelle ${i + 1}: ${source}]\n${content}`