fawn-memory 0.0.4 → 0.0.7

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.
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import type { DateRange } from "./interfaces.js";
5
+
6
+ export type AnswerContext = {
7
+ // Relevant entities
8
+ // Use the 'name' and 'type' properties of entities to PRECISELY identify those that answer the user question.
9
+ entities?: RelevantKnowledge[] | undefined;
10
+ // Relevant topics
11
+ topics?: RelevantKnowledge[] | undefined;
12
+ // Relevant messages
13
+ messages?: RelevantMessage[] | undefined;
14
+ };
15
+
16
+ export type EntityNames = string | string[];
17
+
18
+ export type RelevantKnowledge = {
19
+ // The actual knowledge
20
+ knowledge: unknown;
21
+ // Entity or entities who mentioned the knowledge
22
+ origin?: EntityNames | undefined;
23
+ // Entity or entities who received or consumed this knowledge
24
+ audience?: EntityNames | undefined;
25
+ // Time period during which this knowledge was gathered
26
+ timeRange?: DateRange | undefined;
27
+ };
28
+
29
+ export type RelevantMessage = {
30
+ from?: EntityNames | undefined;
31
+ to?: EntityNames | undefined;
32
+ timestamp?: Date | undefined;
33
+ // Text chunks in this message
34
+ messageText?: string | string[] | undefined;
35
+ };
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ export type AnswerType =
5
+ | "NoAnswer" // If question cannot be accurately answered from [ANSWER CONTEXT]
6
+ | "Answered"; // Fully answer question
7
+
8
+ export type AnswerResponse = {
9
+ // use "NoAnswer" if no highly relevant answer found in the [ANSWER CONTEXT]
10
+ type: AnswerType;
11
+ // the answer to display if [ANSWER CONTEXT] is highly relevant and can be used to answer the user's question
12
+ answer?: string | undefined;
13
+ // If NoAnswer, explain why..
14
+ // particularly explain why you didn't use any supplied entities
15
+ whyNoAnswer?: string;
16
+ };
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ export type DateVal = {
5
+ day: number;
6
+ month: number;
7
+ year: number;
8
+ };
9
+
10
+ export type TimeVal = {
11
+ // In 24 hour form
12
+ hour: number;
13
+ minute: number;
14
+ seconds: number;
15
+ };
16
+
17
+ export type DateTime = {
18
+ date: DateVal;
19
+ time?: TimeVal | undefined;
20
+ };
21
+
22
+ export type DateTimeRange = {
23
+ startDate: DateTime;
24
+ stopDate?: DateTime | undefined;
25
+ };
@@ -0,0 +1,63 @@
1
+ // Quantity must be a number, do not infer amounts.
2
+ export type Quantity = {
3
+ amount: number;
4
+ units: string;
5
+ };
6
+
7
+ // String quantifier, e.g. 'many', 'few', 'several', 'a lot of', 'some'.
8
+ export type Quantifier = {
9
+ amount: string;
10
+ units: string;
11
+ };
12
+
13
+ export type Value = string | number | boolean | Quantity | Quantifier;
14
+
15
+ export type Facet = {
16
+ name: string;
17
+ // Very concise values.
18
+ value: Value;
19
+ };
20
+
21
+ // Specific, tangible people, places, institutions or things only
22
+ export type ConcreteEntity = {
23
+ // the name of the entity or thing such as "Bach", "Great Gatsby", "frog" or "piano"
24
+ name: string;
25
+ // the types of the entity such as "speaker", "person", "artist", "animal", "object", "instrument", "school", "room", "museum", "food" etc.
26
+ // An entity can have multiple types; entity types should be single words
27
+ type: string[];
28
+ // A specific, inherent, defining, or non-immediate facet of the entity such as "blue", "old", "famous", "sister", "aunt_of", "weight: 4 kg"
29
+ // trivial actions or state changes are not facets
30
+ // facets are concise "properties"
31
+ facets?: Facet[];
32
+ };
33
+
34
+ export type ActionParam = {
35
+ name: string;
36
+ value: Value;
37
+ };
38
+
39
+ export type VerbTense = "past" | "present" | "future";
40
+
41
+ export type Action = {
42
+ // Each verb is typically a word
43
+ verbs: string[];
44
+ verbTense: VerbTense;
45
+ subjectEntityName: string | "none";
46
+ objectEntityName: string | "none";
47
+ indirectObjectEntityName: string | "none";
48
+ params?: (string | ActionParam)[];
49
+ // If the action implies this additional facet or property of the subjectEntity, such as hobbies, activities, interests, personality
50
+ subjectEntityFacet?: Facet | undefined;
51
+ };
52
+
53
+ // Detailed and comprehensive knowledge response
54
+ export type KnowledgeResponse = {
55
+ entities: ConcreteEntity[];
56
+ // The 'subjectEntityName' and 'objectEntityName' must correspond to the 'name' of an entity listed in the 'entities' array.
57
+ actions: Action[];
58
+ // Some actions can ALSO be expressed in a reverse way... e.g. (A give to B) --> (B receive from A) and vice versa
59
+ // If so, also return the reverse form of the action, full filled out
60
+ inverseActions: Action[];
61
+ // Detailed, descriptive topics and keyword.
62
+ topics: string[];
63
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Schema for LLM-based related terms expansion.
3
+ * Given a list of terms, the LLM returns semantically related words.
4
+ */
5
+
6
+ /**
7
+ * A term and its semantically related words.
8
+ */
9
+ export interface TermWithRelated {
10
+ /** The original term */
11
+ term: string;
12
+ /** Semantically related words (synonyms, near-synonyms, conceptually related).
13
+ * Do NOT include morphological variants (plurals, verb tenses) - only semantically different words.
14
+ * Examples: book -> [novel, publication, text], buy -> [purchase, acquire], happy -> [joyful, pleased]
15
+ */
16
+ relatedTerms: string[];
17
+ }
18
+
19
+ /**
20
+ * Response containing related terms for a batch of input terms.
21
+ */
22
+ export interface RelatedTermsResponse {
23
+ /** Array of terms with their related words */
24
+ terms: TermWithRelated[];
25
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import type { DateTimeRange } from "./dateTimeSchema.js";
5
+
6
+ export type FacetTerm = {
7
+ // the name of the facet, such as "color", "profession", "patent number"; "*" means match any facet name
8
+ facetName: string;
9
+ // the value of the facet, such as "red", "writer"; "*" means match any facet value
10
+ facetValue: string;
11
+ };
12
+
13
+ // Use to find information about specific, tangible people, places, institutions or things only..
14
+ // This includes entities with particular facets
15
+ // Abstract concepts or topics are not entityTerms. Use string for them
16
+ // Any terms will match fuzzily.
17
+ export type EntityTerm = {
18
+ // the name of the entity or thing such as "Bach", "Great Gatsby", "frog" or "piano" or "we", "I"; "*" means match any entity name
19
+ name: string;
20
+ isNamePronoun: boolean;
21
+ // the specific types of the entity such as "book", "movie", "song", "speaker", "person", "artist", "animal", "instrument", "school", "room", "museum", "food" etc.
22
+ // Generic types like "object", "thing" etc. are NOT allowed
23
+ // An entity can have multiple types; entity types should be single words
24
+ type?: string[];
25
+ // Facet terms search for properties or attributes of the entity.
26
+ // Eg: color(blue), profession(writer), author(*), aunt(Agatha), weight(4kg), phoneNumber(...), etc.
27
+ facets?: FacetTerm[];
28
+ };
29
+
30
+ // Use for action verbs only. Ensure nouns are not misinterpreted as verbs
31
+ export type VerbsTerm = {
32
+ words: string[]; // individual words in single verb or compound verb
33
+ tense: "Past" | "Present" | "Future";
34
+ };
35
+
36
+ export type ActionTerm = {
37
+ // Action verbs describing the interaction
38
+ actionVerbs?: VerbsTerm | undefined;
39
+ // The origin of the action or information, typically the entity performing the action
40
+ actorEntities: EntityTerm[] | "*";
41
+ // the recipient or target of the action or information
42
+ // Action verbs can imply relevant facet names on the targetEntity. E.g. write -> writer, sing -> singer etc.
43
+ targetEntities?: EntityTerm[];
44
+ // additional entities participating in the action.
45
+ // E.g. in the phrase "Jane ate the spaghetti with the fork", "the fork" would be an additional entity
46
+ // E.g. in the phrase "Did Jane speak about Bach with Nina", "Bach" would be the additional entity
47
+ additionalEntities?: EntityTerm[];
48
+ // Is the intent of the phrase translated to this ActionTerm to actually get information about a specific entities?
49
+ // Examples:
50
+ // true: if asking for specific information about an entity, such as "What did Mia say her phone number was?"
51
+ // false if involves actions and interactions between entities, such as "What phone number did Mia mention in her note to Jane?"
52
+ isInformational: boolean;
53
+ };
54
+
55
+ export type ScopeFilter = {
56
+ // Search terms to use to limit search
57
+ entitySearchTerms?: EntityTerm[] | undefined;
58
+ // Use only if request explicitly asks for time range, particular year, month etc.
59
+ timeRange?: DateTimeRange | undefined; // in this time range
60
+ };
61
+
62
+ //
63
+ // Search a search engine using filters:
64
+ // entitySearchTerms cannot contain entities already in actionSearchTerms
65
+ export type SearchFilter = {
66
+ // Use actionSearchTerm for queries involving actions and interactions between entities.
67
+ actionSearchTerm?: ActionTerm;
68
+ // Use entitySearchTerms for queries asking for specific information about entities and their attributes.
69
+ // E.g. "What is Mia's phone number?" or "Where did Jane study?"
70
+ entitySearchTerms?: EntityTerm[];
71
+ // searchTerms:
72
+ // Concepts, topics or other terms that don't fit (or are not already handled by) ActionTerms or EntityTerms.
73
+ // - Do not use noisy searchTerms like "topic", "topics", "subject", "discussion" etc. even if they are mentioned in the user request
74
+ // - Phrases like 'email address' or 'first name' are a single term
75
+ // - use empty searchTerms array when use asks for summaries
76
+ searchTerms?: string[];
77
+ // Use to limit matches to particular sub-set of a conversation, document, etc
78
+ // E.g. if the user request specifies a particular section or context, use scopeSubQuery to limit the search.
79
+ scopeSubQuery?: ScopeFilter | undefined;
80
+ };
81
+
82
+ export type SearchExpr = {
83
+ rewrittenQuery: string;
84
+ // Translate rewritten query into filters
85
+ filters: SearchFilter[];
86
+ };
87
+
88
+ export type SearchQuery = {
89
+ // One expression for each search required by user request
90
+ // Each SearchExpr runs independently, so make them standalone by resolving references like 'it', 'that', 'them' etc.
91
+ searchExpressions: SearchExpr[];
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fawn-memory",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "dist"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsc -p tsconfig.build.json",
13
+ "build": "tsc -p tsconfig.build.json && shx cp src/knowpro/*Schema.ts dist/knowpro/",
14
14
  "dev": "tsx src/index.ts",
15
15
  "lint": "eslint .",
16
16
  "clean": "rimraf dist",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a",
25
25
  "devDependencies": {
26
+ "shx": "^0.3.4",
26
27
  "@eslint/js": "^9.39.2",
27
28
  "@types/node": "^25.0.2",
28
29
  "@typescript-eslint/eslint-plugin": "^8.50.0",