@equationalapplications/core-llm-wiki 4.4.0 → 4.5.0
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 +65 -0
- package/dist/index.d.mts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +56 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2787,16 +2787,20 @@ function scoreFactFor(fact, weights, now) {
|
|
|
2787
2787
|
const recencyDecay = Math.exp(-ageDays / 30);
|
|
2788
2788
|
return confW * weights.confidence + Math.log(1 + fact.access_count) * weights.accessCount + recencyDecay * weights.recency;
|
|
2789
2789
|
}
|
|
2790
|
-
function renderFactMarkdown(fact, includeConfidence, includeTags) {
|
|
2790
|
+
function renderFactMarkdown(fact, includeConfidence, includeTags, includeEntityIds, score) {
|
|
2791
2791
|
const confPart = includeConfidence ? ` (${fact.confidence})` : "";
|
|
2792
2792
|
const tagPart = includeTags && fact.tags.length > 0 ? ` [${fact.tags.join(", ")}]` : "";
|
|
2793
|
-
|
|
2793
|
+
const sourcePart = includeEntityIds ? ` {entity_id=${fact.entity_id}}` : "";
|
|
2794
|
+
const scorePart = score !== void 0 ? ` {score=${score.toFixed(4)}}` : "";
|
|
2795
|
+
return `- **${fact.title}**${confPart}${tagPart}${sourcePart}${scorePart}
|
|
2794
2796
|
${fact.body.replace(/\n/g, "\n ")}`;
|
|
2795
2797
|
}
|
|
2796
|
-
function renderFactPlain(fact, includeConfidence, includeTags) {
|
|
2798
|
+
function renderFactPlain(fact, includeConfidence, includeTags, includeEntityIds, score) {
|
|
2797
2799
|
const confPart = includeConfidence ? ` (${fact.confidence})` : "";
|
|
2798
2800
|
const tagPart = includeTags && fact.tags.length > 0 ? ` [${fact.tags.join(", ")}]` : "";
|
|
2799
|
-
|
|
2801
|
+
const sourcePart = includeEntityIds ? ` {entity_id=${fact.entity_id}}` : "";
|
|
2802
|
+
const scorePart = score !== void 0 ? ` {score=${score.toFixed(4)}}` : "";
|
|
2803
|
+
return `${fact.title}${confPart}${tagPart}${sourcePart}${scorePart}: ${fact.body}`;
|
|
2800
2804
|
}
|
|
2801
2805
|
function renderTaskMarkdown(task) {
|
|
2802
2806
|
return `- [P${task.priority}] ${task.description.replace(/\n/g, "\n ")} (${task.status})`;
|
|
@@ -2820,6 +2824,8 @@ function formatContext(bundle, options) {
|
|
|
2820
2824
|
maxEvents: options?.maxEvents ?? 10,
|
|
2821
2825
|
includeConfidence: options?.includeConfidence ?? true,
|
|
2822
2826
|
includeTags: options?.includeTags ?? true,
|
|
2827
|
+
includeEntityIds: options?.includeEntityIds ?? false,
|
|
2828
|
+
includeFactScores: options?.includeFactScores ?? false,
|
|
2823
2829
|
factWeights: {
|
|
2824
2830
|
confidence: options?.factWeights?.confidence ?? 1,
|
|
2825
2831
|
accessCount: options?.factWeights?.accessCount ?? 0.3,
|
|
@@ -2831,7 +2837,7 @@ function formatContext(bundle, options) {
|
|
|
2831
2837
|
validateMaxOption(opts.maxEvents, "maxEvents");
|
|
2832
2838
|
const weights = opts.factWeights;
|
|
2833
2839
|
const now = Date.now();
|
|
2834
|
-
const sortedFacts = [...bundle.facts].sort((a, b) => scoreFactFor(b, weights, now) - scoreFactFor(a, weights, now)).slice(0, opts.maxFacts);
|
|
2840
|
+
const sortedFacts = bundle.factScores ? [...bundle.facts].slice(0, opts.maxFacts) : [...bundle.facts].sort((a, b) => scoreFactFor(b, weights, now) - scoreFactFor(a, weights, now)).slice(0, opts.maxFacts);
|
|
2835
2841
|
const sortedTasks = [...bundle.tasks].sort((a, b) => b.priority - a.priority || a.created_at - b.created_at).slice(0, opts.maxTasks);
|
|
2836
2842
|
const sortedEvents = [...bundle.events].sort((a, b) => b.created_at - a.created_at).slice(0, opts.maxEvents);
|
|
2837
2843
|
if (sortedFacts.length === 0 && sortedTasks.length === 0 && sortedEvents.length === 0) {
|
|
@@ -2845,7 +2851,7 @@ function formatContext(bundle, options) {
|
|
|
2845
2851
|
lines.push("");
|
|
2846
2852
|
lines.push("### Known Facts");
|
|
2847
2853
|
for (const fact of sortedFacts) {
|
|
2848
|
-
lines.push(renderFactMarkdown(fact, opts.includeConfidence, opts.includeTags));
|
|
2854
|
+
lines.push(renderFactMarkdown(fact, opts.includeConfidence, opts.includeTags, opts.includeEntityIds, opts.includeFactScores ? bundle.factScores?.[fact.id] : void 0));
|
|
2849
2855
|
}
|
|
2850
2856
|
}
|
|
2851
2857
|
if (sortedTasks.length > 0) {
|
|
@@ -2866,7 +2872,7 @@ function formatContext(bundle, options) {
|
|
|
2866
2872
|
if (sortedFacts.length > 0) {
|
|
2867
2873
|
lines.push("KNOWN FACTS:");
|
|
2868
2874
|
for (const fact of sortedFacts) {
|
|
2869
|
-
lines.push(renderFactPlain(fact, opts.includeConfidence, opts.includeTags));
|
|
2875
|
+
lines.push(renderFactPlain(fact, opts.includeConfidence, opts.includeTags, opts.includeEntityIds, opts.includeFactScores ? bundle.factScores?.[fact.id] : void 0));
|
|
2870
2876
|
}
|
|
2871
2877
|
}
|
|
2872
2878
|
if (sortedTasks.length > 0) {
|
|
@@ -2985,11 +2991,50 @@ function formatMemoryDump(dump) {
|
|
|
2985
2991
|
};
|
|
2986
2992
|
}
|
|
2987
2993
|
|
|
2994
|
+
// src/librarianPrompt.ts
|
|
2995
|
+
var DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT = `You are a careful memory synthesis assistant.
|
|
2996
|
+
Use only the retrieved context when answering the request.
|
|
2997
|
+
Preserve source provenance when facts come from different entity namespaces.
|
|
2998
|
+
|
|
2999
|
+
Request:
|
|
3000
|
+
{{query}}
|
|
3001
|
+
|
|
3002
|
+
Retrieved context:
|
|
3003
|
+
{{context}}
|
|
3004
|
+
|
|
3005
|
+
Open tasks:
|
|
3006
|
+
{{tasks}}`;
|
|
3007
|
+
function hydrateLibrarianPrompt(template, variables) {
|
|
3008
|
+
return template.replace(/\{\{(context|tasks|query)\}\}/g, (_, key) => variables[key]);
|
|
3009
|
+
}
|
|
3010
|
+
function validateLibrarianPromptTemplate(template, options) {
|
|
3011
|
+
if (!options.custom) return [];
|
|
3012
|
+
const warnings = [];
|
|
3013
|
+
if (!template.includes("{{context}}")) {
|
|
3014
|
+
warnings.push("Custom Librarian systemPrompt omits {{context}}; retrieved memory will not be injected.");
|
|
3015
|
+
}
|
|
3016
|
+
if (!template.includes("{{query}}")) {
|
|
3017
|
+
warnings.push("Custom Librarian systemPrompt omits {{query}}; the original request will not be injected.");
|
|
3018
|
+
}
|
|
3019
|
+
if (options.taskCount > 0 && !template.includes("{{tasks}}")) {
|
|
3020
|
+
warnings.push("Custom Librarian systemPrompt omits {{tasks}} while retrieved tasks are available.");
|
|
3021
|
+
}
|
|
3022
|
+
return warnings;
|
|
3023
|
+
}
|
|
3024
|
+
function mapLibrarianOptionsToReadOptions(options) {
|
|
3025
|
+
const readOptions = {};
|
|
3026
|
+
if (options.entityWeights !== void 0) readOptions.tierWeights = options.entityWeights;
|
|
3027
|
+
if (options.includeZeroWeightEntities !== void 0) {
|
|
3028
|
+
readOptions.includeZeroWeightEntities = options.includeZeroWeightEntities;
|
|
3029
|
+
}
|
|
3030
|
+
return readOptions;
|
|
3031
|
+
}
|
|
3032
|
+
|
|
2988
3033
|
// src/index.ts
|
|
2989
3034
|
function createWiki(db, options) {
|
|
2990
3035
|
return new WikiMemory(db, options);
|
|
2991
3036
|
}
|
|
2992
3037
|
|
|
2993
|
-
export { PrunePartialFailureError, WikiBusyError, WikiMemory, createWiki, formatContext, formatMemoryDump, parseEmbedding };
|
|
3038
|
+
export { DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, PrunePartialFailureError, WikiBusyError, WikiMemory, createWiki, formatContext, formatMemoryDump, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, validateLibrarianPromptTemplate };
|
|
2994
3039
|
//# sourceMappingURL=index.mjs.map
|
|
2995
3040
|
//# sourceMappingURL=index.mjs.map
|