feat: use cache

This commit is contained in:
Mohamed Marrouchi 2025-05-14 08:32:35 +01:00
parent 6de740f683
commit 2b2d508ec7
2 changed files with 23 additions and 3 deletions

View File

@ -132,9 +132,10 @@ export default class LlmNluHelper
// Perform slot filling in a deterministic way since
// it's currently a challenging task for the LLMs.
const entities = await this.nlpEntityService.findAndPopulate({
lookups: { $in: ['keywords', 'pattern'] },
});
const entities = await this.nlpEntityService.getNlpEntitiesByLookup([
'keywords',
'pattern',
]);
const slotEntities = this.runDeterministicSlotFilling(text, entities);

View File

@ -175,4 +175,23 @@ export class NlpEntityService extends BaseService<
return acc;
}, new Map());
}
/**
* Retrieves all NLP entities that declare at least one of the specified
* lookup strategies.
*
* @async
* @param lookups - One or more lookup strategies to match
* against (e.g., {@link LookupStrategy.keywords}, {@link LookupStrategy.pattern}).
* An entity is included in the result if **any** of these strategies is found
* in its own `lookups` array.
* @returns A promise that resolves to the
* collection of matching entities.
*/
async getNlpEntitiesByLookup(lookups: Lookup[]): Promise<NlpEntityFull[]> {
const entities = [...(await this.getNlpMap()).values()];
return entities.filter((e) => {
return lookups.filter((l) => e.lookups.includes(l)).length > 0;
});
}
}