@vectorize-io/hindsight-client 0.4.21 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectorize-io/hindsight-client",
3
- "version": "0.4.21",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript client for Hindsight - Semantic memory system with personality-driven thinking",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -83,6 +83,7 @@ export interface MemoryItemInput {
83
83
  tags?: string[];
84
84
  observation_scopes?: "per_tag" | "combined" | "all_combinations" | string[][];
85
85
  strategy?: string;
86
+ update_mode?: "replace" | "append";
86
87
  }
87
88
 
88
89
  export class HindsightClient {
@@ -137,6 +138,8 @@ export class HindsightClient {
137
138
  entities?: EntityInput[];
138
139
  /** Optional list of tags for this memory */
139
140
  tags?: string[];
141
+ /** How to handle existing documents: 'replace' (default) or 'append' */
142
+ updateMode?: "replace" | "append";
140
143
  }
141
144
  ): Promise<RetainResponse> {
142
145
  const item: {
@@ -147,6 +150,7 @@ export class HindsightClient {
147
150
  document_id?: string;
148
151
  entities?: EntityInput[];
149
152
  tags?: string[];
153
+ update_mode?: "replace" | "append";
150
154
  } = { content };
151
155
  if (options?.timestamp) {
152
156
  item.timestamp =
@@ -169,6 +173,9 @@ export class HindsightClient {
169
173
  if (options?.tags) {
170
174
  item.tags = options.tags;
171
175
  }
176
+ if (options?.updateMode) {
177
+ item.update_mode = options.updateMode;
178
+ }
172
179
 
173
180
  const response = await sdk.retainMemories({
174
181
  client: this.client,
@@ -192,6 +199,7 @@ export class HindsightClient {
192
199
  tags: item.tags,
193
200
  observation_scopes: item.observation_scopes,
194
201
  strategy: item.strategy,
202
+ update_mode: item.update_mode,
195
203
  timestamp:
196
204
  item.timestamp instanceof Date
197
205
  ? item.timestamp.toISOString()
@@ -742,6 +750,51 @@ export class HindsightClient {
742
750
  }
743
751
  }
744
752
 
753
+ /**
754
+ * Serialize a RecallResponse to a string suitable for LLM prompts.
755
+ *
756
+ * Builds a prompt containing:
757
+ * - Facts: each result as a JSON object with text, context, temporal fields,
758
+ * and source_chunk (if the result's chunk_id matches a chunk in the response).
759
+ * - Entities: entity summaries from observations, formatted as sections.
760
+ *
761
+ * Mirrors the format used internally by Hindsight's reflect operation.
762
+ */
763
+ export function recallResponseToPromptString(response: RecallResponse): string {
764
+ const chunksMap = response.chunks ?? {};
765
+ const sections: string[] = [];
766
+
767
+ // Facts
768
+ const formattedFacts = (response.results ?? []).map((result) => {
769
+ const obj: Record<string, string> = { text: result.text };
770
+ if (result.context) obj.context = result.context;
771
+ if (result.occurred_start) obj.occurred_start = result.occurred_start;
772
+ if (result.occurred_end) obj.occurred_end = result.occurred_end;
773
+ if (result.mentioned_at) obj.mentioned_at = result.mentioned_at;
774
+ if (result.chunk_id && chunksMap[result.chunk_id]) {
775
+ obj.source_chunk = chunksMap[result.chunk_id].text;
776
+ }
777
+ return obj;
778
+ });
779
+ sections.push('FACTS:\n' + JSON.stringify(formattedFacts, null, 2));
780
+
781
+ // Entities
782
+ const entities = response.entities;
783
+ if (entities) {
784
+ const entityParts: string[] = [];
785
+ for (const [name, state] of Object.entries(entities)) {
786
+ if (state.observations?.length) {
787
+ entityParts.push(`## ${name}\n${state.observations[0].text}`);
788
+ }
789
+ }
790
+ if (entityParts.length) {
791
+ sections.push('ENTITIES:\n' + entityParts.join('\n\n'));
792
+ }
793
+ }
794
+
795
+ return sections.join('\n\n');
796
+ }
797
+
745
798
  // Re-export types for convenience
746
799
  export type {
747
800
  RetainRequest,