add_observations
Enhance entities with text observations and index them for full-text and semantic search on Memento, a local, offline MCP 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 implementation of addObservations: inserts observations for entities, generates embeddings using a transformer model, and stores vectors for semantic search.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:90-110 (registration)MCP tool registration for 'add_observations', defining input schema with Zod and thin handler that calls KnowledgeGraphManager.addObservations and returns JSON response.// Tool: add_observations 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:94-99 (schema)Zod input schema for the add_observations tool: 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.') },