Adds a configuration option to fact retrievers to define lifecycle for facts the retriever persists. Possible values are either 'items-to-live' or 'time-to-live'. The former will only n number of items in to the database for each fact per entity. The latter will remove all facts that are older than the TTL value.

Possible values:
* { itl: 5 } // Deletes all facts for the retriever/entity pair, apart from the last five
* { ttl: 1209600000 } // (2 weeks) Deletes all facts older than 2 weeks for the retriever/entity pair
* { ttl: { weeks: 2 } } // Deletes all facts older than 2 weeks for the retriever/entity pair

Signed-off-by: Jussi Hallila <jussi@hallila.com>
This commit is contained in:
Jussi Hallila
2022-01-10 15:38:16 +01:00
parent bc5fe6c6c4
commit dfd5e81721
11 changed files with 286 additions and 19 deletions
+9 -1
View File
@@ -91,7 +91,15 @@ const myFactRetrieverRegistration = createFactRetrieverRegistration(
);
```
Then you can modify the example `techInsights.ts` file shown above like this:
FactRetrieverRegistration also accepts an optional `lifecycle` configuration value. This can be either ITL (items to live) or TTL (time to live). Valid options for this value are either a number for itl or a Luxon duration like object for ttl. For example:
```ts
const itl = { itl: 7 }; // Deletes all but 7 latest facts for each id/entity pair
const ttl = { ttl: 1209600000 }; // (2 weeks) Deletes items older than 2 weeks
const ttlWithAHumanReadableValue = { ttl: { weeks: 2 } }; // Deletes items older than 2 weeks
```
To register these fact retrievers to your application you can modify the example `techInsights.ts` file shown above like this:
```diff
const builder = new DefaultTechInsightsBuilder({