only_ever_generator 8.4.6 → 8.4.8
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/bootstrap/app.d.ts +6 -3
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +11 -17
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +2 -3
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +22 -15
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/prompt_data.d.ts +4 -4
- package/dist/constants/prompt_data.js +302 -302
- package/dist/constants/prompts/card_gen_prompt.js +160 -160
- package/dist/constants/prompts/typology_prompt.js +131 -131
- package/dist/constants/source_data.d.ts +171 -171
- package/dist/constants/source_data.js +973 -973
- package/dist/embedding_generation/local_consolidation.js +104 -104
- package/dist/helper/build_concept_facts_schema.d.ts +42 -42
- package/dist/helper/build_concept_facts_schema.js +44 -44
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.d.ts +1 -9
- package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.js +47 -50
- package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.js +20 -5
- package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.js +18 -7
- package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/parse/response_format_card.d.ts +176 -176
- package/dist/parse/response_format_card.js +371 -371
- package/dist/parse/response_format_typology.d.ts +1 -1
- package/dist/parse/response_format_typology.js +46 -46
- package/dist/services/get_prompts.d.ts +8 -7
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +69 -21
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts +2 -3
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +25 -15
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +2 -1
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +24 -13
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts +2 -3
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +24 -13
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +39 -38
- package/src/bootstrap/app.ts +418 -416
- package/src/card_gen/generate_cards.ts +347 -345
- package/src/config.ts +11 -11
- package/src/constants/api_constants.ts +7 -7
- package/src/constants/prompts/card_gen_prompt.ts +164 -164
- package/src/constants/prompts/typology_prompt.ts +139 -139
- package/src/embedding_generation/consolidation/global_consolidation.ts +96 -96
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -141
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -98
- package/src/embedding_generation/generate_embeddings.ts +42 -42
- package/src/embedding_generation/parse_embedding_response.ts +31 -31
- package/src/enums/card_type_enum.ts +6 -6
- package/src/gap_fill/calculate_gap_fill.ts +50 -50
- package/src/helper/get_id_from_title.ts +33 -33
- package/src/helper/mongo_helper.ts +29 -29
- package/src/helper/openai_helper.ts +20 -20
- package/src/helper/qdrant_db_methods.ts +77 -77
- package/src/helper/schema_helper/build_card_schema.ts +74 -98
- package/src/helper/schema_helper/build_classify_summarize_schema.ts +43 -43
- package/src/helper/schema_helper/build_concept_facts_schema.ts +45 -31
- package/src/helper/schema_helper/build_summary_schema.ts +43 -32
- package/src/index.ts +71 -73
- package/src/logger.ts +65 -65
- package/src/parse/parse_card/parse_cloze_card.ts +146 -146
- package/src/parse/parse_card/parse_flash_cards.ts +42 -42
- package/src/parse/parse_card/parse_match_card.ts +104 -104
- package/src/parse/parse_card/parse_mcq_card.ts +114 -114
- package/src/parse/parse_card_response.ts +197 -197
- package/src/parse/parse_source_content.ts +212 -212
- package/src/services/get_prompts.ts +164 -112
- package/src/services/open_ai_service.ts +89 -89
- package/src/services/qdrant_service.ts +10 -10
- package/src/types/base_param_type.ts +13 -13
- package/src/types/mongo_concept_fact_type.ts +12 -12
- package/src/types/parsed_card_type.ts +39 -39
- package/src/types/raw_card_response_types/generated_card_response_type.ts +59 -59
- package/src/types/source_taxonomy_type.ts +24 -24
- package/src/typology-parsed-response.ts +1932 -1932
- package/src/typology_gen/generate_concept_facts.ts +180 -169
- package/src/typology_gen/generate_typology.ts +203 -189
- package/src/typology_gen/summarize.ts +176 -164
- package/src/utils/distributed_quote_restoration.ts +80 -80
- package/src/utils/generate_args.ts +29 -29
- package/src/utils/parse_openai_response.ts +19 -19
- package/src/utils/sanitize_strings.ts +65 -65
- package/tsconfig.json +16 -16
- package/dist/constants/default_generation_variables.d.ts +0 -3
- package/dist/constants/default_generation_variables.d.ts.map +0 -1
- package/dist/constants/default_generation_variables.js +0 -580
- package/dist/constants/default_generation_variables.js.map +0 -1
- package/dist/services/prompts_test.d.ts +0 -10
- package/dist/services/prompts_test.d.ts.map +0 -1
- package/dist/services/prompts_test.js +0 -227
- package/dist/services/prompts_test.js.map +0 -1
- package/dist/types/generation_variables_schema.d.ts +0 -14
- package/dist/types/generation_variables_schema.d.ts.map +0 -1
- package/dist/types/generation_variables_schema.js +0 -3
- package/dist/types/generation_variables_schema.js.map +0 -1
- package/dist/utils/test.d.ts +0 -2
- package/dist/utils/test.d.ts.map +0 -1
- package/dist/utils/test.js +0 -5
- package/dist/utils/test.js.map +0 -1
- package/src/constants/default_generation_variables.ts +0 -624
- package/src/types/generation_variables_schema.ts +0 -16
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import { randomUUID, UUID } from "crypto";
|
|
2
|
-
|
|
3
|
-
export class LocalConsolidation {
|
|
4
|
-
consolidate(
|
|
5
|
-
concepts_facts: {
|
|
6
|
-
text: string;
|
|
7
|
-
type: string;
|
|
8
|
-
embedding: number[];
|
|
9
|
-
reference: string;
|
|
10
|
-
}[],
|
|
11
|
-
sourceId: string
|
|
12
|
-
) {
|
|
13
|
-
try {
|
|
14
|
-
const sourceIds = [];
|
|
15
|
-
const sourceTaxonomyOps: {
|
|
16
|
-
text: string;
|
|
17
|
-
id: string;
|
|
18
|
-
embedding: number[];
|
|
19
|
-
type: string;
|
|
20
|
-
reference: string;
|
|
21
|
-
}[] = [];
|
|
22
|
-
const globalConceptOps: {
|
|
23
|
-
id: string;
|
|
24
|
-
vector: number[];
|
|
25
|
-
payload: {
|
|
26
|
-
_sources: string[];
|
|
27
|
-
text: string;
|
|
28
|
-
};
|
|
29
|
-
}[] = [];
|
|
30
|
-
const consolidatedConcepts: any[] = [];
|
|
31
|
-
const concepts: {
|
|
32
|
-
id: string;
|
|
33
|
-
text: string;
|
|
34
|
-
reference: string;
|
|
35
|
-
embedding: number[];
|
|
36
|
-
type: string;
|
|
37
|
-
}[] = concepts_facts.map((e: any) => {
|
|
38
|
-
return {
|
|
39
|
-
id: randomUUID().toString(),
|
|
40
|
-
text: e.text,
|
|
41
|
-
reference: e.reference,
|
|
42
|
-
embedding: e.embedding,
|
|
43
|
-
type: e.type,
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
const afterConsolidation = this.consolidateSimilarEmbeddings(concepts);
|
|
47
|
-
sourceIds.push(JSON.stringify(sourceId));
|
|
48
|
-
console.log(afterConsolidation);
|
|
49
|
-
for (var concept of afterConsolidation.finalConsolidatedConcepts) {
|
|
50
|
-
sourceTaxonomyOps.push({
|
|
51
|
-
text: concept.text,
|
|
52
|
-
id: concept.id,
|
|
53
|
-
embedding: concept.embedding,
|
|
54
|
-
type: concept.type,
|
|
55
|
-
reference: concept.reference,
|
|
56
|
-
});
|
|
57
|
-
globalConceptOps.push({
|
|
58
|
-
id: concept.id.toString(),
|
|
59
|
-
vector: concept.embedding,
|
|
60
|
-
payload: {
|
|
61
|
-
_sources: [sourceId],
|
|
62
|
-
text: concept.text,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
consolidatedConcepts.push(...afterConsolidation.consolidatedConcepts);
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
globalConceptOps: globalConceptOps,
|
|
70
|
-
sourceIds: sourceIds,
|
|
71
|
-
consolidatedConcepts: consolidatedConcepts,
|
|
72
|
-
sourceTaxonomyOps: sourceTaxonomyOps,
|
|
73
|
-
};
|
|
74
|
-
} catch (e: any) {
|
|
75
|
-
console.error(
|
|
76
|
-
"Error occurred while converting the parsed array to db operations:",
|
|
77
|
-
e
|
|
78
|
-
);
|
|
79
|
-
throw e;
|
|
80
|
-
}
|
|
81
|
-
// const concepts = concepts_facts.map((e) => {
|
|
82
|
-
// return {
|
|
83
|
-
// id: randomUUID().toString(),
|
|
84
|
-
// text: e.text,
|
|
85
|
-
// type: e.type,
|
|
86
|
-
// embedding: e.embedding,
|
|
87
|
-
// };
|
|
88
|
-
// });
|
|
89
|
-
// const consolidated = this._consolidateSimilarEmbeddings(concepts);
|
|
90
|
-
// return consolidated;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
cosineSimilarity = (a: number[], b: number[]): number => {
|
|
94
|
-
const dotProduct = a.reduce((acc, val, index) => acc + val * b[index], 0);
|
|
95
|
-
const magnitudeA = Math.sqrt(a.reduce((acc, val) => acc + val * val, 0));
|
|
96
|
-
const magnitudeB = Math.sqrt(b.reduce((acc, val) => acc + val * val, 0));
|
|
97
|
-
return dotProduct / (magnitudeA * magnitudeB);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
consolidateSimilarEmbeddings(data: any[], threshold = 0.65) {
|
|
101
|
-
const finalConsolidatedConcepts: {
|
|
102
|
-
id: UUID;
|
|
103
|
-
text: string;
|
|
104
|
-
reference: string;
|
|
105
|
-
embedding: number[];
|
|
106
|
-
type: string;
|
|
107
|
-
}[] = [];
|
|
108
|
-
const visited = new Array(data.length).fill(false);
|
|
109
|
-
const consolidatedConcepts: any[] = [];
|
|
110
|
-
|
|
111
|
-
for (let i = 0; i < data.length; i++) {
|
|
112
|
-
if (visited[i]) continue;
|
|
113
|
-
|
|
114
|
-
const group = [data[i]];
|
|
115
|
-
visited[i] = true;
|
|
116
|
-
|
|
117
|
-
for (let j = i + 1; j < data.length; j++) {
|
|
118
|
-
if (visited[j]) continue;
|
|
119
|
-
|
|
120
|
-
const sim = this.cosineSimilarity(data[i].embedding, data[j].embedding);
|
|
121
|
-
if (sim > threshold) {
|
|
122
|
-
group.push(data[j]);
|
|
123
|
-
visited[j] = true;
|
|
124
|
-
consolidatedConcepts.push({
|
|
125
|
-
concept1: data[i].text,
|
|
126
|
-
concept2: data[j].text,
|
|
127
|
-
similarity: sim,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Consolidate the group (e.g., just take the first, or merge)
|
|
133
|
-
finalConsolidatedConcepts.push(group[0]); // Or you can customize how to merge
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
finalConsolidatedConcepts: finalConsolidatedConcepts,
|
|
138
|
-
consolidatedConcepts: consolidatedConcepts,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
import { randomUUID, UUID } from "crypto";
|
|
2
|
+
|
|
3
|
+
export class LocalConsolidation {
|
|
4
|
+
consolidate(
|
|
5
|
+
concepts_facts: {
|
|
6
|
+
text: string;
|
|
7
|
+
type: string;
|
|
8
|
+
embedding: number[];
|
|
9
|
+
reference: string;
|
|
10
|
+
}[],
|
|
11
|
+
sourceId: string
|
|
12
|
+
) {
|
|
13
|
+
try {
|
|
14
|
+
const sourceIds = [];
|
|
15
|
+
const sourceTaxonomyOps: {
|
|
16
|
+
text: string;
|
|
17
|
+
id: string;
|
|
18
|
+
embedding: number[];
|
|
19
|
+
type: string;
|
|
20
|
+
reference: string;
|
|
21
|
+
}[] = [];
|
|
22
|
+
const globalConceptOps: {
|
|
23
|
+
id: string;
|
|
24
|
+
vector: number[];
|
|
25
|
+
payload: {
|
|
26
|
+
_sources: string[];
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
}[] = [];
|
|
30
|
+
const consolidatedConcepts: any[] = [];
|
|
31
|
+
const concepts: {
|
|
32
|
+
id: string;
|
|
33
|
+
text: string;
|
|
34
|
+
reference: string;
|
|
35
|
+
embedding: number[];
|
|
36
|
+
type: string;
|
|
37
|
+
}[] = concepts_facts.map((e: any) => {
|
|
38
|
+
return {
|
|
39
|
+
id: randomUUID().toString(),
|
|
40
|
+
text: e.text,
|
|
41
|
+
reference: e.reference,
|
|
42
|
+
embedding: e.embedding,
|
|
43
|
+
type: e.type,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const afterConsolidation = this.consolidateSimilarEmbeddings(concepts);
|
|
47
|
+
sourceIds.push(JSON.stringify(sourceId));
|
|
48
|
+
console.log(afterConsolidation);
|
|
49
|
+
for (var concept of afterConsolidation.finalConsolidatedConcepts) {
|
|
50
|
+
sourceTaxonomyOps.push({
|
|
51
|
+
text: concept.text,
|
|
52
|
+
id: concept.id,
|
|
53
|
+
embedding: concept.embedding,
|
|
54
|
+
type: concept.type,
|
|
55
|
+
reference: concept.reference,
|
|
56
|
+
});
|
|
57
|
+
globalConceptOps.push({
|
|
58
|
+
id: concept.id.toString(),
|
|
59
|
+
vector: concept.embedding,
|
|
60
|
+
payload: {
|
|
61
|
+
_sources: [sourceId],
|
|
62
|
+
text: concept.text,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
consolidatedConcepts.push(...afterConsolidation.consolidatedConcepts);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
globalConceptOps: globalConceptOps,
|
|
70
|
+
sourceIds: sourceIds,
|
|
71
|
+
consolidatedConcepts: consolidatedConcepts,
|
|
72
|
+
sourceTaxonomyOps: sourceTaxonomyOps,
|
|
73
|
+
};
|
|
74
|
+
} catch (e: any) {
|
|
75
|
+
console.error(
|
|
76
|
+
"Error occurred while converting the parsed array to db operations:",
|
|
77
|
+
e
|
|
78
|
+
);
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
81
|
+
// const concepts = concepts_facts.map((e) => {
|
|
82
|
+
// return {
|
|
83
|
+
// id: randomUUID().toString(),
|
|
84
|
+
// text: e.text,
|
|
85
|
+
// type: e.type,
|
|
86
|
+
// embedding: e.embedding,
|
|
87
|
+
// };
|
|
88
|
+
// });
|
|
89
|
+
// const consolidated = this._consolidateSimilarEmbeddings(concepts);
|
|
90
|
+
// return consolidated;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
cosineSimilarity = (a: number[], b: number[]): number => {
|
|
94
|
+
const dotProduct = a.reduce((acc, val, index) => acc + val * b[index], 0);
|
|
95
|
+
const magnitudeA = Math.sqrt(a.reduce((acc, val) => acc + val * val, 0));
|
|
96
|
+
const magnitudeB = Math.sqrt(b.reduce((acc, val) => acc + val * val, 0));
|
|
97
|
+
return dotProduct / (magnitudeA * magnitudeB);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
consolidateSimilarEmbeddings(data: any[], threshold = 0.65) {
|
|
101
|
+
const finalConsolidatedConcepts: {
|
|
102
|
+
id: UUID;
|
|
103
|
+
text: string;
|
|
104
|
+
reference: string;
|
|
105
|
+
embedding: number[];
|
|
106
|
+
type: string;
|
|
107
|
+
}[] = [];
|
|
108
|
+
const visited = new Array(data.length).fill(false);
|
|
109
|
+
const consolidatedConcepts: any[] = [];
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < data.length; i++) {
|
|
112
|
+
if (visited[i]) continue;
|
|
113
|
+
|
|
114
|
+
const group = [data[i]];
|
|
115
|
+
visited[i] = true;
|
|
116
|
+
|
|
117
|
+
for (let j = i + 1; j < data.length; j++) {
|
|
118
|
+
if (visited[j]) continue;
|
|
119
|
+
|
|
120
|
+
const sim = this.cosineSimilarity(data[i].embedding, data[j].embedding);
|
|
121
|
+
if (sim > threshold) {
|
|
122
|
+
group.push(data[j]);
|
|
123
|
+
visited[j] = true;
|
|
124
|
+
consolidatedConcepts.push({
|
|
125
|
+
concept1: data[i].text,
|
|
126
|
+
concept2: data[j].text,
|
|
127
|
+
similarity: sim,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Consolidate the group (e.g., just take the first, or merge)
|
|
133
|
+
finalConsolidatedConcepts.push(group[0]); // Or you can customize how to merge
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
finalConsolidatedConcepts: finalConsolidatedConcepts,
|
|
138
|
+
consolidatedConcepts: consolidatedConcepts,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import qdrantClient from "../../services/qdrant_service";
|
|
2
|
-
|
|
3
|
-
export class WriteConsolidatedData {
|
|
4
|
-
async writeConsolidatedData(
|
|
5
|
-
data: {
|
|
6
|
-
source_taxonomy: {
|
|
7
|
-
id: string;
|
|
8
|
-
text: string;
|
|
9
|
-
type: string;
|
|
10
|
-
reference: string;
|
|
11
|
-
}[];
|
|
12
|
-
global_updates: {
|
|
13
|
-
id: string;
|
|
14
|
-
currentPayload: {
|
|
15
|
-
_sources: string[];
|
|
16
|
-
text: string;
|
|
17
|
-
};
|
|
18
|
-
sourceIdToAdd: string;
|
|
19
|
-
}[];
|
|
20
|
-
global_inserts: {
|
|
21
|
-
id: string;
|
|
22
|
-
vector: number[];
|
|
23
|
-
payload: {
|
|
24
|
-
_sources: string[];
|
|
25
|
-
text: string;
|
|
26
|
-
};
|
|
27
|
-
}[];
|
|
28
|
-
},
|
|
29
|
-
generation_requests: any[],
|
|
30
|
-
source_id: string
|
|
31
|
-
) {
|
|
32
|
-
if (data.global_updates.length > 0) {
|
|
33
|
-
await this.writeGlobalUpdates(data.global_updates);
|
|
34
|
-
}
|
|
35
|
-
if (data.global_inserts.length > 0) {
|
|
36
|
-
await this.writeGlobalInserts(data.global_inserts);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
status: "success",
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async writeGlobalUpdates(
|
|
45
|
-
data: {
|
|
46
|
-
id: string;
|
|
47
|
-
currentPayload: {
|
|
48
|
-
_sources: string[];
|
|
49
|
-
text: string;
|
|
50
|
-
};
|
|
51
|
-
sourceIdToAdd: string;
|
|
52
|
-
}[]
|
|
53
|
-
) {
|
|
54
|
-
const operations = data.map((e) => {
|
|
55
|
-
return {
|
|
56
|
-
set_payload: {
|
|
57
|
-
points: [e.id],
|
|
58
|
-
payload: {
|
|
59
|
-
text: e.currentPayload.text,
|
|
60
|
-
_sources: [e.sourceIdToAdd, ...e.currentPayload._sources],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
await qdrantClient.batchUpdate("concepts-vectors", {
|
|
66
|
-
wait: true,
|
|
67
|
-
operations: operations,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async writeGlobalInserts(
|
|
72
|
-
data: {
|
|
73
|
-
id: string;
|
|
74
|
-
vector: number[];
|
|
75
|
-
payload: {
|
|
76
|
-
_sources: string[];
|
|
77
|
-
text: string;
|
|
78
|
-
};
|
|
79
|
-
}[]
|
|
80
|
-
) {
|
|
81
|
-
await qdrantClient.upsert("concepts-vectors", {
|
|
82
|
-
wait: true,
|
|
83
|
-
points: data,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async wiriteToMondo(
|
|
88
|
-
source_taxonomy: any[],
|
|
89
|
-
generation_requests: any[],
|
|
90
|
-
source_id: string
|
|
91
|
-
) {
|
|
92
|
-
const mondo_data = source_taxonomy.map((e) => {
|
|
93
|
-
return {
|
|
94
|
-
id: e.id,
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
import qdrantClient from "../../services/qdrant_service";
|
|
2
|
+
|
|
3
|
+
export class WriteConsolidatedData {
|
|
4
|
+
async writeConsolidatedData(
|
|
5
|
+
data: {
|
|
6
|
+
source_taxonomy: {
|
|
7
|
+
id: string;
|
|
8
|
+
text: string;
|
|
9
|
+
type: string;
|
|
10
|
+
reference: string;
|
|
11
|
+
}[];
|
|
12
|
+
global_updates: {
|
|
13
|
+
id: string;
|
|
14
|
+
currentPayload: {
|
|
15
|
+
_sources: string[];
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
sourceIdToAdd: string;
|
|
19
|
+
}[];
|
|
20
|
+
global_inserts: {
|
|
21
|
+
id: string;
|
|
22
|
+
vector: number[];
|
|
23
|
+
payload: {
|
|
24
|
+
_sources: string[];
|
|
25
|
+
text: string;
|
|
26
|
+
};
|
|
27
|
+
}[];
|
|
28
|
+
},
|
|
29
|
+
generation_requests: any[],
|
|
30
|
+
source_id: string
|
|
31
|
+
) {
|
|
32
|
+
if (data.global_updates.length > 0) {
|
|
33
|
+
await this.writeGlobalUpdates(data.global_updates);
|
|
34
|
+
}
|
|
35
|
+
if (data.global_inserts.length > 0) {
|
|
36
|
+
await this.writeGlobalInserts(data.global_inserts);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
status: "success",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async writeGlobalUpdates(
|
|
45
|
+
data: {
|
|
46
|
+
id: string;
|
|
47
|
+
currentPayload: {
|
|
48
|
+
_sources: string[];
|
|
49
|
+
text: string;
|
|
50
|
+
};
|
|
51
|
+
sourceIdToAdd: string;
|
|
52
|
+
}[]
|
|
53
|
+
) {
|
|
54
|
+
const operations = data.map((e) => {
|
|
55
|
+
return {
|
|
56
|
+
set_payload: {
|
|
57
|
+
points: [e.id],
|
|
58
|
+
payload: {
|
|
59
|
+
text: e.currentPayload.text,
|
|
60
|
+
_sources: [e.sourceIdToAdd, ...e.currentPayload._sources],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
await qdrantClient.batchUpdate("concepts-vectors", {
|
|
66
|
+
wait: true,
|
|
67
|
+
operations: operations,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async writeGlobalInserts(
|
|
72
|
+
data: {
|
|
73
|
+
id: string;
|
|
74
|
+
vector: number[];
|
|
75
|
+
payload: {
|
|
76
|
+
_sources: string[];
|
|
77
|
+
text: string;
|
|
78
|
+
};
|
|
79
|
+
}[]
|
|
80
|
+
) {
|
|
81
|
+
await qdrantClient.upsert("concepts-vectors", {
|
|
82
|
+
wait: true,
|
|
83
|
+
points: data,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async wiriteToMondo(
|
|
88
|
+
source_taxonomy: any[],
|
|
89
|
+
generation_requests: any[],
|
|
90
|
+
source_id: string
|
|
91
|
+
) {
|
|
92
|
+
const mondo_data = source_taxonomy.map((e) => {
|
|
93
|
+
return {
|
|
94
|
+
id: e.id,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { OpenAiService } from "../services/open_ai_service";
|
|
2
|
-
|
|
3
|
-
export class GenerateEmbeddings {
|
|
4
|
-
constructor(private readonly openAiService: OpenAiService) {}
|
|
5
|
-
|
|
6
|
-
async generateEmbeddings(
|
|
7
|
-
concepts_facts: { text: string; type: string; reference: string }[]
|
|
8
|
-
) {
|
|
9
|
-
const texts = concepts_facts.map((e: any) => e.text);
|
|
10
|
-
const response = await this.openAiService.sendEmbeddingRequest(texts);
|
|
11
|
-
if (response.status_code !== 200) {
|
|
12
|
-
console.log(response);
|
|
13
|
-
throw new Error(response.message);
|
|
14
|
-
}
|
|
15
|
-
const embeddings = response.data.data.sort((a: any) => a.index);
|
|
16
|
-
const model = response.data.model;
|
|
17
|
-
const usage = response.data.usage;
|
|
18
|
-
const embeddings_map = [];
|
|
19
|
-
for (let i = 0; i < concepts_facts.length; i++) {
|
|
20
|
-
embeddings_map.push({
|
|
21
|
-
text: concepts_facts[i].text,
|
|
22
|
-
type: concepts_facts[i].type,
|
|
23
|
-
embedding: embeddings[i].embedding,
|
|
24
|
-
reference: concepts_facts[i].reference,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
// return embeddings_map;
|
|
28
|
-
return {
|
|
29
|
-
concepts_facts: embeddings_map,
|
|
30
|
-
metadata: {
|
|
31
|
-
req_time: new Date().toISOString(),
|
|
32
|
-
req_type: {
|
|
33
|
-
type: "embedding",
|
|
34
|
-
},
|
|
35
|
-
req_tokens: usage.prompt_tokens,
|
|
36
|
-
res_tokens: usage.completion_tokens,
|
|
37
|
-
model: model,
|
|
38
|
-
usage: usage,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
2
|
+
|
|
3
|
+
export class GenerateEmbeddings {
|
|
4
|
+
constructor(private readonly openAiService: OpenAiService) {}
|
|
5
|
+
|
|
6
|
+
async generateEmbeddings(
|
|
7
|
+
concepts_facts: { text: string; type: string; reference: string }[]
|
|
8
|
+
) {
|
|
9
|
+
const texts = concepts_facts.map((e: any) => e.text);
|
|
10
|
+
const response = await this.openAiService.sendEmbeddingRequest(texts);
|
|
11
|
+
if (response.status_code !== 200) {
|
|
12
|
+
console.log(response);
|
|
13
|
+
throw new Error(response.message);
|
|
14
|
+
}
|
|
15
|
+
const embeddings = response.data.data.sort((a: any) => a.index);
|
|
16
|
+
const model = response.data.model;
|
|
17
|
+
const usage = response.data.usage;
|
|
18
|
+
const embeddings_map = [];
|
|
19
|
+
for (let i = 0; i < concepts_facts.length; i++) {
|
|
20
|
+
embeddings_map.push({
|
|
21
|
+
text: concepts_facts[i].text,
|
|
22
|
+
type: concepts_facts[i].type,
|
|
23
|
+
embedding: embeddings[i].embedding,
|
|
24
|
+
reference: concepts_facts[i].reference,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// return embeddings_map;
|
|
28
|
+
return {
|
|
29
|
+
concepts_facts: embeddings_map,
|
|
30
|
+
metadata: {
|
|
31
|
+
req_time: new Date().toISOString(),
|
|
32
|
+
req_type: {
|
|
33
|
+
type: "embedding",
|
|
34
|
+
},
|
|
35
|
+
req_tokens: usage.prompt_tokens,
|
|
36
|
+
res_tokens: usage.completion_tokens,
|
|
37
|
+
model: model,
|
|
38
|
+
usage: usage,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { LocalConsolidation } from "./consolidation/local_consolidation";
|
|
2
|
-
|
|
3
|
-
export class ParseEmbeddingResponse {
|
|
4
|
-
parse(
|
|
5
|
-
response: any,
|
|
6
|
-
concepts_facts: { text: string; type: string; reference: string }[]
|
|
7
|
-
) {
|
|
8
|
-
const data = response.data;
|
|
9
|
-
const model = data.model;
|
|
10
|
-
const usage = data.usage;
|
|
11
|
-
const rawEmbeddings = data.data;
|
|
12
|
-
const sorted = rawEmbeddings.sort((e: any) => e.index);
|
|
13
|
-
const embeddings = sorted.map((e: any) => e.embedding);
|
|
14
|
-
const embeddings_map = new Map();
|
|
15
|
-
const embeddings_map_array = [];
|
|
16
|
-
for (let i = 0; i < concepts_facts.length; i++) {
|
|
17
|
-
embeddings_map_array.push({
|
|
18
|
-
text: concepts_facts[i].text,
|
|
19
|
-
type: concepts_facts[i].type,
|
|
20
|
-
embedding: embeddings[i],
|
|
21
|
-
reference: concepts_facts[i].reference,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const embeddingMap = embeddings_map;
|
|
25
|
-
const consolidated = new LocalConsolidation().consolidate(
|
|
26
|
-
embeddings_map_array,
|
|
27
|
-
"sourceID"
|
|
28
|
-
);
|
|
29
|
-
return consolidated;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import { LocalConsolidation } from "./consolidation/local_consolidation";
|
|
2
|
+
|
|
3
|
+
export class ParseEmbeddingResponse {
|
|
4
|
+
parse(
|
|
5
|
+
response: any,
|
|
6
|
+
concepts_facts: { text: string; type: string; reference: string }[]
|
|
7
|
+
) {
|
|
8
|
+
const data = response.data;
|
|
9
|
+
const model = data.model;
|
|
10
|
+
const usage = data.usage;
|
|
11
|
+
const rawEmbeddings = data.data;
|
|
12
|
+
const sorted = rawEmbeddings.sort((e: any) => e.index);
|
|
13
|
+
const embeddings = sorted.map((e: any) => e.embedding);
|
|
14
|
+
const embeddings_map = new Map();
|
|
15
|
+
const embeddings_map_array = [];
|
|
16
|
+
for (let i = 0; i < concepts_facts.length; i++) {
|
|
17
|
+
embeddings_map_array.push({
|
|
18
|
+
text: concepts_facts[i].text,
|
|
19
|
+
type: concepts_facts[i].type,
|
|
20
|
+
embedding: embeddings[i],
|
|
21
|
+
reference: concepts_facts[i].reference,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const embeddingMap = embeddings_map;
|
|
25
|
+
const consolidated = new LocalConsolidation().consolidate(
|
|
26
|
+
embeddings_map_array,
|
|
27
|
+
"sourceID"
|
|
28
|
+
);
|
|
29
|
+
return consolidated;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export enum CardTypeEnum {
|
|
2
|
-
FLASH = "flash",
|
|
3
|
-
CLOZE = "cloze",
|
|
4
|
-
MATCH = "match",
|
|
5
|
-
MCQ = "mcq",
|
|
6
|
-
}
|
|
1
|
+
export enum CardTypeEnum {
|
|
2
|
+
FLASH = "flash",
|
|
3
|
+
CLOZE = "cloze",
|
|
4
|
+
MATCH = "match",
|
|
5
|
+
MCQ = "mcq",
|
|
6
|
+
}
|