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:
@@ -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' },
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user