Merge pull request #1011 from Hexastack/feat/nlp-pattern-lookup-strategy-cache
Some checks failed
Build and Push Docker API Image / build-and-push (push) Has been cancelled
Build and Push Docker Base Image / build-and-push (push) Has been cancelled
Build and Push Docker UI Image / build-and-push (push) Has been cancelled

feat: use cache
This commit is contained in:
Med Marrouchi 2025-05-14 09:05:37 +01:00 committed by GitHub
commit 3d7975ee15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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;
});
}
}