fawn-memory 0.0.3
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/README.md +118 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +183 -0
- package/dist/index.js.map +1 -0
- package/dist/knowpro/answerContextSchema.d.ts +20 -0
- package/dist/knowpro/answerContextSchema.d.ts.map +1 -0
- package/dist/knowpro/answerContextSchema.js +4 -0
- package/dist/knowpro/answerContextSchema.js.map +1 -0
- package/dist/knowpro/answerResponseSchema.d.ts +7 -0
- package/dist/knowpro/answerResponseSchema.d.ts.map +1 -0
- package/dist/knowpro/answerResponseSchema.js +4 -0
- package/dist/knowpro/answerResponseSchema.js.map +1 -0
- package/dist/knowpro/answerTranslator.d.ts +5 -0
- package/dist/knowpro/answerTranslator.d.ts.map +1 -0
- package/dist/knowpro/answerTranslator.js +10 -0
- package/dist/knowpro/answerTranslator.js.map +1 -0
- package/dist/knowpro/collections.d.ts +14 -0
- package/dist/knowpro/collections.d.ts.map +1 -0
- package/dist/knowpro/collections.js +52 -0
- package/dist/knowpro/collections.js.map +1 -0
- package/dist/knowpro/conversation.d.ts +63 -0
- package/dist/knowpro/conversation.d.ts.map +1 -0
- package/dist/knowpro/conversation.js +247 -0
- package/dist/knowpro/conversation.js.map +1 -0
- package/dist/knowpro/dateTimeSchema.d.ts +19 -0
- package/dist/knowpro/dateTimeSchema.d.ts.map +1 -0
- package/dist/knowpro/dateTimeSchema.js +4 -0
- package/dist/knowpro/dateTimeSchema.js.map +1 -0
- package/dist/knowpro/entities.d.ts +9 -0
- package/dist/knowpro/entities.d.ts.map +1 -0
- package/dist/knowpro/entities.js +63 -0
- package/dist/knowpro/entities.js.map +1 -0
- package/dist/knowpro/interfaces.d.ts +637 -0
- package/dist/knowpro/interfaces.d.ts.map +1 -0
- package/dist/knowpro/interfaces.js +4 -0
- package/dist/knowpro/interfaces.js.map +1 -0
- package/dist/knowpro/knowledge.d.ts +19 -0
- package/dist/knowpro/knowledge.d.ts.map +1 -0
- package/dist/knowpro/knowledge.js +97 -0
- package/dist/knowpro/knowledge.js.map +1 -0
- package/dist/knowpro/knowledgeSchema.d.ts +39 -0
- package/dist/knowpro/knowledgeSchema.d.ts.map +1 -0
- package/dist/knowpro/knowledgeSchema.js +2 -0
- package/dist/knowpro/knowledgeSchema.js.map +1 -0
- package/dist/knowpro/llmProvider.d.ts +17 -0
- package/dist/knowpro/llmProvider.d.ts.map +1 -0
- package/dist/knowpro/llmProvider.js +105 -0
- package/dist/knowpro/llmProvider.js.map +1 -0
- package/dist/knowpro/relatedTermsSchema.d.ts +24 -0
- package/dist/knowpro/relatedTermsSchema.d.ts.map +1 -0
- package/dist/knowpro/relatedTermsSchema.js +6 -0
- package/dist/knowpro/relatedTermsSchema.js.map +1 -0
- package/dist/knowpro/schema.d.ts +24 -0
- package/dist/knowpro/schema.d.ts.map +1 -0
- package/dist/knowpro/schema.js +55 -0
- package/dist/knowpro/schema.js.map +1 -0
- package/dist/knowpro/search.d.ts +8 -0
- package/dist/knowpro/search.d.ts.map +1 -0
- package/dist/knowpro/search.js +448 -0
- package/dist/knowpro/search.js.map +1 -0
- package/dist/knowpro/searchQuerySchema.d.ts +40 -0
- package/dist/knowpro/searchQuerySchema.d.ts.map +1 -0
- package/dist/knowpro/searchQuerySchema.js +4 -0
- package/dist/knowpro/searchQuerySchema.js.map +1 -0
- package/dist/knowpro/searchQueryTranslator.d.ts +33 -0
- package/dist/knowpro/searchQueryTranslator.d.ts.map +1 -0
- package/dist/knowpro/searchQueryTranslator.js +47 -0
- package/dist/knowpro/searchQueryTranslator.js.map +1 -0
- package/dist/knowpro/semanticRef.d.ts +4 -0
- package/dist/knowpro/semanticRef.d.ts.map +1 -0
- package/dist/knowpro/semanticRef.js +62 -0
- package/dist/knowpro/semanticRef.js.map +1 -0
- package/dist/knowpro/semanticRefIndex.d.ts +48 -0
- package/dist/knowpro/semanticRefIndex.d.ts.map +1 -0
- package/dist/knowpro/semanticRefIndex.js +388 -0
- package/dist/knowpro/semanticRefIndex.js.map +1 -0
- package/dist/knowpro/storageProvider.d.ts +7 -0
- package/dist/knowpro/storageProvider.d.ts.map +1 -0
- package/dist/knowpro/storageProvider.js +61 -0
- package/dist/knowpro/storageProvider.js.map +1 -0
- package/dist/knowpro/timestampIndex.d.ts +43 -0
- package/dist/knowpro/timestampIndex.d.ts.map +1 -0
- package/dist/knowpro/timestampIndex.js +324 -0
- package/dist/knowpro/timestampIndex.js.map +1 -0
- package/dist/rag/chunking.d.ts +6 -0
- package/dist/rag/chunking.d.ts.map +1 -0
- package/dist/rag/chunking.js +83 -0
- package/dist/rag/chunking.js.map +1 -0
- package/dist/rag/embeddingProvider.d.ts +34 -0
- package/dist/rag/embeddingProvider.d.ts.map +1 -0
- package/dist/rag/embeddingProvider.js +95 -0
- package/dist/rag/embeddingProvider.js.map +1 -0
- package/dist/rag/index.d.ts +8 -0
- package/dist/rag/index.d.ts.map +1 -0
- package/dist/rag/index.js +7 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/rag/knowproAdapter.d.ts +44 -0
- package/dist/rag/knowproAdapter.d.ts.map +1 -0
- package/dist/rag/knowproAdapter.js +66 -0
- package/dist/rag/knowproAdapter.js.map +1 -0
- package/dist/rag/ragIndex.d.ts +101 -0
- package/dist/rag/ragIndex.d.ts.map +1 -0
- package/dist/rag/ragIndex.js +305 -0
- package/dist/rag/ragIndex.js.map +1 -0
- package/dist/rag/similarity.d.ts +15 -0
- package/dist/rag/similarity.d.ts.map +1 -0
- package/dist/rag/similarity.js +47 -0
- package/dist/rag/similarity.js.map +1 -0
- package/dist/rag/types.d.ts +61 -0
- package/dist/rag/types.d.ts.map +1 -0
- package/dist/rag/types.js +2 -0
- package/dist/rag/types.js.map +1 -0
- package/dist/rag/vectorIndex.d.ts +102 -0
- package/dist/rag/vectorIndex.d.ts.map +1 -0
- package/dist/rag/vectorIndex.js +236 -0
- package/dist/rag/vectorIndex.js.map +1 -0
- package/dist/utils/async.d.ts +25 -0
- package/dist/utils/async.d.ts.map +1 -0
- package/dist/utils/async.js +55 -0
- package/dist/utils/async.js.map +1 -0
- package/dist/utils/string.d.ts +3 -0
- package/dist/utils/string.d.ts.map +1 -0
- package/dist/utils/string.js +15 -0
- package/dist/utils/string.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { printRef } from "./entities.js";
|
|
3
|
+
import { loadSchema } from "./schema.js";
|
|
4
|
+
import { hasTemporalReference, parseTemporalExpression } from "./timestampIndex.js";
|
|
5
|
+
function processTerm(term) {
|
|
6
|
+
return term.toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
function createQuestionPrompt(question) {
|
|
9
|
+
const prompt = [
|
|
10
|
+
"The following is a user question:",
|
|
11
|
+
"===",
|
|
12
|
+
question,
|
|
13
|
+
"",
|
|
14
|
+
"===",
|
|
15
|
+
"- The included [ANSWER CONTEXT] contains information that MAY be relevant to answering the question.",
|
|
16
|
+
"- Answer the user question PRECISELY using ONLY information EXPLICITLY provided in the topics, entities, actions, messages and time ranges/timestamps found in [ANSWER CONTEXT]",
|
|
17
|
+
"- Return 'NoAnswer' if you are unsure, , if the answer is not explicitly in [ANSWER CONTEXT], or if the topics or {entity names, types and facets} in the question are not found in [ANSWER CONTEXT].",
|
|
18
|
+
"- Use the 'name', 'type' and 'facets' properties of the provided JSON entities to identify those highly relevant to answering the question.",
|
|
19
|
+
"- 'origin' and 'audience' fields contain the names of entities involved in communication about the knowledge",
|
|
20
|
+
"**Important:** Communicating DOES NOT imply associations such as authorship, ownership etc. E.g. origin: [X] telling audience [Y, Z] communicating about a book does not imply authorship.",
|
|
21
|
+
"- When asked for lists, ensure the list contents answer the question and nothing else. E.g. for the question 'List all books': List only the books in [ANSWER CONTEXT].",
|
|
22
|
+
"- Use direct quotes only when needed or asked. Otherwise answer in your own words.",
|
|
23
|
+
"- Your answer is readable and complete, with appropriate formatting: line breaks, numbered lists, bullet points etc.",
|
|
24
|
+
];
|
|
25
|
+
return prompt.join("\n");
|
|
26
|
+
}
|
|
27
|
+
function createContextPrompt(typeName, schema, context) {
|
|
28
|
+
let content = schema && schema.length > 0
|
|
29
|
+
? `[ANSWER CONTEXT] for answering user questions is a JSON object of type ${typeName} according to the following TypeScript definitions:\n` +
|
|
30
|
+
`\`\`\`\n${schema}\`\`\`\n`
|
|
31
|
+
: "";
|
|
32
|
+
content += `[ANSWER CONTEXT]\n` + `===\n${context}\n===\n`;
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
export function generateAnswer(rawQuery, compiledQuery, answerTranslator) {
|
|
36
|
+
const prompt = [];
|
|
37
|
+
const questionPrompt = createQuestionPrompt(rawQuery);
|
|
38
|
+
const contextSchema = loadSchema(["answerContextSchema.ts"], import.meta.url);
|
|
39
|
+
const contextContent = JSON.stringify(compiledQuery);
|
|
40
|
+
prompt.push(questionPrompt);
|
|
41
|
+
prompt.push(createContextPrompt("AnswerContext", // TODO figure out if this is the intended use for this param
|
|
42
|
+
contextSchema, contextContent));
|
|
43
|
+
const promptText = prompt.join("\n\n");
|
|
44
|
+
console.log("ANSWER PROMPT");
|
|
45
|
+
console.log(promptText, promptText.length);
|
|
46
|
+
writeFileSync("answerPrompt.txt", promptText);
|
|
47
|
+
return answerTranslator.translate(promptText);
|
|
48
|
+
}
|
|
49
|
+
function scoreFacet(masterTerms, facet) {
|
|
50
|
+
let facetScore = 0;
|
|
51
|
+
if (!facet.name) {
|
|
52
|
+
return facetScore;
|
|
53
|
+
}
|
|
54
|
+
if (masterTerms.includes(facet.name.toLowerCase())) {
|
|
55
|
+
facetScore += 1;
|
|
56
|
+
}
|
|
57
|
+
;
|
|
58
|
+
if (masterTerms.includes(facet.value.toString().toLowerCase())) {
|
|
59
|
+
facetScore += 1;
|
|
60
|
+
}
|
|
61
|
+
;
|
|
62
|
+
return facetScore;
|
|
63
|
+
}
|
|
64
|
+
function scoreEntity(masterTerms, scoreMap, ref) {
|
|
65
|
+
const entity = ref.knowledge;
|
|
66
|
+
let entityScore = 0;
|
|
67
|
+
if (masterTerms.includes(entity.name.toLowerCase())) {
|
|
68
|
+
entityScore += 1;
|
|
69
|
+
}
|
|
70
|
+
;
|
|
71
|
+
entity.type.forEach((type) => {
|
|
72
|
+
if (masterTerms.includes(type.toLowerCase())) {
|
|
73
|
+
entityScore += 1;
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
});
|
|
77
|
+
if (entity.facets) {
|
|
78
|
+
entity.facets.forEach((facet) => {
|
|
79
|
+
entityScore += scoreFacet(masterTerms, facet);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
scoreMap.set(ref, entityScore);
|
|
83
|
+
}
|
|
84
|
+
function scoreTopic(masterTerms, scoreMap, ref) {
|
|
85
|
+
const topic = ref.knowledge;
|
|
86
|
+
const tokens = topic.text.split(" ");
|
|
87
|
+
let topicScore = 0;
|
|
88
|
+
tokens.forEach((token) => {
|
|
89
|
+
if (masterTerms.includes(token.toLowerCase())) {
|
|
90
|
+
topicScore += 1;
|
|
91
|
+
}
|
|
92
|
+
;
|
|
93
|
+
});
|
|
94
|
+
scoreMap.set(ref, topicScore);
|
|
95
|
+
}
|
|
96
|
+
function scoreAction(masterTerms, scoreMap, ref) {
|
|
97
|
+
const action = ref.knowledge;
|
|
98
|
+
let actionScore = 0;
|
|
99
|
+
if (action.indirectObjectEntityName && masterTerms.includes(action.indirectObjectEntityName.toLowerCase())) {
|
|
100
|
+
actionScore += 1;
|
|
101
|
+
}
|
|
102
|
+
;
|
|
103
|
+
if (action.objectEntityName && masterTerms.includes(action.objectEntityName.toLowerCase())) {
|
|
104
|
+
actionScore += 1;
|
|
105
|
+
}
|
|
106
|
+
;
|
|
107
|
+
if (action.subjectEntityName && masterTerms.includes(action.subjectEntityName.toLowerCase())) {
|
|
108
|
+
actionScore += 1;
|
|
109
|
+
}
|
|
110
|
+
;
|
|
111
|
+
if (action.verbTense && masterTerms.includes(action.verbTense.toLowerCase())) {
|
|
112
|
+
actionScore += 1;
|
|
113
|
+
}
|
|
114
|
+
;
|
|
115
|
+
if (action.subjectEntityFacet) {
|
|
116
|
+
actionScore += scoreFacet(masterTerms, action.subjectEntityFacet);
|
|
117
|
+
}
|
|
118
|
+
action.verbs.forEach((verb) => {
|
|
119
|
+
if (masterTerms.includes(verb.toLowerCase())) {
|
|
120
|
+
actionScore += 1;
|
|
121
|
+
}
|
|
122
|
+
;
|
|
123
|
+
});
|
|
124
|
+
scoreMap.set(ref, actionScore);
|
|
125
|
+
}
|
|
126
|
+
function scoreRef(masterTerms, scoreMap, ref) {
|
|
127
|
+
switch (ref.knowledgeType) {
|
|
128
|
+
case "entity": {
|
|
129
|
+
scoreEntity(masterTerms, scoreMap, ref);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case "topic": {
|
|
133
|
+
scoreTopic(masterTerms, scoreMap, ref);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "action": {
|
|
137
|
+
scoreAction(masterTerms, scoreMap, ref);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
default: {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function compileContext(query, semanticRefIndex, semanticRefs, messages, secondaryIndexes, originalQuery) {
|
|
146
|
+
// Get timestamp index from secondary indexes if available
|
|
147
|
+
const timestampIndex = secondaryIndexes?.timestampIndex;
|
|
148
|
+
const termList = new Set();
|
|
149
|
+
// Check if query has temporal reference for ranking
|
|
150
|
+
const hasTimeReference = originalQuery ? hasTemporalReference(originalQuery) : false;
|
|
151
|
+
// Extract time range from query if present
|
|
152
|
+
let queryTimeRange;
|
|
153
|
+
if (hasTimeReference && originalQuery) {
|
|
154
|
+
// Try to parse temporal expression from the query
|
|
155
|
+
const temporalTerms = ['today', 'yesterday', 'last week', 'last month', 'this week', 'this month'];
|
|
156
|
+
for (const term of temporalTerms) {
|
|
157
|
+
if (originalQuery.toLowerCase().includes(term)) {
|
|
158
|
+
queryTimeRange = parseTemporalExpression(term);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Also check if the structured query has a time range
|
|
164
|
+
let structuredTimeRange;
|
|
165
|
+
query.searchExpressions.forEach((expression) => {
|
|
166
|
+
expression.filters.forEach((filter) => {
|
|
167
|
+
if (filter.scopeSubQuery?.timeRange) {
|
|
168
|
+
const tr = filter.scopeSubQuery.timeRange;
|
|
169
|
+
structuredTimeRange = {
|
|
170
|
+
start: new Date(tr.startDate.date.year, tr.startDate.date.month - 1, tr.startDate.date.day),
|
|
171
|
+
end: tr.stopDate
|
|
172
|
+
? new Date(tr.stopDate.date.year, tr.stopDate.date.month - 1, tr.stopDate.date.day, 23, 59, 59)
|
|
173
|
+
: new Date(tr.startDate.date.year, tr.startDate.date.month - 1, tr.startDate.date.day, 23, 59, 59)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
// Use structured time range if available, otherwise use parsed temporal expression
|
|
179
|
+
const effectiveTimeRange = structuredTimeRange || queryTimeRange;
|
|
180
|
+
// TODO: this code can definitely be cleaned up
|
|
181
|
+
query.searchExpressions.forEach((expression) => {
|
|
182
|
+
expression.filters.forEach((filter) => {
|
|
183
|
+
// Entities
|
|
184
|
+
console.log(filter);
|
|
185
|
+
console.log("ENTITY SEARCH TERM ", filter.entitySearchTerms);
|
|
186
|
+
if (filter.entitySearchTerms) {
|
|
187
|
+
filter.entitySearchTerms.forEach((entity) => {
|
|
188
|
+
termList.add(processTerm(entity.name));
|
|
189
|
+
if (entity.facets) {
|
|
190
|
+
entity.facets.forEach((facet) => {
|
|
191
|
+
termList.add(processTerm(facet.facetName));
|
|
192
|
+
termList.add(processTerm(facet.facetValue));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (entity.type) {
|
|
196
|
+
entity.type.forEach((token) => {
|
|
197
|
+
termList.add(processTerm(token));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
// Actions
|
|
203
|
+
console.log("ACTION SEARCH TRERM", filter.actionSearchTerm);
|
|
204
|
+
if (filter.actionSearchTerm) {
|
|
205
|
+
if (filter.actionSearchTerm.actionVerbs) {
|
|
206
|
+
filter.actionSearchTerm.actionVerbs.words.forEach((word) => {
|
|
207
|
+
termList.add(processTerm(word));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
console.log("ACTOR ENTITIES", filter.actionSearchTerm.actorEntities);
|
|
211
|
+
if (filter.actionSearchTerm.actorEntities !== "*") {
|
|
212
|
+
filter.actionSearchTerm.actorEntities.forEach((entity) => {
|
|
213
|
+
termList.add(processTerm(entity.name));
|
|
214
|
+
if (entity.facets) {
|
|
215
|
+
entity.facets.forEach((facet) => {
|
|
216
|
+
termList.add(processTerm(facet.facetName));
|
|
217
|
+
termList.add(processTerm(facet.facetValue));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (entity.type) {
|
|
221
|
+
entity.type.forEach((token) => {
|
|
222
|
+
termList.add(processTerm(token));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
console.log("SCOPE QUERY ", filter.scopeSubQuery);
|
|
229
|
+
// Query Scope
|
|
230
|
+
if (filter.scopeSubQuery) {
|
|
231
|
+
// TBD later as we refine search
|
|
232
|
+
}
|
|
233
|
+
// Additional Search Terms
|
|
234
|
+
console.log("SEARCH TERMS ", filter.searchTerms);
|
|
235
|
+
if (filter.searchTerms) {
|
|
236
|
+
filter.searchTerms.forEach((term) => {
|
|
237
|
+
termList.add(processTerm(term));
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
console.log("QUERY EXPRESSION");
|
|
243
|
+
console.log(termList);
|
|
244
|
+
// 1. get all the terms then lookup all the refs for each term
|
|
245
|
+
// 2. merge refs and order ref groups by highest ranked term (by ref count)
|
|
246
|
+
// 3. TODO create a ranking heuristic for the merged refs LETS GET SEARCH WORKING BEFORE PLAYING WITH THIS
|
|
247
|
+
// 4. stick into answer translator, in addition create a heuristic for ranking chunks
|
|
248
|
+
// add these chunks in the remaining context window (but not in JSON as this uses
|
|
249
|
+
// too many tokens)
|
|
250
|
+
const refCountMap = new Map();
|
|
251
|
+
const refsAccumMap = new Map();
|
|
252
|
+
// Track the weight/score for each ref from the index lookup
|
|
253
|
+
const refWeightMap = new Map(); // semanticRefOrdinal -> max weight
|
|
254
|
+
termList.forEach((term) => {
|
|
255
|
+
const termOrdinals = semanticRefIndex.lookupTerm(term);
|
|
256
|
+
if (termOrdinals) {
|
|
257
|
+
const refs = semanticRefs.getMultiple(termOrdinals.map((ordinal) => ordinal.semanticRefOrdinal));
|
|
258
|
+
refCountMap.set(term, refs.length);
|
|
259
|
+
refsAccumMap.set(term, refs);
|
|
260
|
+
// Track the weight for each ref (use max if seen multiple times)
|
|
261
|
+
for (const ordinal of termOrdinals) {
|
|
262
|
+
const currentWeight = refWeightMap.get(ordinal.semanticRefOrdinal) ?? 0;
|
|
263
|
+
refWeightMap.set(ordinal.semanticRefOrdinal, Math.max(currentWeight, ordinal.score));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
// let finalRefs: SemanticRef[] = [];
|
|
268
|
+
// const sortedCountTermPairs = [...refCountMap.entries()].sort((a, b) => b[1] - a[1]);
|
|
269
|
+
// sortedCountTermPairs.forEach((pair) => {
|
|
270
|
+
// finalRefs = finalRefs.concat(refsAccumMap.get(pair[0]) || []);
|
|
271
|
+
// });
|
|
272
|
+
// Note:
|
|
273
|
+
// Merging of duplicate entities needs to happen at some point in this process but
|
|
274
|
+
// unsure if it should happen at the beginning or after
|
|
275
|
+
// the ranking has been completed.
|
|
276
|
+
//
|
|
277
|
+
// to start we are going to merge after we pull all the refs for the search
|
|
278
|
+
// terms
|
|
279
|
+
// OR MAX WITH TOKEN LIMIT:
|
|
280
|
+
// 1. get all the refs for all of the search terms, merge duplicate entities
|
|
281
|
+
// and actions
|
|
282
|
+
// 2. find the refs that match all the terms, then some, then one
|
|
283
|
+
// rank the refs in that order
|
|
284
|
+
// 3. take the token limit and divide it by two, put the top n ranked
|
|
285
|
+
// refs into the answer context up to token limit/2 tokens
|
|
286
|
+
// 4. for the refs in the answer context, fetch the chunk they were pulled
|
|
287
|
+
// from
|
|
288
|
+
// 5. merge duplicate chunks
|
|
289
|
+
// 6. fill the remaning limit/2 tokens with as many chunks as possible to fit
|
|
290
|
+
// in the token limit
|
|
291
|
+
// console.log(finalRefs);
|
|
292
|
+
// if an entity doesn't have facets is it even worth
|
|
293
|
+
// considering? yes because of its text chunk reference
|
|
294
|
+
// Ref Ranking
|
|
295
|
+
// 1. For each ref, do a dfs traversal over the ref's values
|
|
296
|
+
// looking for other terms
|
|
297
|
+
// 2. score the ref based on how many of the found terms in the
|
|
298
|
+
// refs leaves are found in the query expression
|
|
299
|
+
// 3. assign the score to this ref and sort it in with the other
|
|
300
|
+
// refs
|
|
301
|
+
// 4. Factor in the index weight (from related term expansion) -
|
|
302
|
+
// related terms have lower weight than original terms
|
|
303
|
+
const refScoreMap = new Map();
|
|
304
|
+
refsAccumMap.forEach((semanticRefs, term) => {
|
|
305
|
+
semanticRefs.forEach((ref) => {
|
|
306
|
+
scoreRef([...termList], refScoreMap, ref);
|
|
307
|
+
// Apply index weight to the score (related terms have weight < 1.0)
|
|
308
|
+
const indexWeight = refWeightMap.get(ref.semanticRefOrdinal) ?? 1.0;
|
|
309
|
+
const currentScore = refScoreMap.get(ref) ?? 0;
|
|
310
|
+
refScoreMap.set(ref, currentScore * indexWeight);
|
|
311
|
+
});
|
|
312
|
+
console.log("TERM:", term, "COUNT:", semanticRefs.length);
|
|
313
|
+
});
|
|
314
|
+
// Apply temporal filtering and ranking
|
|
315
|
+
if (timestampIndex && effectiveTimeRange) {
|
|
316
|
+
// Get messages in the time range
|
|
317
|
+
const messagesInRange = timestampIndex.lookupRange({ start: effectiveTimeRange.start, end: effectiveTimeRange.end });
|
|
318
|
+
const messageOrdinalsInRange = new Set(messagesInRange.map(m => m.range.start.messageOrdinal));
|
|
319
|
+
console.log(`Temporal filter: ${messageOrdinalsInRange.size} messages in range ${effectiveTimeRange.start.toISOString()} to ${effectiveTimeRange.end.toISOString()}`);
|
|
320
|
+
// Filter or boost based on time range (check ref's source message)
|
|
321
|
+
for (const [ref, score] of refScoreMap) {
|
|
322
|
+
const messageOrdinal = ref.range.start.messageOrdinal;
|
|
323
|
+
if (messageOrdinalsInRange.has(messageOrdinal)) {
|
|
324
|
+
// Boost refs that match time range
|
|
325
|
+
refScoreMap.set(ref, score * 1.5);
|
|
326
|
+
}
|
|
327
|
+
else if (hasTimeReference) {
|
|
328
|
+
// If query explicitly mentions time, penalize refs outside range
|
|
329
|
+
refScoreMap.set(ref, score * 0.3);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
else if (hasTimeReference && timestampIndex) {
|
|
334
|
+
// Query mentions time but no specific range parsed - add timestamp to context
|
|
335
|
+
// Boost refs that have timestamps so they can be used in the answer
|
|
336
|
+
for (const [ref, score] of refScoreMap) {
|
|
337
|
+
const messageOrdinal = ref.range.start.messageOrdinal;
|
|
338
|
+
const timestamp = timestampIndex.getMessageTimestamp(messageOrdinal);
|
|
339
|
+
if (timestamp) {
|
|
340
|
+
// Slightly boost refs with timestamps for "when" queries
|
|
341
|
+
refScoreMap.set(ref, score * 1.1);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const entities = [];
|
|
346
|
+
const topics = [];
|
|
347
|
+
let contextLength = computeContextLength(entities, topics);
|
|
348
|
+
const CHAR_LIMIT = 30_000;
|
|
349
|
+
const REF_LIMIT = CHAR_LIMIT / 2;
|
|
350
|
+
const MESSAGE_LIMIT = CHAR_LIMIT / 2;
|
|
351
|
+
// print our score map
|
|
352
|
+
const sortedRefs = [...refScoreMap.entries()].sort((a, b) => b[1] - a[1]);
|
|
353
|
+
const selectedRefs = [];
|
|
354
|
+
for (const entry of sortedRefs) {
|
|
355
|
+
printRef(entry[0]);
|
|
356
|
+
console.log(`${entry[0].knowledgeType}, ${entry[1]}`);
|
|
357
|
+
// Get timestamp for this ref if available (via its source message)
|
|
358
|
+
let refTimestamp;
|
|
359
|
+
if (timestampIndex) {
|
|
360
|
+
const messageOrdinal = entry[0].range.start.messageOrdinal;
|
|
361
|
+
refTimestamp = timestampIndex.getMessageTimestamp(messageOrdinal);
|
|
362
|
+
}
|
|
363
|
+
const newKnowledge = {
|
|
364
|
+
knowledge: entry[0].knowledge,
|
|
365
|
+
// Include time range if we have a timestamp
|
|
366
|
+
timeRange: refTimestamp ? { start: refTimestamp, end: refTimestamp } : undefined
|
|
367
|
+
};
|
|
368
|
+
if (entry[0].knowledgeType === "topic") {
|
|
369
|
+
topics.push(newKnowledge);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
entities.push(newKnowledge);
|
|
373
|
+
}
|
|
374
|
+
selectedRefs.push(entry[0]);
|
|
375
|
+
contextLength = computeContextLength(entities, topics);
|
|
376
|
+
if (contextLength >= REF_LIMIT) {
|
|
377
|
+
console.log("Ref token limit has been reached");
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// Message Scoring
|
|
382
|
+
// 1. take the top refs that have filled up the context
|
|
383
|
+
// 2. rank the messages in those ref's ranges in terms of
|
|
384
|
+
// hit count
|
|
385
|
+
// 3. put the messages with the highest hit count up to
|
|
386
|
+
// MESSAGE_LIMIT into the message side of the context
|
|
387
|
+
const referencedMergedMessages = new Map();
|
|
388
|
+
selectedRefs.forEach((ref) => {
|
|
389
|
+
const chunkOrdinal = ref.range.start.messageOrdinal;
|
|
390
|
+
if (!referencedMergedMessages.has(chunkOrdinal)) {
|
|
391
|
+
referencedMergedMessages.set(chunkOrdinal, 1);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const previousValue = referencedMergedMessages.get(chunkOrdinal);
|
|
395
|
+
referencedMergedMessages.set(chunkOrdinal, previousValue + 1);
|
|
396
|
+
});
|
|
397
|
+
let messageLength = 0;
|
|
398
|
+
const selectedMessages = [];
|
|
399
|
+
const seenOrdinals = [];
|
|
400
|
+
selectedRefs.forEach((ref) => {
|
|
401
|
+
const chunkOrdinal = ref.range.start.messageOrdinal;
|
|
402
|
+
if (seenOrdinals.includes(chunkOrdinal)) {
|
|
403
|
+
// message is already in so we skip
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
seenOrdinals.push(chunkOrdinal);
|
|
407
|
+
const message = messages.get(chunkOrdinal);
|
|
408
|
+
if (messageLength <= MESSAGE_LIMIT) {
|
|
409
|
+
selectedMessages.push({
|
|
410
|
+
messageText: message.textChunks,
|
|
411
|
+
timestamp: message.timestamp ? new Date(message.timestamp) : undefined
|
|
412
|
+
});
|
|
413
|
+
printRef(ref);
|
|
414
|
+
console.log(message.textChunks);
|
|
415
|
+
}
|
|
416
|
+
messageLength = computeMessageLength(selectedMessages);
|
|
417
|
+
});
|
|
418
|
+
// const sortedEntries = Array.from(referencedMergedMessages.entries()).sort((a, b) => b[1] - a[1]);
|
|
419
|
+
// sortedEntries.forEach(([ordinal, score]) => {
|
|
420
|
+
// const message = messages.get(ordinal);
|
|
421
|
+
// // todo this should be converted to a loop we can break out of
|
|
422
|
+
// // inefecient code
|
|
423
|
+
// if (messageLength <= MESSAGE_LIMIT) {
|
|
424
|
+
// selectedMessages.push({
|
|
425
|
+
// messageText: message.textChunks
|
|
426
|
+
// });
|
|
427
|
+
// }
|
|
428
|
+
// messageLength = computeMessageLength(selectedMessages);
|
|
429
|
+
// });
|
|
430
|
+
const compiledContext = {
|
|
431
|
+
entities,
|
|
432
|
+
topics,
|
|
433
|
+
messages: selectedMessages
|
|
434
|
+
};
|
|
435
|
+
return compiledContext;
|
|
436
|
+
}
|
|
437
|
+
function computeContextLength(entities, topics) {
|
|
438
|
+
return JSON.stringify({
|
|
439
|
+
entities,
|
|
440
|
+
topics
|
|
441
|
+
}).length;
|
|
442
|
+
}
|
|
443
|
+
function computeMessageLength(messsages) {
|
|
444
|
+
return JSON.stringify({
|
|
445
|
+
messsages
|
|
446
|
+
}).length;
|
|
447
|
+
}
|
|
448
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/knowpro/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAA+B,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEjH,SAAS,WAAW,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC1C,MAAM,MAAM,GAAa;QACrB,mCAAmC;QACnC,KAAK;QACL,QAAQ;QACR,EAAE;QACF,KAAK;QACL,sGAAsG;QACtG,iLAAiL;QACjL,uMAAuM;QACvM,6IAA6I;QAC7I,8GAA8G;QAC9G,4LAA4L;QAC5L,yKAAyK;QACzK,oFAAoF;QACpF,sHAAsH;KACzH,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,mBAAmB,CACxB,QAAgB,EAChB,MAAc,EACd,OAAe;IAEf,IAAI,OAAO,GACP,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QACvB,CAAC,CAAC,0EAA0E,QAAQ,uDAAuD;YACzI,WAAW,MAAM,UAAU;QAC7B,CAAC,CAAC,EA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ACb,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QACD,aAAa,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAA;IACF,oGAAoG;IACpG,gDAAgD;IAChD,6CAA6C;IAC7C,qEAAqE;IACrE,yBAAyB;IACzB,4CAA4C;IAC5C,kCAAkC;IAClC,8CAA8C;IAC9C,cAAc;IACd,QAAQ;IACR,8DAA8D;IAC9D,MAAM;IAGN,MAAM,eAAe,GAAG;QACpB,QAAQ;QACR,MAAM;QACN,QAAQ,EAAE,gBAAgB;KAC7B,CAAC;IACF,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,SAAS,oBAAoB,CAAC,QAA2C,EAAE,MAAyC;IAChH,OAAO,IAAI,CAAC,SAAS,CAAC;QAClB,QAAQ;QACR,MAAM;KACT,CAAC,CAAC,MAAM,CAAC;AACd,CAAC;AAED,SAAS,oBAAoB,CAAC,SAA0C;IACpE,OAAO,IAAI,CAAC,SAAS,CAAC;QAClB,SAAS;KACZ,CAAC,CAAC,MAAM,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DateTimeRange } from "./dateTimeSchema.js";
|
|
2
|
+
export type FacetTerm = {
|
|
3
|
+
facetName: string;
|
|
4
|
+
facetValue: string;
|
|
5
|
+
};
|
|
6
|
+
export type EntityTerm = {
|
|
7
|
+
name: string;
|
|
8
|
+
isNamePronoun: boolean;
|
|
9
|
+
type?: string[];
|
|
10
|
+
facets?: FacetTerm[];
|
|
11
|
+
};
|
|
12
|
+
export type VerbsTerm = {
|
|
13
|
+
words: string[];
|
|
14
|
+
tense: "Past" | "Present" | "Future";
|
|
15
|
+
};
|
|
16
|
+
export type ActionTerm = {
|
|
17
|
+
actionVerbs?: VerbsTerm | undefined;
|
|
18
|
+
actorEntities: EntityTerm[] | "*";
|
|
19
|
+
targetEntities?: EntityTerm[];
|
|
20
|
+
additionalEntities?: EntityTerm[];
|
|
21
|
+
isInformational: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ScopeFilter = {
|
|
24
|
+
entitySearchTerms?: EntityTerm[] | undefined;
|
|
25
|
+
timeRange?: DateTimeRange | undefined;
|
|
26
|
+
};
|
|
27
|
+
export type SearchFilter = {
|
|
28
|
+
actionSearchTerm?: ActionTerm;
|
|
29
|
+
entitySearchTerms?: EntityTerm[];
|
|
30
|
+
searchTerms?: string[];
|
|
31
|
+
scopeSubQuery?: ScopeFilter | undefined;
|
|
32
|
+
};
|
|
33
|
+
export type SearchExpr = {
|
|
34
|
+
rewrittenQuery: string;
|
|
35
|
+
filters: SearchFilter[];
|
|
36
|
+
};
|
|
37
|
+
export type SearchQuery = {
|
|
38
|
+
searchExpressions: SearchExpr[];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=searchQuerySchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchQuerySchema.d.ts","sourceRoot":"","sources":["../../src/knowpro/searchQuerySchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,MAAM,SAAS,GAAG;IAEpB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;CACtB,CAAC;AAMF,MAAM,MAAM,UAAU,GAAG;IAErB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,OAAO,CAAC;IAIvB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;CACxB,CAAC;AAGF,MAAM,MAAM,SAAS,GAAG;IACpB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAErB,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAEpC,aAAa,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC;IAGlC,cAAc,CAAC,EAAE,UAAU,EAAE,CAAC;IAI9B,kBAAkB,CAAC,EAAE,UAAU,EAAE,CAAC;IAKlC,eAAe,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAEtB,iBAAiB,CAAC,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;IAE7C,SAAS,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CACzC,CAAC;AAKF,MAAM,MAAM,YAAY,GAAG;IAEvB,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAG9B,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC;IAMjC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAGvB,aAAa,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IAEvB,OAAO,EAAE,YAAY,EAAE,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAGtB,iBAAiB,EAAE,UAAU,EAAE,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchQuerySchema.js","sourceRoot":"","sources":["../../src/knowpro/searchQuerySchema.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PromptSection, Result, TypeChatLanguageModel, TypeChatJsonTranslator } from "typechat";
|
|
2
|
+
import type * as querySchema from "./searchQuerySchema.js";
|
|
3
|
+
import type { IConversation } from "./interfaces.js";
|
|
4
|
+
/**
|
|
5
|
+
* A TypeChat Translator that turns natural language into structured queries
|
|
6
|
+
* of type: {@link SearchQuery}
|
|
7
|
+
*/
|
|
8
|
+
export interface SearchQueryTranslator {
|
|
9
|
+
translate(request: string, promptPreamble?: string | PromptSection[]): Promise<Result<querySchema.SearchQuery>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a query translator using
|
|
13
|
+
* @param {TypeChatLanguageModel} model
|
|
14
|
+
* @returns {SearchQueryTranslator}
|
|
15
|
+
*/
|
|
16
|
+
export declare function createSearchQueryTranslator(model: TypeChatLanguageModel): SearchQueryTranslator;
|
|
17
|
+
/**
|
|
18
|
+
* Create a query translator using
|
|
19
|
+
* @param {TypeChatLanguageModel} model
|
|
20
|
+
* @param schemaFilePath Relative path to schema file
|
|
21
|
+
* @returns {SearchQueryTranslator}
|
|
22
|
+
*/
|
|
23
|
+
export declare function createSearchQueryJsonTranslator<T extends querySchema.SearchQuery>(model: TypeChatLanguageModel, schemaFilePath: string): TypeChatJsonTranslator<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Translate natural language query into a SearchQuery expression
|
|
26
|
+
* @param conversation
|
|
27
|
+
* @param queryTranslator
|
|
28
|
+
* @param text
|
|
29
|
+
* @param promptPreamble
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function searchQueryFromLanguage(conversation: IConversation, queryTranslator: SearchQueryTranslator, text: string, promptPreamble?: PromptSection[]): Promise<Result<querySchema.SearchQuery>>;
|
|
33
|
+
//# sourceMappingURL=searchQueryTranslator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchQueryTranslator.d.ts","sourceRoot":"","sources":["../../src/knowpro/searchQueryTranslator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,aAAa,EACb,MAAM,EACN,qBAAqB,EACrB,sBAAsB,EAAC,MAAM,UAAU,CAAC;AAI5C,OAAO,KAAK,KAAK,WAAW,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,SAAS,CACL,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,MAAM,GAAG,aAAa,EAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACvC,KAAK,EAAE,qBAAqB,GAC7B,qBAAqB,CAUvB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC3C,CAAC,SAAS,WAAW,CAAC,WAAW,EAEjC,KAAK,EAAE,qBAAqB,EAC5B,cAAc,EAAE,MAAM,GACvB,sBAAsB,CAAC,CAAC,CAAC,CAU3B;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CACzC,YAAY,EAAE,aAAa,EAC3B,eAAe,EAAE,qBAAqB,EACtC,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,aAAa,EAAE,GACjC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAQ1C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createJsonTranslator } from "typechat";
|
|
4
|
+
import { createTypeScriptJsonValidator } from "typechat/ts";
|
|
5
|
+
import { loadSchema } from "./schema.js";
|
|
6
|
+
import { getTimeRangePromptSectionForConversation } from "./conversation.js";
|
|
7
|
+
/**
|
|
8
|
+
* Create a query translator using
|
|
9
|
+
* @param {TypeChatLanguageModel} model
|
|
10
|
+
* @returns {SearchQueryTranslator}
|
|
11
|
+
*/
|
|
12
|
+
export function createSearchQueryTranslator(model) {
|
|
13
|
+
const translator = createSearchQueryJsonTranslator(model, "searchQuerySchema.ts");
|
|
14
|
+
return {
|
|
15
|
+
translate(request, promptPreamble) {
|
|
16
|
+
return translator.translate(request, promptPreamble);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a query translator using
|
|
22
|
+
* @param {TypeChatLanguageModel} model
|
|
23
|
+
* @param schemaFilePath Relative path to schema file
|
|
24
|
+
* @returns {SearchQueryTranslator}
|
|
25
|
+
*/
|
|
26
|
+
export function createSearchQueryJsonTranslator(model, schemaFilePath) {
|
|
27
|
+
const typeName = "SearchQuery";
|
|
28
|
+
const searchActionSchema = loadSchema(["dateTimeSchema.ts", schemaFilePath], import.meta.url);
|
|
29
|
+
return createJsonTranslator(model, createTypeScriptJsonValidator(searchActionSchema, typeName));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Translate natural language query into a SearchQuery expression
|
|
33
|
+
* @param conversation
|
|
34
|
+
* @param queryTranslator
|
|
35
|
+
* @param text
|
|
36
|
+
* @param promptPreamble
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export async function searchQueryFromLanguage(conversation, queryTranslator, text, promptPreamble) {
|
|
40
|
+
const timeRange = getTimeRangePromptSectionForConversation(conversation);
|
|
41
|
+
const queryContext = promptPreamble && promptPreamble.length > 0
|
|
42
|
+
? [...promptPreamble, ...timeRange]
|
|
43
|
+
: timeRange;
|
|
44
|
+
const result = await queryTranslator.translate(text, queryContext);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=searchQueryTranslator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchQueryTranslator.js","sourceRoot":"","sources":["../../src/knowpro/searchQueryTranslator.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAOlC,OAAO,EACH,oBAAoB,EACvB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wCAAwC,EAAE,MAAM,mBAAmB,CAAC;AAa7E;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACvC,KAA4B;IAE5B,MAAM,UAAU,GAAG,+BAA+B,CAC9C,KAAK,EACL,sBAAsB,CACzB,CAAC;IACF,OAAO;QACH,SAAS,CAAC,OAAO,EAAE,cAAc;YAC7B,OAAO,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACzD,CAAC;KACJ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,+BAA+B,CAG3C,KAA4B,EAC5B,cAAsB;IAEtB,MAAM,QAAQ,GAAG,aAAa,CAAC;IAC/B,MAAM,kBAAkB,GAAG,UAAU,CACjC,CAAC,mBAAmB,EAAE,cAAc,CAAC,EACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAClB,CAAC;IACF,OAAO,oBAAoB,CACvB,KAAK,EACL,6BAA6B,CAAI,kBAAkB,EAAE,QAAQ,CAAC,CACjE,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,YAA2B,EAC3B,eAAsC,EACtC,IAAY,EACZ,cAAgC;IAEhC,MAAM,SAAS,GAAG,wCAAwC,CAAC,YAAY,CAAC,CAAC;IACzE,MAAM,YAAY,GACd,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC;QACvC,CAAC,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,SAAS,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IACpB,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ISemanticRefCollection } from "./interfaces.js";
|
|
2
|
+
import type { KnowledgeResponse } from "./knowledgeSchema.js";
|
|
3
|
+
export declare function populateSemanticRef(semanticRefs: ISemanticRefCollection, knowledgeResponse: KnowledgeResponse, baseSemanticRefOrdinal: number, messageOrdinal: number): ISemanticRefCollection;
|
|
4
|
+
//# sourceMappingURL=semanticRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semanticRef.d.ts","sourceRoot":"","sources":["../../src/knowpro/semanticRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,wBAAgB,mBAAmB,CAC/B,YAAY,EAAE,sBAAsB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,sBAAsB,EAAE,MAAM,EAC9B,cAAc,EAAE,MAAM,GACvB,sBAAsB,CAgExB"}
|