@claritylabs/cl-sdk 0.13.1 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +788 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +788 -38
- package/dist/index.mjs.map +1 -1
- package/dist/storage-sqlite.d.mts +1 -1
- package/dist/storage-sqlite.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2455,7 +2455,20 @@ async function formatDocumentContent(doc, generateText, options) {
|
|
|
2455
2455
|
}
|
|
2456
2456
|
|
|
2457
2457
|
// src/extraction/chunking.ts
|
|
2458
|
+
function formatAddress(addr) {
|
|
2459
|
+
const parts = [addr.street1, addr.street2, addr.city, addr.state, addr.zip, addr.country].filter(Boolean);
|
|
2460
|
+
return parts.join(", ");
|
|
2461
|
+
}
|
|
2458
2462
|
function chunkDocument(doc) {
|
|
2463
|
+
const ensureArray = (v) => Array.isArray(v) ? v : [];
|
|
2464
|
+
doc = {
|
|
2465
|
+
...doc,
|
|
2466
|
+
taxesAndFees: ensureArray(doc.taxesAndFees),
|
|
2467
|
+
ratingBasis: ensureArray(doc.ratingBasis),
|
|
2468
|
+
claimsContacts: ensureArray(doc.claimsContacts),
|
|
2469
|
+
regulatoryContacts: ensureArray(doc.regulatoryContacts),
|
|
2470
|
+
thirdPartyAdministrators: ensureArray(doc.thirdPartyAdministrators)
|
|
2471
|
+
};
|
|
2459
2472
|
const chunks = [];
|
|
2460
2473
|
const docId = doc.id;
|
|
2461
2474
|
function stringMetadata(entries) {
|
|
@@ -2472,10 +2485,101 @@ function chunkDocument(doc) {
|
|
|
2472
2485
|
doc.carrierLegalName ? `Legal Name: ${doc.carrierLegalName}` : null,
|
|
2473
2486
|
doc.carrierNaicNumber ? `NAIC: ${doc.carrierNaicNumber}` : null,
|
|
2474
2487
|
doc.carrierAmBestRating ? `AM Best: ${doc.carrierAmBestRating}` : null,
|
|
2475
|
-
doc.
|
|
2488
|
+
doc.carrierAdmittedStatus ? `Admitted Status: ${doc.carrierAdmittedStatus}` : null,
|
|
2489
|
+
doc.mga ? `MGA: ${doc.mga}` : null,
|
|
2490
|
+
doc.underwriter ? `Underwriter: ${doc.underwriter}` : null,
|
|
2491
|
+
doc.brokerAgency ? `Broker: ${doc.brokerAgency}` : null,
|
|
2492
|
+
doc.brokerContactName ? `Broker Contact: ${doc.brokerContactName}` : null,
|
|
2493
|
+
doc.brokerLicenseNumber ? `Broker License: ${doc.brokerLicenseNumber}` : null,
|
|
2494
|
+
doc.programName ? `Program: ${doc.programName}` : null,
|
|
2495
|
+
doc.priorPolicyNumber ? `Prior Policy: ${doc.priorPolicyNumber}` : null,
|
|
2496
|
+
doc.isRenewal != null ? `Renewal: ${doc.isRenewal ? "Yes" : "No"}` : null,
|
|
2497
|
+
doc.isPackage != null ? `Package: ${doc.isPackage ? "Yes" : "No"}` : null,
|
|
2498
|
+
doc.security ? `Security: ${doc.security}` : null,
|
|
2499
|
+
doc.policyTypes?.length ? `Policy Types: ${doc.policyTypes.join(", ")}` : null
|
|
2476
2500
|
].filter(Boolean).join("\n"),
|
|
2477
2501
|
metadata: stringMetadata({ carrier: doc.carrier, documentType: doc.type })
|
|
2478
2502
|
});
|
|
2503
|
+
if (doc.summary) {
|
|
2504
|
+
chunks.push({
|
|
2505
|
+
id: `${docId}:declaration:summary`,
|
|
2506
|
+
documentId: docId,
|
|
2507
|
+
type: "declaration",
|
|
2508
|
+
text: `Policy Summary: ${doc.summary}`,
|
|
2509
|
+
metadata: stringMetadata({ documentType: doc.type })
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
if (doc.type === "policy") {
|
|
2513
|
+
const pol = doc;
|
|
2514
|
+
chunks.push({
|
|
2515
|
+
id: `${docId}:declaration:policy_details`,
|
|
2516
|
+
documentId: docId,
|
|
2517
|
+
type: "declaration",
|
|
2518
|
+
text: [
|
|
2519
|
+
`Policy Number: ${pol.policyNumber}`,
|
|
2520
|
+
`Effective Date: ${pol.effectiveDate}`,
|
|
2521
|
+
pol.expirationDate ? `Expiration Date: ${pol.expirationDate}` : null,
|
|
2522
|
+
pol.policyTermType ? `Term Type: ${pol.policyTermType}` : null,
|
|
2523
|
+
pol.effectiveTime ? `Effective Time: ${pol.effectiveTime}` : null,
|
|
2524
|
+
pol.nextReviewDate ? `Next Review Date: ${pol.nextReviewDate}` : null
|
|
2525
|
+
].filter(Boolean).join("\n"),
|
|
2526
|
+
metadata: stringMetadata({
|
|
2527
|
+
policyNumber: pol.policyNumber,
|
|
2528
|
+
effectiveDate: pol.effectiveDate,
|
|
2529
|
+
expirationDate: pol.expirationDate,
|
|
2530
|
+
documentType: doc.type
|
|
2531
|
+
})
|
|
2532
|
+
});
|
|
2533
|
+
} else {
|
|
2534
|
+
const quote = doc;
|
|
2535
|
+
chunks.push({
|
|
2536
|
+
id: `${docId}:declaration:quote_details`,
|
|
2537
|
+
documentId: docId,
|
|
2538
|
+
type: "declaration",
|
|
2539
|
+
text: [
|
|
2540
|
+
`Quote Number: ${quote.quoteNumber}`,
|
|
2541
|
+
quote.proposedEffectiveDate ? `Proposed Effective Date: ${quote.proposedEffectiveDate}` : null,
|
|
2542
|
+
quote.proposedExpirationDate ? `Proposed Expiration Date: ${quote.proposedExpirationDate}` : null,
|
|
2543
|
+
quote.quoteExpirationDate ? `Quote Expiration Date: ${quote.quoteExpirationDate}` : null
|
|
2544
|
+
].filter(Boolean).join("\n"),
|
|
2545
|
+
metadata: stringMetadata({
|
|
2546
|
+
quoteNumber: quote.quoteNumber,
|
|
2547
|
+
documentType: doc.type
|
|
2548
|
+
})
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
if (doc.insurer) {
|
|
2552
|
+
chunks.push({
|
|
2553
|
+
id: `${docId}:party:insurer`,
|
|
2554
|
+
documentId: docId,
|
|
2555
|
+
type: "party",
|
|
2556
|
+
text: [
|
|
2557
|
+
`Insurer: ${doc.insurer.legalName}`,
|
|
2558
|
+
doc.insurer.naicNumber ? `NAIC: ${doc.insurer.naicNumber}` : null,
|
|
2559
|
+
doc.insurer.amBestRating ? `AM Best Rating: ${doc.insurer.amBestRating}` : null,
|
|
2560
|
+
doc.insurer.amBestNumber ? `AM Best Number: ${doc.insurer.amBestNumber}` : null,
|
|
2561
|
+
doc.insurer.admittedStatus ? `Admitted Status: ${doc.insurer.admittedStatus}` : null,
|
|
2562
|
+
doc.insurer.stateOfDomicile ? `State of Domicile: ${doc.insurer.stateOfDomicile}` : null
|
|
2563
|
+
].filter(Boolean).join("\n"),
|
|
2564
|
+
metadata: stringMetadata({ partyRole: "insurer", partyName: doc.insurer.legalName, documentType: doc.type })
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
if (doc.producer) {
|
|
2568
|
+
chunks.push({
|
|
2569
|
+
id: `${docId}:party:producer`,
|
|
2570
|
+
documentId: docId,
|
|
2571
|
+
type: "party",
|
|
2572
|
+
text: [
|
|
2573
|
+
`Producer/Broker: ${doc.producer.agencyName}`,
|
|
2574
|
+
doc.producer.contactName ? `Contact: ${doc.producer.contactName}` : null,
|
|
2575
|
+
doc.producer.licenseNumber ? `License: ${doc.producer.licenseNumber}` : null,
|
|
2576
|
+
doc.producer.phone ? `Phone: ${doc.producer.phone}` : null,
|
|
2577
|
+
doc.producer.email ? `Email: ${doc.producer.email}` : null,
|
|
2578
|
+
doc.producer.address ? `Address: ${formatAddress(doc.producer.address)}` : null
|
|
2579
|
+
].filter(Boolean).join("\n"),
|
|
2580
|
+
metadata: stringMetadata({ partyRole: "producer", partyName: doc.producer.agencyName, documentType: doc.type })
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2479
2583
|
chunks.push({
|
|
2480
2584
|
id: `${docId}:named_insured:0`,
|
|
2481
2585
|
documentId: docId,
|
|
@@ -2483,11 +2587,27 @@ function chunkDocument(doc) {
|
|
|
2483
2587
|
text: [
|
|
2484
2588
|
`Insured: ${doc.insuredName}`,
|
|
2485
2589
|
doc.insuredDba ? `DBA: ${doc.insuredDba}` : null,
|
|
2590
|
+
doc.insuredEntityType ? `Entity Type: ${doc.insuredEntityType}` : null,
|
|
2486
2591
|
doc.insuredFein ? `FEIN: ${doc.insuredFein}` : null,
|
|
2487
|
-
doc.
|
|
2592
|
+
doc.insuredSicCode ? `SIC: ${doc.insuredSicCode}` : null,
|
|
2593
|
+
doc.insuredNaicsCode ? `NAICS: ${doc.insuredNaicsCode}` : null,
|
|
2594
|
+
doc.insuredAddress ? `Address: ${formatAddress(doc.insuredAddress)}` : null
|
|
2488
2595
|
].filter(Boolean).join("\n"),
|
|
2489
2596
|
metadata: stringMetadata({ insuredName: doc.insuredName, documentType: doc.type })
|
|
2490
2597
|
});
|
|
2598
|
+
doc.additionalNamedInsureds?.forEach((insured, i) => {
|
|
2599
|
+
chunks.push({
|
|
2600
|
+
id: `${docId}:named_insured:${i + 1}`,
|
|
2601
|
+
documentId: docId,
|
|
2602
|
+
type: "named_insured",
|
|
2603
|
+
text: [
|
|
2604
|
+
`Additional Named Insured: ${insured.name}`,
|
|
2605
|
+
insured.address ? `Address: ${formatAddress(insured.address)}` : null,
|
|
2606
|
+
insured.relationship ? `Relationship: ${insured.relationship}` : null
|
|
2607
|
+
].filter(Boolean).join("\n"),
|
|
2608
|
+
metadata: stringMetadata({ insuredName: insured.name, role: "additional_named_insured", documentType: doc.type })
|
|
2609
|
+
});
|
|
2610
|
+
});
|
|
2491
2611
|
doc.coverages.forEach((cov, i) => {
|
|
2492
2612
|
chunks.push({
|
|
2493
2613
|
id: `${docId}:coverage:${i}`,
|
|
@@ -2514,6 +2634,153 @@ function chunkDocument(doc) {
|
|
|
2514
2634
|
})
|
|
2515
2635
|
});
|
|
2516
2636
|
});
|
|
2637
|
+
doc.enrichedCoverages?.forEach((cov, i) => {
|
|
2638
|
+
chunks.push({
|
|
2639
|
+
id: `${docId}:coverage:enriched:${i}`,
|
|
2640
|
+
documentId: docId,
|
|
2641
|
+
type: "coverage",
|
|
2642
|
+
text: [
|
|
2643
|
+
`Coverage: ${cov.name}`,
|
|
2644
|
+
cov.coverageCode ? `Code: ${cov.coverageCode}` : null,
|
|
2645
|
+
`Limit: ${cov.limit}`,
|
|
2646
|
+
cov.limitType ? `Limit Type: ${cov.limitType}` : null,
|
|
2647
|
+
cov.deductible ? `Deductible: ${cov.deductible}` : null,
|
|
2648
|
+
cov.deductibleType ? `Deductible Type: ${cov.deductibleType}` : null,
|
|
2649
|
+
cov.sir ? `SIR: ${cov.sir}` : null,
|
|
2650
|
+
cov.sublimit ? `Sublimit: ${cov.sublimit}` : null,
|
|
2651
|
+
cov.coinsurance ? `Coinsurance: ${cov.coinsurance}` : null,
|
|
2652
|
+
cov.valuation ? `Valuation: ${cov.valuation}` : null,
|
|
2653
|
+
cov.territory ? `Territory: ${cov.territory}` : null,
|
|
2654
|
+
cov.trigger ? `Trigger: ${cov.trigger}` : null,
|
|
2655
|
+
cov.retroactiveDate ? `Retroactive Date: ${cov.retroactiveDate}` : null,
|
|
2656
|
+
`Included: ${cov.included ? "Yes" : "No"}`,
|
|
2657
|
+
cov.premium ? `Premium: ${cov.premium}` : null,
|
|
2658
|
+
cov.originalContent ? `Source: ${cov.originalContent}` : null
|
|
2659
|
+
].filter(Boolean).join("\n"),
|
|
2660
|
+
metadata: stringMetadata({
|
|
2661
|
+
coverageName: cov.name,
|
|
2662
|
+
coverageCode: cov.coverageCode,
|
|
2663
|
+
limit: cov.limit,
|
|
2664
|
+
deductible: cov.deductible,
|
|
2665
|
+
formNumber: cov.formNumber,
|
|
2666
|
+
pageNumber: cov.pageNumber,
|
|
2667
|
+
included: cov.included,
|
|
2668
|
+
documentType: doc.type
|
|
2669
|
+
})
|
|
2670
|
+
});
|
|
2671
|
+
});
|
|
2672
|
+
if (doc.limits) {
|
|
2673
|
+
const limitLines = ["Limit Schedule"];
|
|
2674
|
+
const lim = doc.limits;
|
|
2675
|
+
if (lim.perOccurrence) limitLines.push(`Per Occurrence: ${lim.perOccurrence}`);
|
|
2676
|
+
if (lim.generalAggregate) limitLines.push(`General Aggregate: ${lim.generalAggregate}`);
|
|
2677
|
+
if (lim.productsCompletedOpsAggregate) limitLines.push(`Products/Completed Ops Aggregate: ${lim.productsCompletedOpsAggregate}`);
|
|
2678
|
+
if (lim.personalAdvertisingInjury) limitLines.push(`Personal & Advertising Injury: ${lim.personalAdvertisingInjury}`);
|
|
2679
|
+
if (lim.eachEmployee) limitLines.push(`Each Employee: ${lim.eachEmployee}`);
|
|
2680
|
+
if (lim.fireDamage) limitLines.push(`Fire Damage: ${lim.fireDamage}`);
|
|
2681
|
+
if (lim.medicalExpense) limitLines.push(`Medical Expense: ${lim.medicalExpense}`);
|
|
2682
|
+
if (lim.combinedSingleLimit) limitLines.push(`Combined Single Limit: ${lim.combinedSingleLimit}`);
|
|
2683
|
+
if (lim.bodilyInjuryPerPerson) limitLines.push(`Bodily Injury Per Person: ${lim.bodilyInjuryPerPerson}`);
|
|
2684
|
+
if (lim.bodilyInjuryPerAccident) limitLines.push(`Bodily Injury Per Accident: ${lim.bodilyInjuryPerAccident}`);
|
|
2685
|
+
if (lim.propertyDamage) limitLines.push(`Property Damage: ${lim.propertyDamage}`);
|
|
2686
|
+
if (lim.eachOccurrenceUmbrella) limitLines.push(`Umbrella Each Occurrence: ${lim.eachOccurrenceUmbrella}`);
|
|
2687
|
+
if (lim.umbrellaAggregate) limitLines.push(`Umbrella Aggregate: ${lim.umbrellaAggregate}`);
|
|
2688
|
+
if (lim.umbrellaRetention) limitLines.push(`Umbrella Retention: ${lim.umbrellaRetention}`);
|
|
2689
|
+
if (lim.statutory) limitLines.push(`Statutory: Yes`);
|
|
2690
|
+
if (lim.employersLiability) {
|
|
2691
|
+
limitLines.push(`Employers Liability \u2014 Each Accident: ${lim.employersLiability.eachAccident}, Disease Policy Limit: ${lim.employersLiability.diseasePolicyLimit}, Disease Each Employee: ${lim.employersLiability.diseaseEachEmployee}`);
|
|
2692
|
+
}
|
|
2693
|
+
if (lim.defenseCostTreatment) limitLines.push(`Defense Cost Treatment: ${lim.defenseCostTreatment}`);
|
|
2694
|
+
chunks.push({
|
|
2695
|
+
id: `${docId}:coverage:limit_schedule`,
|
|
2696
|
+
documentId: docId,
|
|
2697
|
+
type: "coverage",
|
|
2698
|
+
text: limitLines.join("\n"),
|
|
2699
|
+
metadata: stringMetadata({ coverageName: "limit_schedule", documentType: doc.type })
|
|
2700
|
+
});
|
|
2701
|
+
lim.sublimits?.forEach((sub, i) => {
|
|
2702
|
+
chunks.push({
|
|
2703
|
+
id: `${docId}:coverage:sublimit:${i}`,
|
|
2704
|
+
documentId: docId,
|
|
2705
|
+
type: "coverage",
|
|
2706
|
+
text: [
|
|
2707
|
+
`Sublimit: ${sub.name}`,
|
|
2708
|
+
`Limit: ${sub.limit}`,
|
|
2709
|
+
sub.appliesTo ? `Applies To: ${sub.appliesTo}` : null,
|
|
2710
|
+
sub.deductible ? `Deductible: ${sub.deductible}` : null
|
|
2711
|
+
].filter(Boolean).join("\n"),
|
|
2712
|
+
metadata: stringMetadata({ coverageName: sub.name, limit: sub.limit, documentType: doc.type })
|
|
2713
|
+
});
|
|
2714
|
+
});
|
|
2715
|
+
lim.sharedLimits?.forEach((sl, i) => {
|
|
2716
|
+
chunks.push({
|
|
2717
|
+
id: `${docId}:coverage:shared_limit:${i}`,
|
|
2718
|
+
documentId: docId,
|
|
2719
|
+
type: "coverage",
|
|
2720
|
+
text: [
|
|
2721
|
+
`Shared Limit: ${sl.description}`,
|
|
2722
|
+
`Limit: ${sl.limit}`,
|
|
2723
|
+
`Coverage Parts: ${sl.coverageParts.join(", ")}`
|
|
2724
|
+
].join("\n"),
|
|
2725
|
+
metadata: stringMetadata({ coverageName: sl.description, limit: sl.limit, documentType: doc.type })
|
|
2726
|
+
});
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
if (doc.deductibles) {
|
|
2730
|
+
const dedLines = ["Deductible Schedule"];
|
|
2731
|
+
const ded = doc.deductibles;
|
|
2732
|
+
if (ded.perClaim) dedLines.push(`Per Claim: ${ded.perClaim}`);
|
|
2733
|
+
if (ded.perOccurrence) dedLines.push(`Per Occurrence: ${ded.perOccurrence}`);
|
|
2734
|
+
if (ded.aggregateDeductible) dedLines.push(`Aggregate: ${ded.aggregateDeductible}`);
|
|
2735
|
+
if (ded.selfInsuredRetention) dedLines.push(`Self-Insured Retention: ${ded.selfInsuredRetention}`);
|
|
2736
|
+
if (ded.corridorDeductible) dedLines.push(`Corridor: ${ded.corridorDeductible}`);
|
|
2737
|
+
if (ded.waitingPeriod) dedLines.push(`Waiting Period: ${ded.waitingPeriod}`);
|
|
2738
|
+
if (ded.appliesTo) dedLines.push(`Applies To: ${ded.appliesTo}`);
|
|
2739
|
+
if (dedLines.length > 1) {
|
|
2740
|
+
chunks.push({
|
|
2741
|
+
id: `${docId}:coverage:deductible_schedule`,
|
|
2742
|
+
documentId: docId,
|
|
2743
|
+
type: "coverage",
|
|
2744
|
+
text: dedLines.join("\n"),
|
|
2745
|
+
metadata: stringMetadata({ coverageName: "deductible_schedule", documentType: doc.type })
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
const claimsMadeLines = [
|
|
2750
|
+
doc.coverageForm ? `Coverage Form: ${doc.coverageForm}` : null,
|
|
2751
|
+
doc.retroactiveDate ? `Retroactive Date: ${doc.retroactiveDate}` : null,
|
|
2752
|
+
doc.extendedReportingPeriod?.basicDays ? `Extended Reporting Period (Basic): ${doc.extendedReportingPeriod.basicDays} days` : null,
|
|
2753
|
+
doc.extendedReportingPeriod?.supplementalYears ? `Extended Reporting Period (Supplemental): ${doc.extendedReportingPeriod.supplementalYears} years` : null,
|
|
2754
|
+
doc.extendedReportingPeriod?.supplementalPremium ? `Extended Reporting Period Premium: ${doc.extendedReportingPeriod.supplementalPremium}` : null
|
|
2755
|
+
].filter(Boolean);
|
|
2756
|
+
if (claimsMadeLines.length > 0) {
|
|
2757
|
+
chunks.push({
|
|
2758
|
+
id: `${docId}:coverage:claims_made_details`,
|
|
2759
|
+
documentId: docId,
|
|
2760
|
+
type: "coverage",
|
|
2761
|
+
text: claimsMadeLines.join("\n"),
|
|
2762
|
+
metadata: stringMetadata({ coverageName: "claims_made_details", documentType: doc.type })
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
doc.formInventory?.forEach((form, i) => {
|
|
2766
|
+
chunks.push({
|
|
2767
|
+
id: `${docId}:declaration:form:${i}`,
|
|
2768
|
+
documentId: docId,
|
|
2769
|
+
type: "declaration",
|
|
2770
|
+
text: [
|
|
2771
|
+
`Form: ${form.formNumber}`,
|
|
2772
|
+
form.title ? `Title: ${form.title}` : null,
|
|
2773
|
+
`Type: ${form.formType}`,
|
|
2774
|
+
form.editionDate ? `Edition: ${form.editionDate}` : null,
|
|
2775
|
+
form.pageStart ? `Pages: ${form.pageStart}${form.pageEnd ? `-${form.pageEnd}` : ""}` : null
|
|
2776
|
+
].filter(Boolean).join("\n"),
|
|
2777
|
+
metadata: stringMetadata({
|
|
2778
|
+
formNumber: form.formNumber,
|
|
2779
|
+
formType: form.formType,
|
|
2780
|
+
documentType: doc.type
|
|
2781
|
+
})
|
|
2782
|
+
});
|
|
2783
|
+
});
|
|
2517
2784
|
doc.endorsements?.forEach((end, i) => {
|
|
2518
2785
|
chunks.push({
|
|
2519
2786
|
id: `${docId}:endorsement:${i}`,
|
|
@@ -2540,63 +2807,546 @@ ${exc.content}`.trim(),
|
|
|
2540
2807
|
metadata: stringMetadata({ formNumber: exc.formNumber, pageNumber: exc.pageNumber, documentType: doc.type })
|
|
2541
2808
|
});
|
|
2542
2809
|
});
|
|
2543
|
-
doc.
|
|
2810
|
+
doc.conditions?.forEach((cond, i) => {
|
|
2544
2811
|
chunks.push({
|
|
2545
|
-
id: `${docId}:
|
|
2812
|
+
id: `${docId}:condition:${i}`,
|
|
2546
2813
|
documentId: docId,
|
|
2547
|
-
type: "
|
|
2548
|
-
text:
|
|
2814
|
+
type: "condition",
|
|
2815
|
+
text: [
|
|
2816
|
+
`Condition: ${cond.name}`,
|
|
2817
|
+
`Type: ${cond.conditionType}`,
|
|
2818
|
+
cond.content,
|
|
2819
|
+
...cond.keyValues?.map((kv) => `${kv.key}: ${kv.value}`) ?? []
|
|
2820
|
+
].join("\n"),
|
|
2821
|
+
metadata: stringMetadata({
|
|
2822
|
+
conditionName: cond.name,
|
|
2823
|
+
conditionType: cond.conditionType,
|
|
2824
|
+
pageNumber: cond.pageNumber,
|
|
2825
|
+
documentType: doc.type
|
|
2826
|
+
})
|
|
2827
|
+
});
|
|
2828
|
+
});
|
|
2829
|
+
if (doc.declarations) {
|
|
2830
|
+
const decl = doc.declarations;
|
|
2831
|
+
const declLines = [];
|
|
2832
|
+
for (const [key, value] of Object.entries(decl)) {
|
|
2833
|
+
if (value && typeof value === "string") {
|
|
2834
|
+
declLines.push(`${key}: ${value}`);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
if (declLines.length > 0) {
|
|
2838
|
+
chunks.push({
|
|
2839
|
+
id: `${docId}:declaration:0`,
|
|
2840
|
+
documentId: docId,
|
|
2841
|
+
type: "declaration",
|
|
2842
|
+
text: `Declarations
|
|
2843
|
+
${declLines.join("\n")}`,
|
|
2844
|
+
metadata: stringMetadata({ documentType: doc.type })
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
doc.sections?.forEach((sec, i) => {
|
|
2849
|
+
const hasSubsections = sec.subsections && sec.subsections.length > 0;
|
|
2850
|
+
const contentLength = sec.content.length;
|
|
2851
|
+
if (hasSubsections) {
|
|
2852
|
+
chunks.push({
|
|
2853
|
+
id: `${docId}:section:${i}`,
|
|
2854
|
+
documentId: docId,
|
|
2855
|
+
type: "section",
|
|
2856
|
+
text: `Section: ${sec.title}
|
|
2857
|
+
${sec.content}`,
|
|
2858
|
+
metadata: stringMetadata({
|
|
2859
|
+
sectionType: sec.type,
|
|
2860
|
+
sectionNumber: sec.sectionNumber,
|
|
2861
|
+
pageStart: sec.pageStart,
|
|
2862
|
+
pageEnd: sec.pageEnd,
|
|
2863
|
+
documentType: doc.type,
|
|
2864
|
+
hasSubsections: "true"
|
|
2865
|
+
})
|
|
2866
|
+
});
|
|
2867
|
+
sec.subsections.forEach((sub, j) => {
|
|
2868
|
+
chunks.push({
|
|
2869
|
+
id: `${docId}:section:${i}:sub:${j}`,
|
|
2870
|
+
documentId: docId,
|
|
2871
|
+
type: "section",
|
|
2872
|
+
text: `${sec.title} > ${sub.title}
|
|
2873
|
+
${sub.content}`,
|
|
2874
|
+
metadata: stringMetadata({
|
|
2875
|
+
sectionType: sec.type,
|
|
2876
|
+
parentSection: sec.title,
|
|
2877
|
+
sectionNumber: sub.sectionNumber,
|
|
2878
|
+
pageNumber: sub.pageNumber,
|
|
2879
|
+
documentType: doc.type
|
|
2880
|
+
})
|
|
2881
|
+
});
|
|
2882
|
+
});
|
|
2883
|
+
} else if (contentLength > 2e3) {
|
|
2884
|
+
const paragraphs = sec.content.split(/\n\n+/);
|
|
2885
|
+
let currentChunk = "";
|
|
2886
|
+
let chunkIndex = 0;
|
|
2887
|
+
for (const para of paragraphs) {
|
|
2888
|
+
if (currentChunk.length + para.length > 1e3 && currentChunk.length > 0) {
|
|
2889
|
+
chunks.push({
|
|
2890
|
+
id: `${docId}:section:${i}:part:${chunkIndex}`,
|
|
2891
|
+
documentId: docId,
|
|
2892
|
+
type: "section",
|
|
2893
|
+
text: `Section: ${sec.title} (part ${chunkIndex + 1})
|
|
2894
|
+
${currentChunk.trim()}`,
|
|
2895
|
+
metadata: stringMetadata({
|
|
2896
|
+
sectionType: sec.type,
|
|
2897
|
+
sectionNumber: sec.sectionNumber,
|
|
2898
|
+
pageStart: sec.pageStart,
|
|
2899
|
+
pageEnd: sec.pageEnd,
|
|
2900
|
+
documentType: doc.type,
|
|
2901
|
+
partIndex: chunkIndex
|
|
2902
|
+
})
|
|
2903
|
+
});
|
|
2904
|
+
currentChunk = "";
|
|
2905
|
+
chunkIndex++;
|
|
2906
|
+
}
|
|
2907
|
+
currentChunk += (currentChunk ? "\n\n" : "") + para;
|
|
2908
|
+
}
|
|
2909
|
+
if (currentChunk.trim()) {
|
|
2910
|
+
chunks.push({
|
|
2911
|
+
id: `${docId}:section:${i}:part:${chunkIndex}`,
|
|
2912
|
+
documentId: docId,
|
|
2913
|
+
type: "section",
|
|
2914
|
+
text: `Section: ${sec.title} (part ${chunkIndex + 1})
|
|
2915
|
+
${currentChunk.trim()}`,
|
|
2916
|
+
metadata: stringMetadata({
|
|
2917
|
+
sectionType: sec.type,
|
|
2918
|
+
sectionNumber: sec.sectionNumber,
|
|
2919
|
+
pageStart: sec.pageStart,
|
|
2920
|
+
pageEnd: sec.pageEnd,
|
|
2921
|
+
documentType: doc.type,
|
|
2922
|
+
partIndex: chunkIndex
|
|
2923
|
+
})
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
} else {
|
|
2927
|
+
chunks.push({
|
|
2928
|
+
id: `${docId}:section:${i}`,
|
|
2929
|
+
documentId: docId,
|
|
2930
|
+
type: "section",
|
|
2931
|
+
text: `Section: ${sec.title}
|
|
2549
2932
|
${sec.content}`,
|
|
2550
|
-
|
|
2933
|
+
metadata: stringMetadata({
|
|
2934
|
+
sectionType: sec.type,
|
|
2935
|
+
sectionNumber: sec.sectionNumber,
|
|
2936
|
+
pageStart: sec.pageStart,
|
|
2937
|
+
pageEnd: sec.pageEnd,
|
|
2938
|
+
documentType: doc.type
|
|
2939
|
+
})
|
|
2940
|
+
});
|
|
2941
|
+
}
|
|
2942
|
+
});
|
|
2943
|
+
doc.locations?.forEach((loc, i) => {
|
|
2944
|
+
chunks.push({
|
|
2945
|
+
id: `${docId}:location:${i}`,
|
|
2946
|
+
documentId: docId,
|
|
2947
|
+
type: "location",
|
|
2948
|
+
text: [
|
|
2949
|
+
`Location ${loc.number}: ${formatAddress(loc.address)}`,
|
|
2950
|
+
loc.description ? `Description: ${loc.description}` : null,
|
|
2951
|
+
loc.occupancy ? `Occupancy: ${loc.occupancy}` : null,
|
|
2952
|
+
loc.constructionType ? `Construction: ${loc.constructionType}` : null,
|
|
2953
|
+
loc.yearBuilt ? `Year Built: ${loc.yearBuilt}` : null,
|
|
2954
|
+
loc.squareFootage ? `Square Footage: ${loc.squareFootage}` : null,
|
|
2955
|
+
loc.protectionClass ? `Protection Class: ${loc.protectionClass}` : null,
|
|
2956
|
+
loc.sprinklered != null ? `Sprinklered: ${loc.sprinklered ? "Yes" : "No"}` : null,
|
|
2957
|
+
loc.alarmType ? `Alarm: ${loc.alarmType}` : null,
|
|
2958
|
+
loc.buildingValue ? `Building Value: ${loc.buildingValue}` : null,
|
|
2959
|
+
loc.contentsValue ? `Contents Value: ${loc.contentsValue}` : null,
|
|
2960
|
+
loc.businessIncomeValue ? `Business Income Value: ${loc.businessIncomeValue}` : null
|
|
2961
|
+
].filter(Boolean).join("\n"),
|
|
2962
|
+
metadata: stringMetadata({
|
|
2963
|
+
locationNumber: loc.number,
|
|
2964
|
+
occupancy: loc.occupancy,
|
|
2965
|
+
constructionType: loc.constructionType,
|
|
2966
|
+
documentType: doc.type
|
|
2967
|
+
})
|
|
2968
|
+
});
|
|
2969
|
+
});
|
|
2970
|
+
doc.vehicles?.forEach((veh, i) => {
|
|
2971
|
+
const vehicleDesc = `${veh.year} ${veh.make} ${veh.model}`;
|
|
2972
|
+
chunks.push({
|
|
2973
|
+
id: `${docId}:vehicle:${i}`,
|
|
2974
|
+
documentId: docId,
|
|
2975
|
+
type: "vehicle",
|
|
2976
|
+
text: [
|
|
2977
|
+
`Vehicle ${veh.number}: ${vehicleDesc}`,
|
|
2978
|
+
`VIN: ${veh.vin}`,
|
|
2979
|
+
veh.vehicleType ? `Type: ${veh.vehicleType}` : null,
|
|
2980
|
+
veh.costNew ? `Cost New: ${veh.costNew}` : null,
|
|
2981
|
+
veh.statedValue ? `Stated Value: ${veh.statedValue}` : null,
|
|
2982
|
+
veh.garageLocation ? `Garage Location: ${veh.garageLocation}` : null,
|
|
2983
|
+
veh.radius ? `Radius: ${veh.radius}` : null,
|
|
2984
|
+
...veh.coverages?.map(
|
|
2985
|
+
(vc) => `${vc.type}: ${[vc.limit && `Limit ${vc.limit}`, vc.deductible && `Ded ${vc.deductible}`, vc.included ? "Included" : "Excluded"].filter(Boolean).join(", ")}`
|
|
2986
|
+
) ?? []
|
|
2987
|
+
].filter(Boolean).join("\n"),
|
|
2988
|
+
metadata: stringMetadata({
|
|
2989
|
+
vehicleNumber: veh.number,
|
|
2990
|
+
vehicleYear: veh.year,
|
|
2991
|
+
vehicleMake: veh.make,
|
|
2992
|
+
vehicleModel: veh.model,
|
|
2993
|
+
vin: veh.vin,
|
|
2994
|
+
documentType: doc.type
|
|
2995
|
+
})
|
|
2996
|
+
});
|
|
2997
|
+
});
|
|
2998
|
+
doc.classifications?.forEach((cls, i) => {
|
|
2999
|
+
chunks.push({
|
|
3000
|
+
id: `${docId}:classification:${i}`,
|
|
3001
|
+
documentId: docId,
|
|
3002
|
+
type: "classification",
|
|
3003
|
+
text: [
|
|
3004
|
+
`Classification: ${cls.code} \u2014 ${cls.description}`,
|
|
3005
|
+
`Premium Basis: ${cls.premiumBasis}`,
|
|
3006
|
+
cls.basisAmount ? `Basis Amount: ${cls.basisAmount}` : null,
|
|
3007
|
+
cls.rate ? `Rate: ${cls.rate}` : null,
|
|
3008
|
+
cls.premium ? `Premium: ${cls.premium}` : null,
|
|
3009
|
+
cls.locationNumber ? `Location: ${cls.locationNumber}` : null
|
|
3010
|
+
].filter(Boolean).join("\n"),
|
|
3011
|
+
metadata: stringMetadata({
|
|
3012
|
+
classCode: cls.code,
|
|
3013
|
+
classDescription: cls.description,
|
|
3014
|
+
locationNumber: cls.locationNumber,
|
|
3015
|
+
documentType: doc.type
|
|
3016
|
+
})
|
|
3017
|
+
});
|
|
3018
|
+
});
|
|
3019
|
+
doc.additionalInsureds?.forEach((party, i) => {
|
|
3020
|
+
chunks.push({
|
|
3021
|
+
id: `${docId}:party:additional_insured:${i}`,
|
|
3022
|
+
documentId: docId,
|
|
3023
|
+
type: "party",
|
|
3024
|
+
text: [
|
|
3025
|
+
`Additional Insured: ${party.name}`,
|
|
3026
|
+
`Role: ${party.role}`,
|
|
3027
|
+
party.relationship ? `Relationship: ${party.relationship}` : null,
|
|
3028
|
+
party.scope ? `Scope: ${party.scope}` : null,
|
|
3029
|
+
party.address ? `Address: ${formatAddress(party.address)}` : null
|
|
3030
|
+
].filter(Boolean).join("\n"),
|
|
3031
|
+
metadata: stringMetadata({ partyRole: "additional_insured", partyName: party.name, documentType: doc.type })
|
|
3032
|
+
});
|
|
3033
|
+
});
|
|
3034
|
+
doc.lossPayees?.forEach((party, i) => {
|
|
3035
|
+
chunks.push({
|
|
3036
|
+
id: `${docId}:party:loss_payee:${i}`,
|
|
3037
|
+
documentId: docId,
|
|
3038
|
+
type: "party",
|
|
3039
|
+
text: [
|
|
3040
|
+
`Loss Payee: ${party.name}`,
|
|
3041
|
+
party.relationship ? `Relationship: ${party.relationship}` : null,
|
|
3042
|
+
party.scope ? `Scope: ${party.scope}` : null,
|
|
3043
|
+
party.address ? `Address: ${formatAddress(party.address)}` : null
|
|
3044
|
+
].filter(Boolean).join("\n"),
|
|
3045
|
+
metadata: stringMetadata({ partyRole: "loss_payee", partyName: party.name, documentType: doc.type })
|
|
3046
|
+
});
|
|
3047
|
+
});
|
|
3048
|
+
doc.mortgageHolders?.forEach((party, i) => {
|
|
3049
|
+
chunks.push({
|
|
3050
|
+
id: `${docId}:party:mortgage_holder:${i}`,
|
|
3051
|
+
documentId: docId,
|
|
3052
|
+
type: "party",
|
|
3053
|
+
text: [
|
|
3054
|
+
`Mortgage Holder: ${party.name}`,
|
|
3055
|
+
party.relationship ? `Relationship: ${party.relationship}` : null,
|
|
3056
|
+
party.scope ? `Scope: ${party.scope}` : null,
|
|
3057
|
+
party.address ? `Address: ${formatAddress(party.address)}` : null
|
|
3058
|
+
].filter(Boolean).join("\n"),
|
|
3059
|
+
metadata: stringMetadata({ partyRole: "mortgage_holder", partyName: party.name, documentType: doc.type })
|
|
2551
3060
|
});
|
|
2552
3061
|
});
|
|
2553
3062
|
if (doc.premium) {
|
|
3063
|
+
const premiumLines = [
|
|
3064
|
+
`Premium: ${doc.premium}`,
|
|
3065
|
+
doc.totalCost ? `Total Cost: ${doc.totalCost}` : null,
|
|
3066
|
+
doc.minimumPremium ? `Minimum Premium: ${doc.minimumPremium}` : null,
|
|
3067
|
+
doc.depositPremium ? `Deposit Premium: ${doc.depositPremium}` : null,
|
|
3068
|
+
doc.auditType ? `Audit Type: ${doc.auditType}` : null
|
|
3069
|
+
].filter(Boolean);
|
|
2554
3070
|
chunks.push({
|
|
2555
3071
|
id: `${docId}:premium:0`,
|
|
2556
3072
|
documentId: docId,
|
|
2557
3073
|
type: "premium",
|
|
2558
|
-
text:
|
|
2559
|
-
Total Cost: ${doc.totalCost}` : ""}`,
|
|
3074
|
+
text: premiumLines.join("\n"),
|
|
2560
3075
|
metadata: stringMetadata({ premium: doc.premium, documentType: doc.type })
|
|
2561
3076
|
});
|
|
2562
3077
|
}
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
3078
|
+
if (doc.taxesAndFees?.length) {
|
|
3079
|
+
chunks.push({
|
|
3080
|
+
id: `${docId}:financial:taxes_fees`,
|
|
3081
|
+
documentId: docId,
|
|
3082
|
+
type: "financial",
|
|
3083
|
+
text: doc.taxesAndFees.map(
|
|
3084
|
+
(item) => [
|
|
3085
|
+
`${item.type ? `[${item.type}] ` : ""}${item.name}: ${item.amount}`,
|
|
3086
|
+
item.description ? ` ${item.description}` : null
|
|
3087
|
+
].filter(Boolean).join("\n")
|
|
3088
|
+
).join("\n"),
|
|
3089
|
+
metadata: stringMetadata({ financialCategory: "taxes_fees", documentType: doc.type })
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
if (doc.paymentPlan?.installments?.length) {
|
|
3093
|
+
chunks.push({
|
|
3094
|
+
id: `${docId}:financial:payment_plan`,
|
|
3095
|
+
documentId: docId,
|
|
3096
|
+
type: "financial",
|
|
3097
|
+
text: [
|
|
3098
|
+
"Payment Plan:",
|
|
3099
|
+
...doc.paymentPlan.installments.map(
|
|
3100
|
+
(inst) => `${inst.dueDate}: ${inst.amount}${inst.description ? ` (${inst.description})` : ""}`
|
|
3101
|
+
),
|
|
3102
|
+
doc.paymentPlan.financeCharge ? `Finance Charge: ${doc.paymentPlan.financeCharge}` : null
|
|
3103
|
+
].filter(Boolean).join("\n"),
|
|
3104
|
+
metadata: stringMetadata({ financialCategory: "payment_plan", documentType: doc.type })
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
doc.premiumByLocation?.forEach((lp, i) => {
|
|
3108
|
+
chunks.push({
|
|
3109
|
+
id: `${docId}:financial:location_premium:${i}`,
|
|
3110
|
+
documentId: docId,
|
|
3111
|
+
type: "financial",
|
|
3112
|
+
text: [
|
|
3113
|
+
`Location ${lp.locationNumber} Premium: ${lp.premium}`,
|
|
3114
|
+
lp.description ? `Description: ${lp.description}` : null
|
|
3115
|
+
].filter(Boolean).join("\n"),
|
|
3116
|
+
metadata: stringMetadata({
|
|
3117
|
+
financialCategory: "location_premium",
|
|
3118
|
+
locationNumber: lp.locationNumber,
|
|
3119
|
+
documentType: doc.type
|
|
3120
|
+
})
|
|
3121
|
+
});
|
|
3122
|
+
});
|
|
3123
|
+
if (doc.ratingBasis?.length) {
|
|
3124
|
+
chunks.push({
|
|
3125
|
+
id: `${docId}:financial:rating_basis`,
|
|
3126
|
+
documentId: docId,
|
|
3127
|
+
type: "financial",
|
|
3128
|
+
text: doc.ratingBasis.map(
|
|
3129
|
+
(rb) => [
|
|
3130
|
+
`Rating Basis: ${rb.type}`,
|
|
3131
|
+
rb.amount ? `Amount: ${rb.amount}` : null,
|
|
3132
|
+
rb.description ? `Description: ${rb.description}` : null
|
|
3133
|
+
].filter(Boolean).join(" | ")
|
|
3134
|
+
).join("\n"),
|
|
3135
|
+
metadata: stringMetadata({ financialCategory: "rating_basis", documentType: doc.type })
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3138
|
+
if (doc.lossSummary) {
|
|
3139
|
+
chunks.push({
|
|
3140
|
+
id: `${docId}:loss_history:summary`,
|
|
3141
|
+
documentId: docId,
|
|
3142
|
+
type: "loss_history",
|
|
3143
|
+
text: [
|
|
3144
|
+
"Loss Summary",
|
|
3145
|
+
doc.lossSummary.period ? `Period: ${doc.lossSummary.period}` : null,
|
|
3146
|
+
doc.lossSummary.totalClaims != null ? `Total Claims: ${doc.lossSummary.totalClaims}` : null,
|
|
3147
|
+
doc.lossSummary.totalIncurred ? `Total Incurred: ${doc.lossSummary.totalIncurred}` : null,
|
|
3148
|
+
doc.lossSummary.totalPaid ? `Total Paid: ${doc.lossSummary.totalPaid}` : null,
|
|
3149
|
+
doc.lossSummary.totalReserved ? `Total Reserved: ${doc.lossSummary.totalReserved}` : null,
|
|
3150
|
+
doc.lossSummary.lossRatio ? `Loss Ratio: ${doc.lossSummary.lossRatio}` : null
|
|
3151
|
+
].filter(Boolean).join("\n"),
|
|
3152
|
+
metadata: stringMetadata({ lossHistoryCategory: "summary", documentType: doc.type })
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3155
|
+
doc.individualClaims?.forEach((claim, i) => {
|
|
3156
|
+
chunks.push({
|
|
3157
|
+
id: `${docId}:loss_history:claim:${i}`,
|
|
3158
|
+
documentId: docId,
|
|
3159
|
+
type: "loss_history",
|
|
3160
|
+
text: [
|
|
3161
|
+
`Claim: ${claim.dateOfLoss}`,
|
|
3162
|
+
claim.claimNumber ? `Claim #: ${claim.claimNumber}` : null,
|
|
3163
|
+
`Description: ${claim.description}`,
|
|
3164
|
+
`Status: ${claim.status}`,
|
|
3165
|
+
claim.claimant ? `Claimant: ${claim.claimant}` : null,
|
|
3166
|
+
claim.coverageLine ? `Coverage Line: ${claim.coverageLine}` : null,
|
|
3167
|
+
claim.paid ? `Paid: ${claim.paid}` : null,
|
|
3168
|
+
claim.reserved ? `Reserved: ${claim.reserved}` : null,
|
|
3169
|
+
claim.incurred ? `Incurred: ${claim.incurred}` : null
|
|
3170
|
+
].filter(Boolean).join("\n"),
|
|
3171
|
+
metadata: stringMetadata({
|
|
3172
|
+
lossHistoryCategory: "claim",
|
|
3173
|
+
claimNumber: claim.claimNumber,
|
|
3174
|
+
claimStatus: claim.status,
|
|
3175
|
+
dateOfLoss: claim.dateOfLoss,
|
|
3176
|
+
documentType: doc.type
|
|
3177
|
+
})
|
|
3178
|
+
});
|
|
3179
|
+
});
|
|
3180
|
+
if (doc.experienceMod) {
|
|
3181
|
+
chunks.push({
|
|
3182
|
+
id: `${docId}:loss_history:experience_mod`,
|
|
3183
|
+
documentId: docId,
|
|
3184
|
+
type: "loss_history",
|
|
3185
|
+
text: [
|
|
3186
|
+
`Experience Modification Factor: ${doc.experienceMod.factor}`,
|
|
3187
|
+
doc.experienceMod.effectiveDate ? `Effective Date: ${doc.experienceMod.effectiveDate}` : null,
|
|
3188
|
+
doc.experienceMod.state ? `State: ${doc.experienceMod.state}` : null
|
|
3189
|
+
].filter(Boolean).join("\n"),
|
|
3190
|
+
metadata: stringMetadata({ lossHistoryCategory: "experience_mod", documentType: doc.type })
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
if (doc.type === "quote") {
|
|
3194
|
+
const quote = doc;
|
|
3195
|
+
const subjectivities = quote.enrichedSubjectivities ?? quote.subjectivities;
|
|
3196
|
+
subjectivities?.forEach((sub, i) => {
|
|
3197
|
+
const enriched = sub;
|
|
3198
|
+
chunks.push({
|
|
3199
|
+
id: `${docId}:subjectivity:${i}`,
|
|
3200
|
+
documentId: docId,
|
|
3201
|
+
type: "subjectivity",
|
|
3202
|
+
text: [
|
|
3203
|
+
`Subjectivity: ${sub.description}`,
|
|
3204
|
+
sub.category ? `Category: ${sub.category}` : null,
|
|
3205
|
+
enriched.dueDate ? `Due Date: ${enriched.dueDate}` : null,
|
|
3206
|
+
enriched.status ? `Status: ${enriched.status}` : null
|
|
3207
|
+
].filter(Boolean).join("\n"),
|
|
3208
|
+
metadata: stringMetadata({
|
|
3209
|
+
category: sub.category,
|
|
3210
|
+
status: enriched.status,
|
|
3211
|
+
documentType: doc.type
|
|
3212
|
+
})
|
|
3213
|
+
});
|
|
3214
|
+
});
|
|
3215
|
+
const uwConditions = quote.enrichedUnderwritingConditions ?? quote.underwritingConditions;
|
|
3216
|
+
uwConditions?.forEach((cond, i) => {
|
|
3217
|
+
const enriched = cond;
|
|
3218
|
+
chunks.push({
|
|
3219
|
+
id: `${docId}:underwriting_condition:${i}`,
|
|
3220
|
+
documentId: docId,
|
|
3221
|
+
type: "underwriting_condition",
|
|
3222
|
+
text: [
|
|
3223
|
+
`Underwriting Condition: ${cond.description}`,
|
|
3224
|
+
enriched.category ? `Category: ${enriched.category}` : null
|
|
3225
|
+
].filter(Boolean).join("\n"),
|
|
3226
|
+
metadata: stringMetadata({ documentType: doc.type })
|
|
3227
|
+
});
|
|
3228
|
+
});
|
|
3229
|
+
if (quote.premiumBreakdown?.length) {
|
|
3230
|
+
chunks.push({
|
|
3231
|
+
id: `${docId}:financial:premium_breakdown`,
|
|
3232
|
+
documentId: docId,
|
|
3233
|
+
type: "financial",
|
|
3234
|
+
text: quote.premiumBreakdown.map((line) => `${line.line}: ${line.amount}`).join("\n"),
|
|
3235
|
+
metadata: stringMetadata({ financialCategory: "premium_breakdown", documentType: doc.type })
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
if (quote.bindingAuthority) {
|
|
3239
|
+
chunks.push({
|
|
3240
|
+
id: `${docId}:financial:binding_authority`,
|
|
3241
|
+
documentId: docId,
|
|
3242
|
+
type: "financial",
|
|
3243
|
+
text: [
|
|
3244
|
+
"Binding Authority",
|
|
3245
|
+
quote.bindingAuthority.authorizedBy ? `Authorized By: ${quote.bindingAuthority.authorizedBy}` : null,
|
|
3246
|
+
quote.bindingAuthority.method ? `Method: ${quote.bindingAuthority.method}` : null,
|
|
3247
|
+
quote.bindingAuthority.expiration ? `Expiration: ${quote.bindingAuthority.expiration}` : null,
|
|
3248
|
+
...quote.bindingAuthority.conditions?.map((c) => `Condition: ${c}`) ?? []
|
|
3249
|
+
].filter(Boolean).join("\n"),
|
|
3250
|
+
metadata: stringMetadata({ financialCategory: "binding_authority", documentType: doc.type })
|
|
3251
|
+
});
|
|
3252
|
+
}
|
|
3253
|
+
if (quote.warrantyRequirements?.length) {
|
|
3254
|
+
quote.warrantyRequirements.forEach((req, i) => {
|
|
3255
|
+
chunks.push({
|
|
3256
|
+
id: `${docId}:underwriting_condition:warranty:${i}`,
|
|
3257
|
+
documentId: docId,
|
|
3258
|
+
type: "underwriting_condition",
|
|
3259
|
+
text: `Warranty Requirement: ${req}`,
|
|
3260
|
+
metadata: stringMetadata({ conditionCategory: "warranty", documentType: doc.type })
|
|
3261
|
+
});
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
if (quote.lossControlRecommendations?.length) {
|
|
3265
|
+
quote.lossControlRecommendations.forEach((rec, i) => {
|
|
3266
|
+
chunks.push({
|
|
3267
|
+
id: `${docId}:underwriting_condition:loss_control:${i}`,
|
|
3268
|
+
documentId: docId,
|
|
3269
|
+
type: "underwriting_condition",
|
|
3270
|
+
text: `Loss Control Recommendation: ${rec}`,
|
|
3271
|
+
metadata: stringMetadata({ conditionCategory: "loss_control", documentType: doc.type })
|
|
3272
|
+
});
|
|
3273
|
+
});
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
let supplementaryIndex = 0;
|
|
3277
|
+
if (doc.claimsContacts?.length) {
|
|
3278
|
+
chunks.push({
|
|
3279
|
+
id: `${docId}:supplementary:${supplementaryIndex++}`,
|
|
3280
|
+
documentId: docId,
|
|
3281
|
+
type: "supplementary",
|
|
3282
|
+
text: doc.claimsContacts.map((contact) => `Claims Contact: ${[
|
|
3283
|
+
contact.name,
|
|
3284
|
+
contact.phone,
|
|
3285
|
+
contact.email,
|
|
3286
|
+
contact.hours
|
|
3287
|
+
].filter(Boolean).join(" | ")}`).join("\n"),
|
|
3288
|
+
metadata: stringMetadata({ documentType: doc.type, supplementaryCategory: "claims_contacts" })
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
if (doc.regulatoryContacts?.length) {
|
|
3292
|
+
chunks.push({
|
|
3293
|
+
id: `${docId}:supplementary:${supplementaryIndex++}`,
|
|
3294
|
+
documentId: docId,
|
|
3295
|
+
type: "supplementary",
|
|
3296
|
+
text: doc.regulatoryContacts.map((contact) => `Regulatory Contact: ${[
|
|
3297
|
+
contact.name,
|
|
3298
|
+
contact.phone,
|
|
3299
|
+
contact.email
|
|
3300
|
+
].filter(Boolean).join(" | ")}`).join("\n"),
|
|
3301
|
+
metadata: stringMetadata({ documentType: doc.type, supplementaryCategory: "regulatory_contacts" })
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
if (doc.thirdPartyAdministrators?.length) {
|
|
3305
|
+
chunks.push({
|
|
3306
|
+
id: `${docId}:supplementary:${supplementaryIndex++}`,
|
|
3307
|
+
documentId: docId,
|
|
3308
|
+
type: "supplementary",
|
|
3309
|
+
text: doc.thirdPartyAdministrators.map((contact) => `TPA: ${[
|
|
3310
|
+
contact.name,
|
|
3311
|
+
contact.phone,
|
|
3312
|
+
contact.email
|
|
3313
|
+
].filter(Boolean).join(" | ")}`).join("\n"),
|
|
3314
|
+
metadata: stringMetadata({ documentType: doc.type, supplementaryCategory: "third_party_administrators" })
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
const noticePeriodLines = [
|
|
2585
3318
|
doc.cancellationNoticeDays != null ? `Cancellation Notice Days: ${doc.cancellationNoticeDays}` : null,
|
|
2586
3319
|
doc.nonrenewalNoticeDays != null ? `Nonrenewal Notice Days: ${doc.nonrenewalNoticeDays}` : null
|
|
2587
3320
|
].filter((line) => Boolean(line));
|
|
2588
|
-
if (
|
|
3321
|
+
if (noticePeriodLines.length > 0) {
|
|
2589
3322
|
chunks.push({
|
|
2590
|
-
id: `${docId}:supplementary
|
|
3323
|
+
id: `${docId}:supplementary:${supplementaryIndex++}`,
|
|
2591
3324
|
documentId: docId,
|
|
2592
3325
|
type: "supplementary",
|
|
2593
|
-
text:
|
|
2594
|
-
metadata: stringMetadata({
|
|
2595
|
-
documentType: doc.type,
|
|
2596
|
-
supplementaryFactCount: doc.supplementaryFacts?.length
|
|
2597
|
-
})
|
|
3326
|
+
text: noticePeriodLines.join("\n"),
|
|
3327
|
+
metadata: stringMetadata({ documentType: doc.type, supplementaryCategory: "notice_periods" })
|
|
2598
3328
|
});
|
|
2599
3329
|
}
|
|
3330
|
+
if (doc.supplementaryFacts?.length) {
|
|
3331
|
+
for (const fact of doc.supplementaryFacts) {
|
|
3332
|
+
chunks.push({
|
|
3333
|
+
id: `${docId}:supplementary:${supplementaryIndex++}`,
|
|
3334
|
+
documentId: docId,
|
|
3335
|
+
type: "supplementary",
|
|
3336
|
+
text: [
|
|
3337
|
+
fact.subject ? `Subject: ${fact.subject}` : null,
|
|
3338
|
+
`${fact.key}: ${fact.value}`,
|
|
3339
|
+
fact.context ? `Context: ${fact.context}` : null
|
|
3340
|
+
].filter(Boolean).join(" | "),
|
|
3341
|
+
metadata: stringMetadata({
|
|
3342
|
+
documentType: doc.type,
|
|
3343
|
+
supplementaryCategory: "auxiliary_fact",
|
|
3344
|
+
factKey: fact.key,
|
|
3345
|
+
factSubject: fact.subject
|
|
3346
|
+
})
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
2600
3350
|
return chunks;
|
|
2601
3351
|
}
|
|
2602
3352
|
|