Skip to content

Commit 2396581

Browse files
committed
feat(component): fix cache problem
1 parent a44f0a1 commit 2396581

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/components/db-query/nodes/check-cache.node.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ export class CheckCacheNode implements IGraphNode<DbQueryState> {
3232
) {}
3333
prompt = PromptTemplate.fromTemplate(`
3434
<instructions>
35-
You are an expert Semantic analyser, you will be given a prompt and a list of past prompts that were successfully processed, and you need to return the most relevant prompt from the list and in which of the following ways is it relevant -
35+
You are an expert Semantic analyser, you will be given a prompt from the user and a list of past prompts that were handled successfully, along with description of the sql generated from those prompts.
36+
You need to return the most relevant prompt from the list and in which of the following ways is it relevant -
3637
- return '${CacheResults.AsIs}' if the prompt's result would contain the information the user is looking for without any changes in the result, and can be used as it is.
3738
- return '${CacheResults.Similar}' if the prompt's result would be similar to the question in the new prompt but not exactly, and can be modified to get the data user needs.
3839
- return '${CacheResults.NotRelevant}' if the prompt is not relevant to the new prompt at all.
3940
Remember that if the cached prompt has extra information, then still the old prompt could be considered exactly same as long as it does not contradict the new prompt.
4041
</instructions>
41-
<user-question>
42+
<user-prompt>
4243
{prompt}
43-
</user-question>
44+
</user-prompt>
4445
<queries>
4546
{queries}
4647
</queries>
@@ -81,7 +82,7 @@ If no queries are relevant, return '${CacheResults.NotRelevant}' and nothing els
8182
queries: relevantDocs
8283
.map(
8384
(doc, index) =>
84-
`<query-${index + 1}>\n${doc.pageContent}\n</query-${index + 1}>`,
85+
`<query-${index + 1}>\n<prompt>\n${doc.pageContent}\n</prompt>\n<description>${doc.metadata.description}</description></query-${index + 1}>`,
8586
)
8687
.join('\n'),
8788
prompt: state.prompt,

src/components/db-query/services/dataset-helper.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ export class DataSetHelper {
5454
// clear from cache and re-add if likes > 0
5555
await this.vectorStore.delete({
5656
filter: {
57-
metadata: {
58-
datasetId: id,
59-
tenantId: dataset.tenantId,
60-
},
57+
datasetId: id,
58+
tenantId: dataset.tenantId,
6159
},
6260
});
6361
if (dataset.votes > 0) {
6462
await this.vectorStore.addDocuments([
6563
{
66-
pageContent: dataset.description,
64+
pageContent: dataset.prompt,
6765
metadata: {
6866
datasetId: id,
6967
votes: dataset.votes,
68+
description: dataset.description,
7069
type: DbQueryStoredTypes.DataSet,
7170
tenantId: dataset.tenantId,
71+
query: dataset.query,
7272
},
7373
},
7474
]);

src/components/db-query/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ export type QueryCacheMetadata = {
183183
datasetId: string;
184184
query: string;
185185
type: DbQueryStoredTypes.DataSet;
186+
description: string;
187+
votes: number;
186188
};
187189

188190
export type QueryParam = string | number;

0 commit comments

Comments
 (0)