add_observations
Add text observations to existing entities and index them for full-text and semantic search within the Memento memory server.
Instructions
Add text observations to existing entities and index them for full-text and semantic search.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| observations | Yes | List of {entityName, contents} pairs. |
Implementation Reference
- src/knowledge-graph-manager.js:64-87 (handler)Core handler function that adds observations to entities: resolves entity IDs, inserts new observations, generates embeddings using embedTexts, and stores observation vectors in the repository.async addObservations(list) { const results = []; for (const { entityName, contents } of list) { const entityId = await this.#repository.getOrCreateEntityId(entityName, 'Unknown'); const inserted = []; for (const content of contents) { const { inserted: wasInserted, observationId } = await this.#repository.insertObservation(entityId, content); if (wasInserted && observationId !== null && observationId !== undefined) { inserted.push({ observationId, content }); } } if (inserted.length) { const embeddings = await this.embedTexts(inserted.map(row => row.content)); const vectorRows = inserted.map((row, index) => ({ observationId: row.observationId, entityId, embedding: embeddings[index] })); await this.#repository.insertObservationVectors(vectorRows); } results.push({ entityName, addedObservations: inserted.map(item => item.content) }); } return results; }
- src/server.js:91-110 (registration)Registers the 'add_observations' MCP tool, defines input schema using Zod, and provides a thin handler that delegates to KnowledgeGraphManager.addObservations and returns JSON-formatted results.this.tool( 'add_observations', 'Add text observations to existing entities and index them for full-text and semantic search.', { observations: z.array(z.object({ entityName: z.string().describe('Name of the entity to annotate.'), contents: z.array(z.string()).describe('List of text observations to add.') })).describe('List of {entityName, contents} pairs.') }, async ({ observations }) => ({ content: [{ type: 'text', text: JSON.stringify( await this.#knowledgeGraphManager.addObservations(observations), null, 2 ) }] }) );
- src/server.js:95-99 (schema)Zod schema defining the input parameters for the add_observations tool: an array of objects with entityName (string) and contents (array of strings).observations: z.array(z.object({ entityName: z.string().describe('Name of the entity to annotate.'), contents: z.array(z.string()).describe('List of text observations to add.') })).describe('List of {entityName, contents} pairs.') },