@carlonicora/nestjs-neo4jsonapi 1.4.1 → 1.5.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/agents/agents.modules.d.ts.map +1 -1
- package/dist/agents/agents.modules.js +21 -2
- package/dist/agents/agents.modules.js.map +1 -1
- package/dist/agents/community.detector/community.detector.module.d.ts +3 -0
- package/dist/agents/community.detector/community.detector.module.d.ts.map +1 -0
- package/dist/agents/community.detector/community.detector.module.js +25 -0
- package/dist/agents/community.detector/community.detector.module.js.map +1 -0
- package/dist/agents/community.detector/services/community.detector.service.d.ts +63 -0
- package/dist/agents/community.detector/services/community.detector.service.d.ts.map +1 -0
- package/dist/agents/community.detector/services/community.detector.service.js +343 -0
- package/dist/agents/community.detector/services/community.detector.service.js.map +1 -0
- package/dist/agents/community.summariser/community.summariser.module.d.ts +3 -0
- package/dist/agents/community.summariser/community.summariser.module.d.ts.map +1 -0
- package/dist/agents/community.summariser/community.summariser.module.js +33 -0
- package/dist/agents/community.summariser/community.summariser.module.js.map +1 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts +21 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.d.ts.map +1 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.js +70 -0
- package/dist/agents/community.summariser/processors/community.summariser.processor.js.map +1 -0
- package/dist/agents/community.summariser/services/community.summariser.service.d.ts +26 -0
- package/dist/agents/community.summariser/services/community.summariser.service.d.ts.map +1 -0
- package/dist/agents/community.summariser/services/community.summariser.service.js +155 -0
- package/dist/agents/community.summariser/services/community.summariser.service.js.map +1 -0
- package/dist/agents/drift/contexts/drift.context.d.ts +56 -0
- package/dist/agents/drift/contexts/drift.context.d.ts.map +1 -0
- package/dist/agents/drift/contexts/drift.context.js +91 -0
- package/dist/agents/drift/contexts/drift.context.js.map +1 -0
- package/dist/agents/drift/drift.module.d.ts +3 -0
- package/dist/agents/drift/drift.module.d.ts.map +1 -0
- package/dist/agents/drift/drift.module.js +44 -0
- package/dist/agents/drift/drift.module.js.map +1 -0
- package/dist/agents/drift/nodes/community.search.node.service.d.ts +12 -0
- package/dist/agents/drift/nodes/community.search.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/community.search.node.service.js +57 -0
- package/dist/agents/drift/nodes/community.search.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/followup.node.service.d.ts +28 -0
- package/dist/agents/drift/nodes/followup.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/followup.node.service.js +174 -0
- package/dist/agents/drift/nodes/followup.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/hyde.node.service.d.ts +21 -0
- package/dist/agents/drift/nodes/hyde.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/hyde.node.service.js +114 -0
- package/dist/agents/drift/nodes/hyde.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.d.ts +17 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.js +108 -0
- package/dist/agents/drift/nodes/primer.answer.node.service.js.map +1 -0
- package/dist/agents/drift/nodes/synthesis.node.service.d.ts +17 -0
- package/dist/agents/drift/nodes/synthesis.node.service.d.ts.map +1 -0
- package/dist/agents/drift/nodes/synthesis.node.service.js +105 -0
- package/dist/agents/drift/nodes/synthesis.node.service.js.map +1 -0
- package/dist/agents/drift/services/drift.migration.service.d.ts +47 -0
- package/dist/agents/drift/services/drift.migration.service.d.ts.map +1 -0
- package/dist/agents/drift/services/drift.migration.service.js +114 -0
- package/dist/agents/drift/services/drift.migration.service.js.map +1 -0
- package/dist/agents/drift/services/drift.search.service.d.ts +52 -0
- package/dist/agents/drift/services/drift.search.service.d.ts.map +1 -0
- package/dist/agents/drift/services/drift.search.service.js +185 -0
- package/dist/agents/drift/services/drift.search.service.js.map +1 -0
- package/dist/agents/graph.creator/interfaces/chunk.analysis.interface.d.ts +4 -0
- package/dist/agents/graph.creator/interfaces/chunk.analysis.interface.d.ts.map +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.d.ts +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.d.ts.map +1 -1
- package/dist/agents/graph.creator/services/graph.creator.service.js +43 -0
- package/dist/agents/graph.creator/services/graph.creator.service.js.map +1 -1
- package/dist/agents/index.d.ts +8 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +18 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/responder/contexts/responder.context.d.ts +3 -0
- package/dist/agents/responder/contexts/responder.context.d.ts.map +1 -1
- package/dist/agents/responder/contexts/responder.context.js +8 -0
- package/dist/agents/responder/contexts/responder.context.js.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.d.ts +1 -0
- package/dist/agents/responder/factories/responder.context.factory.d.ts.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.js +2 -0
- package/dist/agents/responder/factories/responder.context.factory.js.map +1 -1
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts +22 -0
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts.map +1 -1
- package/dist/agents/responder/nodes/responder.answer.node.service.js +155 -0
- package/dist/agents/responder/nodes/responder.answer.node.service.js.map +1 -1
- package/dist/agents/responder/responder.module.d.ts.map +1 -1
- package/dist/agents/responder/responder.module.js +2 -1
- package/dist/agents/responder/responder.module.js.map +1 -1
- package/dist/agents/responder/services/responder.service.d.ts +17 -1
- package/dist/agents/responder/services/responder.service.d.ts.map +1 -1
- package/dist/agents/responder/services/responder.service.js +49 -5
- package/dist/agents/responder/services/responder.service.js.map +1 -1
- package/dist/common/interfaces/agents/graph.creator.interface.d.ts +4 -0
- package/dist/common/interfaces/agents/graph.creator.interface.d.ts.map +1 -1
- package/dist/config/enums/queue.id.d.ts +2 -1
- package/dist/config/enums/queue.id.d.ts.map +1 -1
- package/dist/config/enums/queue.id.js +1 -0
- package/dist/config/enums/queue.id.js.map +1 -1
- package/dist/config/interfaces/config.prompts.interface.d.ts +5 -0
- package/dist/config/interfaces/config.prompts.interface.d.ts.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.d.ts.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.js +8 -0
- package/dist/foundations/chunk/services/chunk.service.js.map +1 -1
- package/dist/foundations/community/community.module.d.ts +5 -0
- package/dist/foundations/community/community.module.d.ts.map +1 -0
- package/dist/foundations/community/community.module.js +29 -0
- package/dist/foundations/community/community.module.js.map +1 -0
- package/dist/foundations/community/entities/community.entity.d.ts +18 -0
- package/dist/foundations/community/entities/community.entity.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.entity.js +3 -0
- package/dist/foundations/community/entities/community.entity.js.map +1 -0
- package/dist/foundations/community/entities/community.map.d.ts +8 -0
- package/dist/foundations/community/entities/community.map.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.map.js +23 -0
- package/dist/foundations/community/entities/community.map.js.map +1 -0
- package/dist/foundations/community/entities/community.meta.d.ts +3 -0
- package/dist/foundations/community/entities/community.meta.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.meta.js +10 -0
- package/dist/foundations/community/entities/community.meta.js.map +1 -0
- package/dist/foundations/community/entities/community.model.d.ts +4 -0
- package/dist/foundations/community/entities/community.model.d.ts.map +1 -0
- package/dist/foundations/community/entities/community.model.js +15 -0
- package/dist/foundations/community/entities/community.model.js.map +1 -0
- package/dist/foundations/community/repositories/community.repository.d.ts +138 -0
- package/dist/foundations/community/repositories/community.repository.d.ts.map +1 -0
- package/dist/foundations/community/repositories/community.repository.js +446 -0
- package/dist/foundations/community/repositories/community.repository.js.map +1 -0
- package/dist/foundations/community/services/community.service.d.ts +8 -0
- package/dist/foundations/community/services/community.service.d.ts.map +1 -0
- package/dist/foundations/community/services/community.service.js +28 -0
- package/dist/foundations/community/services/community.service.js.map +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.entity.d.ts +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.entity.d.ts.map +1 -1
- package/dist/foundations/keyconcept/entities/key.concept.map.d.ts.map +1 -1
- package/dist/foundations/keyconcept/entities/key.concept.map.js +1 -0
- package/dist/foundations/keyconcept/entities/key.concept.map.js.map +1 -1
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.d.ts +13 -2
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.d.ts.map +1 -1
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.js +22 -2
- package/dist/foundations/keyconcept/repositories/keyconcept.repository.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ClsService } from "nestjs-cls";
|
|
2
|
+
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
3
|
+
import { CommunityRepository } from "../../../foundations/community/repositories/community.repository";
|
|
4
|
+
import { CompanyRepository } from "../../../foundations/company/repositories/company.repository";
|
|
5
|
+
import { CommunityDetectorService } from "../../community.detector/services/community.detector.service";
|
|
6
|
+
export interface MigrationResult {
|
|
7
|
+
totalCompanies: number;
|
|
8
|
+
processedCompanies: number;
|
|
9
|
+
failedCompanies: string[];
|
|
10
|
+
communitiesCreated: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class DriftMigrationService {
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly clsService;
|
|
15
|
+
private readonly companyRepository;
|
|
16
|
+
private readonly communityRepository;
|
|
17
|
+
private readonly communityDetectorService;
|
|
18
|
+
constructor(logger: AppLoggingService, clsService: ClsService, companyRepository: CompanyRepository, communityRepository: CommunityRepository, communityDetectorService: CommunityDetectorService);
|
|
19
|
+
/**
|
|
20
|
+
* Run DRIFT migration for all companies
|
|
21
|
+
* This detects communities for all existing KeyConcepts
|
|
22
|
+
* The community summariser cron job will then generate summaries
|
|
23
|
+
*/
|
|
24
|
+
migrateAll(): Promise<MigrationResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Run DRIFT migration for a specific company
|
|
27
|
+
* Sets up CLS context and runs community detection
|
|
28
|
+
*/
|
|
29
|
+
migrateCompany(companyId: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Get migration status - count stale vs processed communities per company
|
|
32
|
+
*/
|
|
33
|
+
getMigrationStatus(): Promise<{
|
|
34
|
+
companies: {
|
|
35
|
+
companyId: string;
|
|
36
|
+
companyName: string;
|
|
37
|
+
totalCommunities: number;
|
|
38
|
+
staleCommunities: number;
|
|
39
|
+
processedCommunities: number;
|
|
40
|
+
}[];
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Get community counts for a specific company
|
|
44
|
+
*/
|
|
45
|
+
private getCommunityCountsForCompany;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=drift.migration.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.migration.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/drift/services/drift.migration.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kEAAkE,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,8DAA8D,CAAC;AACjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,8DAA8D,CAAC;AAExG,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,qBACa,qBAAqB;IAE9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,wBAAwB;gBAJxB,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,UAAU,EACtB,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,mBAAmB,EACxC,wBAAwB,EAAE,wBAAwB;IAGrE;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAqC5C;;;OAGG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtD;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC;QAClC,SAAS,EAAE;YACT,SAAS,EAAE,MAAM,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;YACpB,gBAAgB,EAAE,MAAM,CAAC;YACzB,gBAAgB,EAAE,MAAM,CAAC;YACzB,oBAAoB,EAAE,MAAM,CAAC;SAC9B,EAAE,CAAC;KACL,CAAC;IAsBF;;OAEG;YACW,4BAA4B;CAqB3C"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DriftMigrationService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const nestjs_cls_1 = require("nestjs-cls");
|
|
15
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
16
|
+
const community_repository_1 = require("../../../foundations/community/repositories/community.repository");
|
|
17
|
+
const company_repository_1 = require("../../../foundations/company/repositories/company.repository");
|
|
18
|
+
const community_detector_service_1 = require("../../community.detector/services/community.detector.service");
|
|
19
|
+
let DriftMigrationService = class DriftMigrationService {
|
|
20
|
+
constructor(logger, clsService, companyRepository, communityRepository, communityDetectorService) {
|
|
21
|
+
this.logger = logger;
|
|
22
|
+
this.clsService = clsService;
|
|
23
|
+
this.companyRepository = companyRepository;
|
|
24
|
+
this.communityRepository = communityRepository;
|
|
25
|
+
this.communityDetectorService = communityDetectorService;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run DRIFT migration for all companies
|
|
29
|
+
* This detects communities for all existing KeyConcepts
|
|
30
|
+
* The community summariser cron job will then generate summaries
|
|
31
|
+
*/
|
|
32
|
+
async migrateAll() {
|
|
33
|
+
this.logger.log("Starting DRIFT migration for all companies", "DriftMigrationService");
|
|
34
|
+
const result = {
|
|
35
|
+
totalCompanies: 0,
|
|
36
|
+
processedCompanies: 0,
|
|
37
|
+
failedCompanies: [],
|
|
38
|
+
communitiesCreated: 0,
|
|
39
|
+
};
|
|
40
|
+
const companies = await this.companyRepository.fetchAll();
|
|
41
|
+
result.totalCompanies = companies.length;
|
|
42
|
+
this.logger.log(`Found ${companies.length} companies to process`, "DriftMigrationService");
|
|
43
|
+
for (const company of companies) {
|
|
44
|
+
try {
|
|
45
|
+
await this.migrateCompany(company.id);
|
|
46
|
+
result.processedCompanies++;
|
|
47
|
+
this.logger.log(`Processed company ${company.id} (${company.name})`, "DriftMigrationService");
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
result.failedCompanies.push(company.id);
|
|
51
|
+
this.logger.error(`Failed to process company ${company.id}: ${error.message}`, "DriftMigrationService");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
this.logger.log(`DRIFT migration completed: ${result.processedCompanies}/${result.totalCompanies} companies processed`, "DriftMigrationService");
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Run DRIFT migration for a specific company
|
|
59
|
+
* Sets up CLS context and runs community detection
|
|
60
|
+
*/
|
|
61
|
+
async migrateCompany(companyId) {
|
|
62
|
+
await this.clsService.run(async () => {
|
|
63
|
+
this.clsService.set("companyId", companyId);
|
|
64
|
+
this.logger.debug(`Running community detection for company ${companyId}`, "DriftMigrationService");
|
|
65
|
+
await this.communityDetectorService.detectCommunities();
|
|
66
|
+
this.logger.debug(`Community detection completed for company ${companyId}`, "DriftMigrationService");
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get migration status - count stale vs processed communities per company
|
|
71
|
+
*/
|
|
72
|
+
async getMigrationStatus() {
|
|
73
|
+
const companies = await this.companyRepository.fetchAll();
|
|
74
|
+
const status = [];
|
|
75
|
+
for (const company of companies) {
|
|
76
|
+
const counts = await this.getCommunityCountsForCompany(company.id);
|
|
77
|
+
status.push({
|
|
78
|
+
companyId: company.id,
|
|
79
|
+
companyName: company.name,
|
|
80
|
+
...counts,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return { companies: status };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get community counts for a specific company
|
|
87
|
+
*/
|
|
88
|
+
async getCommunityCountsForCompany(companyId) {
|
|
89
|
+
return new Promise((resolve) => {
|
|
90
|
+
this.clsService.run(async () => {
|
|
91
|
+
this.clsService.set("companyId", companyId);
|
|
92
|
+
const levelCounts = await this.communityRepository.countByLevel();
|
|
93
|
+
const staleCommunities = await this.communityRepository.findStaleCommunities(1000);
|
|
94
|
+
const totalCommunities = (levelCounts ?? []).reduce((sum, lc) => sum + lc.count, 0);
|
|
95
|
+
const staleCount = (staleCommunities ?? []).length;
|
|
96
|
+
resolve({
|
|
97
|
+
totalCommunities,
|
|
98
|
+
staleCommunities: staleCount,
|
|
99
|
+
processedCommunities: totalCommunities - staleCount,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.DriftMigrationService = DriftMigrationService;
|
|
106
|
+
exports.DriftMigrationService = DriftMigrationService = __decorate([
|
|
107
|
+
(0, common_1.Injectable)(),
|
|
108
|
+
__metadata("design:paramtypes", [logging_service_1.AppLoggingService,
|
|
109
|
+
nestjs_cls_1.ClsService,
|
|
110
|
+
company_repository_1.CompanyRepository,
|
|
111
|
+
community_repository_1.CommunityRepository,
|
|
112
|
+
community_detector_service_1.CommunityDetectorService])
|
|
113
|
+
], DriftMigrationService);
|
|
114
|
+
//# sourceMappingURL=drift.migration.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.migration.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/services/drift.migration.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAwC;AACxC,oFAAmF;AACnF,2GAAuG;AACvG,qGAAiG;AACjG,6GAAwG;AAUjG,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,YACmB,MAAyB,EACzB,UAAsB,EACtB,iBAAoC,EACpC,mBAAwC,EACxC,wBAAkD;QAJlD,WAAM,GAAN,MAAM,CAAmB;QACzB,eAAU,GAAV,UAAU,CAAY;QACtB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,6BAAwB,GAAxB,wBAAwB,CAA0B;IAClE,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,4CAA4C,EAAE,uBAAuB,CAAC,CAAC;QAEvF,MAAM,MAAM,GAAoB;YAC9B,cAAc,EAAE,CAAC;YACjB,kBAAkB,EAAE,CAAC;YACrB,eAAe,EAAE,EAAE;YACnB,kBAAkB,EAAE,CAAC;SACtB,CAA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AE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpF,MAAM,UAAU,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;gBAEnD,OAAO,CAAC;oBACN,gBAAgB;oBAChB,gBAAgB,EAAE,UAAU;oBAC5B,oBAAoB,EAAE,gBAAgB,GAAG,UAAU;iBACpD,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA5HY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAGgB,mCAAiB;QACb,uBAAU;QACH,sCAAiB;QACf,0CAAmB;QACd,qDAAwB;GAN1D,qBAAqB,CA4HjC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
2
|
+
import { TracingService } from "../../../core/tracing/services/tracing.service";
|
|
3
|
+
import { Community } from "../../../foundations/community/entities/community.entity";
|
|
4
|
+
import { FollowUpAnswer } from "../contexts/drift.context";
|
|
5
|
+
import { CommunitySearchNodeService } from "../nodes/community.search.node.service";
|
|
6
|
+
import { FollowUpNodeService } from "../nodes/followup.node.service";
|
|
7
|
+
import { HydeNodeService } from "../nodes/hyde.node.service";
|
|
8
|
+
import { PrimerAnswerNodeService } from "../nodes/primer.answer.node.service";
|
|
9
|
+
import { SynthesisNodeService } from "../nodes/synthesis.node.service";
|
|
10
|
+
export interface DriftSearchResult {
|
|
11
|
+
answer: string;
|
|
12
|
+
matchedCommunities: Community[];
|
|
13
|
+
followUpAnswers: FollowUpAnswer[];
|
|
14
|
+
initialAnswer: string;
|
|
15
|
+
confidence: number;
|
|
16
|
+
hydeEmbedding: number[];
|
|
17
|
+
}
|
|
18
|
+
export interface DriftConfig {
|
|
19
|
+
primerTopK?: number;
|
|
20
|
+
followUpDepth?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class DriftSearchService {
|
|
23
|
+
private readonly hydeNode;
|
|
24
|
+
private readonly communitySearchNode;
|
|
25
|
+
private readonly primerAnswerNode;
|
|
26
|
+
private readonly followUpNode;
|
|
27
|
+
private readonly synthesisNode;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private readonly tracer;
|
|
30
|
+
constructor(hydeNode: HydeNodeService, communitySearchNode: CommunitySearchNodeService, primerAnswerNode: PrimerAnswerNodeService, followUpNode: FollowUpNodeService, synthesisNode: SynthesisNodeService, logger: AppLoggingService, tracer: TracingService);
|
|
31
|
+
/**
|
|
32
|
+
* Run full DRIFT search workflow using LangGraph StateGraph:
|
|
33
|
+
* 1. HyDE: Generate hypothetical document embedding
|
|
34
|
+
* 2. Community Search: Vector search against community summaries
|
|
35
|
+
* 3. Primer Answer: Generate initial answer + follow-up questions
|
|
36
|
+
* 4. Follow-up: Process follow-up questions iteratively
|
|
37
|
+
* 5. Synthesis: Combine all answers into final response
|
|
38
|
+
*/
|
|
39
|
+
search(params: {
|
|
40
|
+
question: string;
|
|
41
|
+
config?: DriftConfig;
|
|
42
|
+
}): Promise<DriftSearchResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Quick search - just HyDE + community search + primer answer (no follow-ups)
|
|
45
|
+
* Useful for when you want fast results
|
|
46
|
+
*/
|
|
47
|
+
quickSearch(params: {
|
|
48
|
+
question: string;
|
|
49
|
+
topK?: number;
|
|
50
|
+
}): Promise<DriftSearchResult>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=drift.search.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.search.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/drift/services/drift.search.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,0DAA0D,CAAC;AACrF,OAAO,EAAmC,cAAc,EAAE,MAA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AAC,iBAAiB,CAAC;IAqI5F;;;OAGG;IACG,WAAW,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAS3F"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DriftSearchService = void 0;
|
|
13
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
const logging_service_1 = require("../../../core/logging/services/logging.service");
|
|
17
|
+
const tracing_service_1 = require("../../../core/tracing/services/tracing.service");
|
|
18
|
+
const drift_context_1 = require("../contexts/drift.context");
|
|
19
|
+
const community_search_node_service_1 = require("../nodes/community.search.node.service");
|
|
20
|
+
const followup_node_service_1 = require("../nodes/followup.node.service");
|
|
21
|
+
const hyde_node_service_1 = require("../nodes/hyde.node.service");
|
|
22
|
+
const primer_answer_node_service_1 = require("../nodes/primer.answer.node.service");
|
|
23
|
+
const synthesis_node_service_1 = require("../nodes/synthesis.node.service");
|
|
24
|
+
let DriftSearchService = class DriftSearchService {
|
|
25
|
+
constructor(hydeNode, communitySearchNode, primerAnswerNode, followUpNode, synthesisNode, logger, tracer) {
|
|
26
|
+
this.hydeNode = hydeNode;
|
|
27
|
+
this.communitySearchNode = communitySearchNode;
|
|
28
|
+
this.primerAnswerNode = primerAnswerNode;
|
|
29
|
+
this.followUpNode = followUpNode;
|
|
30
|
+
this.synthesisNode = synthesisNode;
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.tracer = tracer;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Run full DRIFT search workflow using LangGraph StateGraph:
|
|
36
|
+
* 1. HyDE: Generate hypothetical document embedding
|
|
37
|
+
* 2. Community Search: Vector search against community summaries
|
|
38
|
+
* 3. Primer Answer: Generate initial answer + follow-up questions
|
|
39
|
+
* 4. Follow-up: Process follow-up questions iteratively
|
|
40
|
+
* 5. Synthesis: Combine all answers into final response
|
|
41
|
+
*/
|
|
42
|
+
async search(params) {
|
|
43
|
+
const config = params.config ?? {};
|
|
44
|
+
const maxHops = 20;
|
|
45
|
+
this.logger.log(`Starting DRIFT search for: "${params.question}"`, "DriftSearchService");
|
|
46
|
+
this.tracer.startSpan("DRIFT Search Workflow", {
|
|
47
|
+
attributes: {
|
|
48
|
+
question: params.question,
|
|
49
|
+
topK: config.primerTopK ?? 5,
|
|
50
|
+
maxDepth: config.followUpDepth ?? 2,
|
|
51
|
+
maxHops,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const returnState = (state) => {
|
|
55
|
+
const nextStep = state.hops >= maxHops ? "synthesis" : state.nextStep;
|
|
56
|
+
return nextStep === "end" ? langgraph_1.END : nextStep;
|
|
57
|
+
};
|
|
58
|
+
const workflow = new langgraph_1.StateGraph(drift_context_1.DriftContext)
|
|
59
|
+
.addNode("hyde", async (state) => {
|
|
60
|
+
this.tracer.addSpanEvent(`Node: hyde - hop ${state.hops}/${maxHops}`, { hopCount: state.hops });
|
|
61
|
+
const result = await this.hydeNode.execute({ state });
|
|
62
|
+
this.tracer.addSpanEvent(`Node: hyde complete`, { nextStep: result.nextStep });
|
|
63
|
+
return result;
|
|
64
|
+
})
|
|
65
|
+
.addNode("community_search", async (state) => {
|
|
66
|
+
this.tracer.addSpanEvent(`Node: community_search - hop ${state.hops}/${maxHops}`, { hopCount: state.hops });
|
|
67
|
+
const result = await this.communitySearchNode.execute({ state });
|
|
68
|
+
this.tracer.addSpanEvent(`Node: community_search complete`, {
|
|
69
|
+
communitiesFound: result.matchedCommunities?.length ?? 0,
|
|
70
|
+
nextStep: result.nextStep,
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
})
|
|
74
|
+
.addNode("primer_answer", async (state) => {
|
|
75
|
+
this.tracer.addSpanEvent(`Node: primer_answer - hop ${state.hops}/${maxHops}`, { hopCount: state.hops });
|
|
76
|
+
const result = await this.primerAnswerNode.execute({ state });
|
|
77
|
+
this.tracer.addSpanEvent(`Node: primer_answer complete`, {
|
|
78
|
+
confidence: result.confidence,
|
|
79
|
+
followUpCount: result.followUpQuestions?.length ?? 0,
|
|
80
|
+
nextStep: result.nextStep,
|
|
81
|
+
});
|
|
82
|
+
return result;
|
|
83
|
+
})
|
|
84
|
+
.addNode("followup", async (state) => {
|
|
85
|
+
this.tracer.addSpanEvent(`Node: followup - hop ${state.hops}/${maxHops}`, {
|
|
86
|
+
hopCount: state.hops,
|
|
87
|
+
questionIndex: state.currentFollowUpIndex,
|
|
88
|
+
depth: state.currentDepth,
|
|
89
|
+
});
|
|
90
|
+
const result = await this.followUpNode.execute({ state });
|
|
91
|
+
this.tracer.addSpanEvent(`Node: followup complete`, { nextStep: result.nextStep });
|
|
92
|
+
return result;
|
|
93
|
+
})
|
|
94
|
+
.addNode("synthesis", async (state) => {
|
|
95
|
+
this.tracer.addSpanEvent(`Node: synthesis - hop ${state.hops}/${maxHops} (final)`, { hopCount: state.hops });
|
|
96
|
+
const result = await this.synthesisNode.execute({ state });
|
|
97
|
+
this.tracer.addSpanEvent(`Node: synthesis complete`);
|
|
98
|
+
return result;
|
|
99
|
+
})
|
|
100
|
+
.addEdge(langgraph_1.START, "hyde")
|
|
101
|
+
.addEdge("hyde", "community_search")
|
|
102
|
+
.addConditionalEdges("community_search", (state) => returnState(state))
|
|
103
|
+
.addConditionalEdges("primer_answer", (state) => returnState(state))
|
|
104
|
+
.addConditionalEdges("followup", (state) => returnState(state))
|
|
105
|
+
.addEdge("synthesis", langgraph_1.END);
|
|
106
|
+
const threadId = (0, crypto_1.randomUUID)();
|
|
107
|
+
const checkpointer = new langgraph_1.MemorySaver();
|
|
108
|
+
const app = workflow.compile({ checkpointer });
|
|
109
|
+
const initialState = {
|
|
110
|
+
question: params.question,
|
|
111
|
+
topK: config.primerTopK ?? 5,
|
|
112
|
+
maxDepth: config.followUpDepth ?? 2,
|
|
113
|
+
nextStep: "hyde",
|
|
114
|
+
hops: 0,
|
|
115
|
+
hypotheticalAnswer: "",
|
|
116
|
+
hydeEmbedding: [],
|
|
117
|
+
matchedCommunities: [],
|
|
118
|
+
communitySummaries: "",
|
|
119
|
+
initialAnswer: "",
|
|
120
|
+
followUpQuestions: [],
|
|
121
|
+
confidence: 0,
|
|
122
|
+
currentFollowUpIndex: 0,
|
|
123
|
+
currentDepth: 0,
|
|
124
|
+
followUpAnswers: [],
|
|
125
|
+
priorContext: "",
|
|
126
|
+
finalAnswer: "",
|
|
127
|
+
tokens: { input: 0, output: 0 },
|
|
128
|
+
};
|
|
129
|
+
this.tracer.addSpanEvent("Workflow Executing");
|
|
130
|
+
let finalState;
|
|
131
|
+
try {
|
|
132
|
+
finalState = await app.invoke(initialState, {
|
|
133
|
+
configurable: { thread_id: threadId },
|
|
134
|
+
recursionLimit: maxHops + 5,
|
|
135
|
+
});
|
|
136
|
+
this.tracer.addSpanEvent("Workflow Completed", {
|
|
137
|
+
finalHopCount: finalState.hops,
|
|
138
|
+
communitiesMatched: finalState.matchedCommunities.length,
|
|
139
|
+
followUpAnswersCount: finalState.followUpAnswers.length,
|
|
140
|
+
});
|
|
141
|
+
this.tracer.setSpanSuccess();
|
|
142
|
+
this.tracer.endSpan();
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
this.tracer.setSpanError(e);
|
|
146
|
+
this.tracer.endSpan();
|
|
147
|
+
this.logger.error(`DRIFT workflow failed: ${e.message}`, "DriftSearchService");
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
150
|
+
this.logger.log(`DRIFT search complete: ${finalState.matchedCommunities.length} communities, ${finalState.followUpAnswers.length} follow-ups, ${finalState.hops} hops`, "DriftSearchService");
|
|
151
|
+
return {
|
|
152
|
+
answer: finalState.finalAnswer,
|
|
153
|
+
matchedCommunities: finalState.matchedCommunities,
|
|
154
|
+
followUpAnswers: finalState.followUpAnswers,
|
|
155
|
+
initialAnswer: finalState.initialAnswer,
|
|
156
|
+
confidence: finalState.confidence,
|
|
157
|
+
hydeEmbedding: finalState.hydeEmbedding,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Quick search - just HyDE + community search + primer answer (no follow-ups)
|
|
162
|
+
* Useful for when you want fast results
|
|
163
|
+
*/
|
|
164
|
+
async quickSearch(params) {
|
|
165
|
+
return this.search({
|
|
166
|
+
question: params.question,
|
|
167
|
+
config: {
|
|
168
|
+
primerTopK: params.topK,
|
|
169
|
+
followUpDepth: 0, // Skip follow-ups
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
exports.DriftSearchService = DriftSearchService;
|
|
175
|
+
exports.DriftSearchService = DriftSearchService = __decorate([
|
|
176
|
+
(0, common_1.Injectable)(),
|
|
177
|
+
__metadata("design:paramtypes", [hyde_node_service_1.HydeNodeService,
|
|
178
|
+
community_search_node_service_1.CommunitySearchNodeService,
|
|
179
|
+
primer_answer_node_service_1.PrimerAnswerNodeService,
|
|
180
|
+
followup_node_service_1.FollowUpNodeService,
|
|
181
|
+
synthesis_node_service_1.SynthesisNodeService,
|
|
182
|
+
logging_service_1.AppLoggingService,
|
|
183
|
+
tracing_service_1.TracingService])
|
|
184
|
+
], DriftSearchService);
|
|
185
|
+
//# sourceMappingURL=drift.search.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.search.service.js","sourceRoot":"","sources":["../../../../src/agents/drift/services/drift.search.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,2CAA4C;AAC5C,mCAAoC;AACpC,oFAAmF;AACnF,oFAAgF;AAEhF,6DAA4F;AAC5F,0FAAoF;AACpF,0EAAqE;AACrE,kEAA6D;AAC7D,oFAA8E;AAC9E,4EAAuE;AAiBhE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YACmB,QAAyB,EACzB,mBAA+C,EAC/C,gBAAyC,EACzC,YAAiC,EACjC,aAAmC,EACnC,MAAyB,EACzB,MAAsB;QANtB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,wBAAmB,GAAnB,mBAAmB,CAA4B;QAC/C,qBAAgB,GAAhB,gBAAgB,CAAyB;QACzC,iBAAY,GAAZ,YAAY,CAAqB;QACjC,kBAAa,GAAb,aAAa,CAAsB;QACnC,WAAM,GAAN,MAAM,CAAmB;QACzB,WAAM,GAAN,MAAM,CAAgB;IACtC,CAAC;IAEJ;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,MAAkD;QAC7D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,+BAA+B,MAAM,CAAC,QAAQ,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAEzF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,uBAAuB,EAAE;YAC7C,UAAU,EAAE;gBACV,QAAQ,EAAE,MAAM,CAAC,QA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YACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA2B,CAAW,CAAC,OAAO,EAAE,EAAE,oBAAoB,CAAC,CAAC;YAC1F,MAAM,CAAC,CAAC;QACV,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,0BAA0B,UAAU,CAAC,kBAAkB,CAAC,MAAM,iBAAiB,UAAU,CAAC,eAAe,CAAC,MAAM,gBAAgB,UAAU,CAAC,IAAI,OAAO,EACtJ,oBAAoB,CACrB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,UAAU,CAAC,WAAW;YAC9B,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;YACjD,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,aAAa,EAAE,UAAU,CAAC,aAAa;YACvC,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,aAAa,EAAE,UAAU,CAAC,aAAa;SACxC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,MAA2C;QAC3D,OAAO,IAAI,CAAC,MAAM,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE;gBACN,UAAU,EAAE,MAAM,CAAC,IAAI;gBACvB,aAAa,EAAE,CAAC,EAAE,kBAAkB;aACrC;SACF,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArKY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAGkB,mCAAe;QACJ,0DAA0B;QAC7B,oDAAuB;QAC3B,2CAAmB;QAClB,6CAAoB;QAC3B,mCAAiB;QACjB,gCAAc;GAR9B,kBAAkB,CAqK9B"}
|
|
@@ -9,6 +9,10 @@ export interface ChunkAnalysisInterface {
|
|
|
9
9
|
keyConcept2: string;
|
|
10
10
|
relationship: string;
|
|
11
11
|
}[];
|
|
12
|
+
keyConceptDescriptions: {
|
|
13
|
+
keyConcept: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}[];
|
|
12
16
|
tokens: TokenUsageInterface;
|
|
13
17
|
}
|
|
14
18
|
//# sourceMappingURL=chunk.analysis.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.analysis.interface.d.ts","sourceRoot":"","sources":["../../../../src/agents/graph.creator/interfaces/chunk.analysis.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AAEvF,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,EAAE,CAAC;IACJ,wBAAwB,EAAE;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,EAAE,CAAC;IACJ,MAAM,EAAE,mBAAmB,CAAC;CAC7B"}
|
|
1
|
+
{"version":3,"file":"chunk.analysis.interface.d.ts","sourceRoot":"","sources":["../../../../src/agents/graph.creator/interfaces/chunk.analysis.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AAEvF,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,EAAE,CAAC;IACJ,wBAAwB,EAAE;QACxB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB,EAAE,CAAC;IACJ,sBAAsB,EAAE;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;KACrB,EAAE,CAAC;IACJ,MAAM,EAAE,mBAAmB,CAAC;CAC7B"}
|
|
@@ -3,7 +3,7 @@ import { BaseConfigInterface } from "../../../config/interfaces";
|
|
|
3
3
|
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
4
4
|
import { AppLoggingService } from "../../../core/logging/services/logging.service";
|
|
5
5
|
import { ChunkAnalysisInterface } from "../../graph.creator/interfaces/chunk.analysis.interface";
|
|
6
|
-
export declare const prompt = "\nYou are an intelligent assistant that extracts structured knowledge from text.\n\n## CRITICAL: Garbage Detection\n\n**BEFORE attempting any extraction, evaluate if the text is intelligible.**\n\nIf the text contains:\n- Unintelligible OCR garbage or random characters (e.g., \"!\u00A7Ydsv$\", \"aitsru{.*U\", \"Q\u00A7tvllvll\")\n- Mostly punctuation marks with no semantic meaning (e.g., \"!!!\", \"===\", \"|||\")\n- Random character sequences that form no recognizable words\n- Repetitive meaningless patterns\n- No coherent sentences or semantic content\n\n**Then you MUST:**\n- Return EMPTY atomicFacts array: []\n- Return EMPTY keyConceptsRelationships array: []\n- Do NOT attempt to extract anything from garbage text\n\n## Definitions\n\n**Atomic Fact**: A single, indivisible statement containing **ONE action, ONE event, or ONE relationship**. Each atomic fact must represent the smallest unit of meaningful information that cannot be broken down further.\n\n**CRITICAL: ONE ACTION PER FACT**\n- Each atomic fact must contain ONLY ONE verb/action\n- If a sentence contains multiple actions connected by \"and\", \"but\", commas, split it into separate atomic facts\n- Each action, decision, or event gets its own atomic fact\n\n**Examples of CORRECT Atomic Facts (one action each):**\n- \u2705 \"The president detects the ambiguity of the notification\"\n- \u2705 \"The president grants an extension until 15/2/2023\"\n- \u2705 \"The president postpones the hearing to 29/3/2023\"\n- \u2705 \"Joe Bauer was born in London on 03.04.1985\"\n\n**Examples of INCORRECT Atomic Facts (multiple actions - MUST BE SPLIT):**\n- \u274C \"The president detects the ambiguity of the notification, grants an extension until 15/2/2023 and postpones the hearing to 29/3/2023\"\n \u2192 WRONG: Contains 3 actions (detects, grants, postpones) - must be split into 3 atomic facts\n- \u274C \"Joe Bauer was born in London and studied at university\"\n \u2192 WRONG: Contains 2 actions (was born, studied) - must be split into 2 atomic facts\n\n**Key Concept**: ONLY semantically meaningful entities - proper nouns, specific terms, named entities:\n\n**VALID Key Concepts (extract these):**\n- **Proper names**: \"joe bauer\", \"mike modano\", ...\n- **Places**: \"london\", \"italy\", \"rome\", \"washington\", ...\n- **Organizations**: \"microsoft\", \"apple\", \"phlow\", \"united nations\", \"tribunale di roma\", ...\n- **Complete dates with legal significance**: \"28.12.2019\", \"15/2/2023\", \"29/3/2023\", \"03.04.1985\", \"15 january 2023\"\n - \u2705 ONLY extract dates that are significant to the atomic fact\n - \u2705 Include time ONLY when paired with a date AND relevant to the atomic fact: \"29/3/2023 alle 10.40\"\n- **Acronyms**: \"upu\", \"nlp\", \"api\", \"crm\", \"d.p.r.\", \"c.c.\", \"c.p.\" (always lowercase)\n- **Technical terms**: \"knowledge base\", \"semantic search\", \"blockchain\"\n- **Products/systems**: \"kubernetes\", \"microsoft\", \"s3\"\n\n**INVALID Key Concepts (NEVER extract these):**\n- \u274C Single characters: \"!\", \"e\", \"i\", \"a\", \"o\", \"n\", \"'\"\n- \u274C Pure punctuation: \".\", \",\", \":\", \";\", \"(\", \")\", \"[\", \"]\"\n- \u274C Random garbage: \"!\u00A7Ydsv$\", \"Q\u00A7tvllvll\", \"aitsru{.*U\", \"ourpEl}r\"\n- \u274C Meaningless sequences: \"||!\", \"===\", \"___\", \"***\"\n- \u274C Pure numbers without context: \"254\", \"819\", \"123\"\n- \u274C **Isolated times without dates**: \"12.40\", \"10:30\", \"15.00\" (unless part of legally significant event like \"udienza alle 10.40\" with date)\n- \u274C **Administrative timestamps**: \"verbale chiuso alle 12.40\", \"documento firmato alle 15.00\" (not legally significant)\n- \u274C Generic words without specific meaning: \"thing\", \"way\", \"type\", \"method\"\n\n**Markdown Headers**: Structural elements like \"## Data Architecture\" that organize content.\n\n## Instructions\n\n1. **Evaluate text quality** - Is this intelligible text or garbage? If garbage, return empty arrays.\n2. **Check for markdown headers** - If text starts with ##, ###, etc., note the complete header text\n3. **Decompose compound sentences** - If a sentence contains multiple actions/verbs (connected by \"and\", \"but\", commas):\n - Break it into separate atomic facts\n - Each action gets its own atomic fact\n - Example: \"The president detects the ambiguity, grants an extension and postpones the hearing\" \u2192 3 atomic facts\n4. **Extract atomic facts** - Only from intelligible, meaningful text. ONE ACTION PER FACT.\n5. **MANDATORY: Create summary atomic fact** - Must include the markdown header if present. Example: \"Recommendation 1 focuses on improving UPU service standards\" (key concepts: \"recommendation 1\", \"upu\", \"service standards\")\n6. **Identify key concepts** - Only SEMANTICALLY MEANINGFUL entities (names, places, significant dates, organizations, legal terms)\n7. **Create relationships** - Between valid key concepts based on how they connect in atomic facts\n\n## Atomic Fact Rules\n\n**CRITICAL: ONE ACTION/EVENT PER ATOMIC FACT**\n- Each atomic fact must contain ONLY ONE verb/action\n- If you see multiple verbs in a sentence (e.g., \"detects\", \"grants\", \"postpones\"), create separate atomic facts for each\n- Use the subject from the original sentence for each split fact\n- Each atomic fact must be a complete, grammatically correct sentence\n\n**Decomposition Process:**\n1. Identify all verbs/actions in the sentence\n2. Count them - if more than one, decomposition is required\n3. Create one atomic fact per action, maintaining the subject\n4. Example:\n - Input: \"The president detects the ambiguity, grants an extension and postpones the hearing\"\n - Actions found: \"detects\" (1), \"grants\" (2), \"postpones\" (3) = 3 actions\n - Output: 3 atomic facts:\n 1. \"The president detects the ambiguity\"\n 2. \"The president grants an extension\"\n 3. \"The president postpones the hearing\"\n\n## Key Concept Rules\n\n- Key concepts **MUST** be semantically meaningful entities (see examples above)\n- **COPY VERBATIM** from the text (lowercasing allowed, no other changes)\n- Minimum 2 characters length\n- Must contain actual semantic meaning (not punctuation, not single letters)\n- **DO NOT change** spelling, letters, or structure\n- Always include acronyms and technical terms found in text\n- Include complete markdown headers as Key Concepts: \"## Recommendation 1\" becomes \"recommendation 1\"\n- Every key concept must appear in at least one atomic fact\n\n**Character Requirements:**\n- Must have at least 40% alphanumeric characters (not mostly punctuation)\n- Cannot be pure punctuation or special characters\n- Cannot be random character sequences\n\n## Relationships Rules\n\n**Key Concepts Relationships**: Analyze relationships between key concepts to create a network graph.\n- For each relationship:\n - **node_1**: First key concept (must be a valid key concept from extraction)\n - **node_2**: Second key concept (must be a valid key concept from extraction)\n - **edge**: Sentence describing the relationship in present tense\n- Only create relationships between VALID key concepts\n- Both nodes must be semantically meaningful entities\n\n## Additional Considerations\n\n- **DECOMPOSE compound sentences** - Always split sentences with multiple actions into separate atomic facts\n- Focus on extracting **named entities** and **specific domain terminology**\n- Ignore filler words, articles, prepositions, conjunctions\n- Pay special attention to proper names, places, significant dates, organizations, and legal entities\n- Terms mentioned in the same sentence or paragraph are typically related\n\n## CRITICAL: Quality over Quantity\n\n- It is BETTER to return empty arrays than to extract garbage\n- Only extract from intelligible, meaningful text\n- Every key concept must be a real entity with semantic meaning\n- Single characters, punctuation, and random sequences are NEVER valid key concepts\n\n## CRITICAL: Atomic Fact Decomposition\n\n**MANDATORY PROCESS FOR EVERY SENTENCE:**\n1. Count the number of actions/verbs in the sentence\n2. If count > 1, YOU MUST split into separate atomic facts\n3. Each action gets its own atomic fact with complete subject and context\n4. NEVER create compound atomic facts with multiple actions\n\n**Remember:**\n- \u274C WRONG: \"The president detects, grants and postpones\" (3 actions in 1 fact)\n- \u2705 RIGHT: Three separate facts - one for \"detects\", one for \"grants\", one for \"postpones\"\n\n## **Strictly follow the above instructions. Evaluate text quality first, then decompose compound sentences. Begin.**\n";
|
|
6
|
+
export declare const prompt = "\nYou are an intelligent assistant that extracts structured knowledge from text.\n\n## CRITICAL: Garbage Detection\n\n**BEFORE attempting any extraction, evaluate if the text is intelligible.**\n\nIf the text contains:\n- Unintelligible OCR garbage or random characters (e.g., \"!\u00A7Ydsv$\", \"aitsru{.*U\", \"Q\u00A7tvllvll\")\n- Mostly punctuation marks with no semantic meaning (e.g., \"!!!\", \"===\", \"|||\")\n- Random character sequences that form no recognizable words\n- Repetitive meaningless patterns\n- No coherent sentences or semantic content\n\n**Then you MUST:**\n- Return EMPTY atomicFacts array: []\n- Return EMPTY keyConceptsRelationships array: []\n- Do NOT attempt to extract anything from garbage text\n\n## Definitions\n\n**Atomic Fact**: A single, indivisible statement containing **ONE action, ONE event, or ONE relationship**. Each atomic fact must represent the smallest unit of meaningful information that cannot be broken down further.\n\n**CRITICAL: ONE ACTION PER FACT**\n- Each atomic fact must contain ONLY ONE verb/action\n- If a sentence contains multiple actions connected by \"and\", \"but\", commas, split it into separate atomic facts\n- Each action, decision, or event gets its own atomic fact\n\n**Examples of CORRECT Atomic Facts (one action each):**\n- \u2705 \"The president detects the ambiguity of the notification\"\n- \u2705 \"The president grants an extension until 15/2/2023\"\n- \u2705 \"The president postpones the hearing to 29/3/2023\"\n- \u2705 \"Joe Bauer was born in London on 03.04.1985\"\n\n**Examples of INCORRECT Atomic Facts (multiple actions - MUST BE SPLIT):**\n- \u274C \"The president detects the ambiguity of the notification, grants an extension until 15/2/2023 and postpones the hearing to 29/3/2023\"\n \u2192 WRONG: Contains 3 actions (detects, grants, postpones) - must be split into 3 atomic facts\n- \u274C \"Joe Bauer was born in London and studied at university\"\n \u2192 WRONG: Contains 2 actions (was born, studied) - must be split into 2 atomic facts\n\n**Key Concept**: ONLY semantically meaningful entities - proper nouns, specific terms, named entities:\n\n**VALID Key Concepts (extract these):**\n- **Proper names**: \"joe bauer\", \"mike modano\", ...\n- **Places**: \"london\", \"italy\", \"rome\", \"washington\", ...\n- **Organizations**: \"microsoft\", \"apple\", \"phlow\", \"united nations\", \"tribunale di roma\", ...\n- **Complete dates with legal significance**: \"28.12.2019\", \"15/2/2023\", \"29/3/2023\", \"03.04.1985\", \"15 january 2023\"\n - \u2705 ONLY extract dates that are significant to the atomic fact\n - \u2705 Include time ONLY when paired with a date AND relevant to the atomic fact: \"29/3/2023 alle 10.40\"\n- **Acronyms**: \"upu\", \"nlp\", \"api\", \"crm\", \"d.p.r.\", \"c.c.\", \"c.p.\" (always lowercase)\n- **Technical terms**: \"knowledge base\", \"semantic search\", \"blockchain\"\n- **Products/systems**: \"kubernetes\", \"microsoft\", \"s3\"\n\n**INVALID Key Concepts (NEVER extract these):**\n- \u274C Single characters: \"!\", \"e\", \"i\", \"a\", \"o\", \"n\", \"'\"\n- \u274C Pure punctuation: \".\", \",\", \":\", \";\", \"(\", \")\", \"[\", \"]\"\n- \u274C Random garbage: \"!\u00A7Ydsv$\", \"Q\u00A7tvllvll\", \"aitsru{.*U\", \"ourpEl}r\"\n- \u274C Meaningless sequences: \"||!\", \"===\", \"___\", \"***\"\n- \u274C Pure numbers without context: \"254\", \"819\", \"123\"\n- \u274C **Isolated times without dates**: \"12.40\", \"10:30\", \"15.00\" (unless part of legally significant event like \"udienza alle 10.40\" with date)\n- \u274C **Administrative timestamps**: \"verbale chiuso alle 12.40\", \"documento firmato alle 15.00\" (not legally significant)\n- \u274C Generic words without specific meaning: \"thing\", \"way\", \"type\", \"method\"\n\n**Markdown Headers**: Structural elements like \"## Data Architecture\" that organize content.\n\n## Instructions\n\n1. **Evaluate text quality** - Is this intelligible text or garbage? If garbage, return empty arrays.\n2. **Check for markdown headers** - If text starts with ##, ###, etc., note the complete header text\n3. **Decompose compound sentences** - If a sentence contains multiple actions/verbs (connected by \"and\", \"but\", commas):\n - Break it into separate atomic facts\n - Each action gets its own atomic fact\n - Example: \"The president detects the ambiguity, grants an extension and postpones the hearing\" \u2192 3 atomic facts\n4. **Extract atomic facts** - Only from intelligible, meaningful text. ONE ACTION PER FACT.\n5. **MANDATORY: Create summary atomic fact** - Must include the markdown header if present. Example: \"Recommendation 1 focuses on improving UPU service standards\" (key concepts: \"recommendation 1\", \"upu\", \"service standards\")\n6. **Identify key concepts** - Only SEMANTICALLY MEANINGFUL entities (names, places, significant dates, organizations, legal terms)\n7. **Create relationships** - Between valid key concepts based on how they connect in atomic facts\n\n## Atomic Fact Rules\n\n**CRITICAL: ONE ACTION/EVENT PER ATOMIC FACT**\n- Each atomic fact must contain ONLY ONE verb/action\n- If you see multiple verbs in a sentence (e.g., \"detects\", \"grants\", \"postpones\"), create separate atomic facts for each\n- Use the subject from the original sentence for each split fact\n- Each atomic fact must be a complete, grammatically correct sentence\n\n**Decomposition Process:**\n1. Identify all verbs/actions in the sentence\n2. Count them - if more than one, decomposition is required\n3. Create one atomic fact per action, maintaining the subject\n4. Example:\n - Input: \"The president detects the ambiguity, grants an extension and postpones the hearing\"\n - Actions found: \"detects\" (1), \"grants\" (2), \"postpones\" (3) = 3 actions\n - Output: 3 atomic facts:\n 1. \"The president detects the ambiguity\"\n 2. \"The president grants an extension\"\n 3. \"The president postpones the hearing\"\n\n## Key Concept Rules\n\n- Key concepts **MUST** be semantically meaningful entities (see examples above)\n- **COPY VERBATIM** from the text (lowercasing allowed, no other changes)\n- Minimum 2 characters length\n- Must contain actual semantic meaning (not punctuation, not single letters)\n- **DO NOT change** spelling, letters, or structure\n- Always include acronyms and technical terms found in text\n- Include complete markdown headers as Key Concepts: \"## Recommendation 1\" becomes \"recommendation 1\"\n- Every key concept must appear in at least one atomic fact\n\n**Character Requirements:**\n- Must have at least 40% alphanumeric characters (not mostly punctuation)\n- Cannot be pure punctuation or special characters\n- Cannot be random character sequences\n\n## Key Concept Descriptions\n\nFor each unique key concept extracted, generate a brief description (1-2 sentences) that:\n- Explains what the entity is in the context of the document\n- Captures its role, type, or significance\n- Uses information from the text to provide context\n\n**Examples:**\n- \"joe bauer\" \u2192 \"A person born in London who studied at university\"\n- \"tribunale di roma\" \u2192 \"The court of Rome, an Italian judicial institution\"\n- \"upu\" \u2192 \"Universal Postal Union, an international postal organization\"\n- \"15/2/2023\" \u2192 \"Date when the president granted an extension\"\n\n## Relationships Rules\n\n**Key Concepts Relationships**: Analyze relationships between key concepts to create a network graph.\n- For each relationship:\n - **node_1**: First key concept (must be a valid key concept from extraction)\n - **node_2**: Second key concept (must be a valid key concept from extraction)\n - **edge**: Sentence describing the relationship in present tense\n- Only create relationships between VALID key concepts\n- Both nodes must be semantically meaningful entities\n\n## Additional Considerations\n\n- **DECOMPOSE compound sentences** - Always split sentences with multiple actions into separate atomic facts\n- Focus on extracting **named entities** and **specific domain terminology**\n- Ignore filler words, articles, prepositions, conjunctions\n- Pay special attention to proper names, places, significant dates, organizations, and legal entities\n- Terms mentioned in the same sentence or paragraph are typically related\n\n## CRITICAL: Quality over Quantity\n\n- It is BETTER to return empty arrays than to extract garbage\n- Only extract from intelligible, meaningful text\n- Every key concept must be a real entity with semantic meaning\n- Single characters, punctuation, and random sequences are NEVER valid key concepts\n\n## CRITICAL: Atomic Fact Decomposition\n\n**MANDATORY PROCESS FOR EVERY SENTENCE:**\n1. Count the number of actions/verbs in the sentence\n2. If count > 1, YOU MUST split into separate atomic facts\n3. Each action gets its own atomic fact with complete subject and context\n4. NEVER create compound atomic facts with multiple actions\n\n**Remember:**\n- \u274C WRONG: \"The president detects, grants and postpones\" (3 actions in 1 fact)\n- \u2705 RIGHT: Three separate facts - one for \"detects\", one for \"grants\", one for \"postpones\"\n\n## **Strictly follow the above instructions. Evaluate text quality first, then decompose compound sentences. Begin.**\n";
|
|
7
7
|
export declare class GraphCreatorService {
|
|
8
8
|
private readonly llmService;
|
|
9
9
|
private readonly logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.creator.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/graph.creator/services/graph.creator.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yDAAyD,CAAC;AAEjG,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"graph.creator.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/graph.creator/services/graph.creator.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yDAAyD,CAAC;AAEjG,eAAO,MAAM,MAAM,2lSAqKlB,CAAC;AA8KF,qBACa,mBAAmB;IAI5B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGnB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAAC;IAM9D,aAAa,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;CA6LlF"}
|
|
@@ -129,6 +129,19 @@ If the text contains:
|
|
|
129
129
|
- Cannot be pure punctuation or special characters
|
|
130
130
|
- Cannot be random character sequences
|
|
131
131
|
|
|
132
|
+
## Key Concept Descriptions
|
|
133
|
+
|
|
134
|
+
For each unique key concept extracted, generate a brief description (1-2 sentences) that:
|
|
135
|
+
- Explains what the entity is in the context of the document
|
|
136
|
+
- Captures its role, type, or significance
|
|
137
|
+
- Uses information from the text to provide context
|
|
138
|
+
|
|
139
|
+
**Examples:**
|
|
140
|
+
- "joe bauer" → "A person born in London who studied at university"
|
|
141
|
+
- "tribunale di roma" → "The court of Rome, an Italian judicial institution"
|
|
142
|
+
- "upu" → "Universal Postal Union, an international postal organization"
|
|
143
|
+
- "15/2/2023" → "Date when the president granted an extension"
|
|
144
|
+
|
|
132
145
|
## Relationships Rules
|
|
133
146
|
|
|
134
147
|
**Key Concepts Relationships**: Analyze relationships between key concepts to create a network graph.
|
|
@@ -188,6 +201,14 @@ const outputSchema = zod_1.z.object({
|
|
|
188
201
|
.describe(`Relationship between the two specific entities, node_1 and node_2 in one or two sentences.`),
|
|
189
202
|
}))
|
|
190
203
|
.describe(`List of all the key concepts in the atomic facts and their relationships to one another`),
|
|
204
|
+
keyConceptDescriptions: zod_1.z
|
|
205
|
+
.array(zod_1.z.object({
|
|
206
|
+
keyConcept: zod_1.z.string().describe(`The key concept value (lowercase, exact match from atomicFacts)`),
|
|
207
|
+
description: zod_1.z
|
|
208
|
+
.string()
|
|
209
|
+
.describe(`Brief 1-2 sentence description of what this entity is in the context of the document. Explains its role, type, or significance.`),
|
|
210
|
+
}))
|
|
211
|
+
.describe(`Descriptions for each unique key concept extracted from the atomic facts`),
|
|
191
212
|
});
|
|
192
213
|
const inputSchema = zod_1.z.object({
|
|
193
214
|
content: zod_1.z.string().describe("The content to analyse"),
|
|
@@ -312,6 +333,7 @@ let GraphCreatorService = class GraphCreatorService {
|
|
|
312
333
|
const response = {
|
|
313
334
|
atomicFacts: [],
|
|
314
335
|
keyConceptsRelationships: [],
|
|
336
|
+
keyConceptDescriptions: [],
|
|
315
337
|
tokens: { input: 0, output: 0 },
|
|
316
338
|
};
|
|
317
339
|
if (!params.content || typeof params.content !== "string" || params.content.trim().length === 0) {
|
|
@@ -406,12 +428,33 @@ let GraphCreatorService = class GraphCreatorService {
|
|
|
406
428
|
return null;
|
|
407
429
|
})
|
|
408
430
|
.filter(Boolean);
|
|
431
|
+
// Collect all valid key concepts from atomicFacts for filtering descriptions
|
|
432
|
+
const validKeyConcepts = new Set();
|
|
433
|
+
response.atomicFacts.forEach((fact) => {
|
|
434
|
+
fact.keyConcepts.forEach((kc) => validKeyConcepts.add(kc));
|
|
435
|
+
});
|
|
436
|
+
// Process key concept descriptions - only keep those for valid key concepts
|
|
437
|
+
response.keyConceptDescriptions = (llmResponse.keyConceptDescriptions || [])
|
|
438
|
+
?.map((desc) => {
|
|
439
|
+
const cleanKeyConcept = (desc.keyConcept || "").trim().toLowerCase();
|
|
440
|
+
// Only include descriptions for key concepts that exist in our valid set
|
|
441
|
+
if (isValidKeyConcept(cleanKeyConcept) && validKeyConcepts.has(cleanKeyConcept) && desc.description) {
|
|
442
|
+
return {
|
|
443
|
+
keyConcept: cleanKeyConcept,
|
|
444
|
+
description: desc.description.trim(),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
})
|
|
449
|
+
.filter(Boolean);
|
|
409
450
|
response.tokens = llmResponse.tokenUsage;
|
|
410
451
|
this.logger.debug("Post-LLM filtering completed", "GraphCreatorService", {
|
|
411
452
|
llmExtractedFacts: llmResponse.atomicFacts?.length || 0,
|
|
412
453
|
llmExtractedRelationships: llmResponse.keyConceptsRelationships?.length || 0,
|
|
454
|
+
llmExtractedDescriptions: llmResponse.keyConceptDescriptions?.length || 0,
|
|
413
455
|
finalAtomicFacts: response.atomicFacts.length,
|
|
414
456
|
finalRelationships: response.keyConceptsRelationships.length,
|
|
457
|
+
finalDescriptions: response.keyConceptDescriptions.length,
|
|
415
458
|
factsFilteredOut: (llmResponse.atomicFacts?.length || 0) - response.atomicFacts.length,
|
|
416
459
|
relationshipsFilteredOut: (llmResponse.keyConceptsRelationships?.length || 0) - response.keyConceptsRelationships.length,
|
|
417
460
|
});
|