Smritea

TypeScript SDK

Reference for the Smritea TypeScript SDK. Install it, create a client, and call add, search, get and delete.

Ask AI about this page

The TypeScript SDK is the smritea-sdk package. It gives you an async SmriteaClient with four calls: add, search, get and delete. It ships both ESM and CommonJS builds.

Install

npm install smritea-sdk

Import the client from smritea-sdk:

import { SmriteaClient } from 'smritea-sdk';

Create a client

SmriteaClient takes one config object. You must set apiKey and appId. Create them in the dashboard; see Create an app and API key.

OptionTypeDefaultDescription
apiKeystringnoneThe API key, in the form smrt_<prefix>_<secret>.
appIdstringnoneThe app ID, in the form app_....
baseUrlstringhttps://api-us.smritea.aiThe host for your region. See Regions.
maxRetriesnumber2Retries after a rate limit. 0 turns retries off.
traceIdstringnoneA trace ID to send with each call. A bad value throws TypeError.
fetchtypeof fetchglobal fetchYour own fetch function. Set timeouts here.

The client has no timeout option. Pass a fetch that sets one.

Methods

The table lists the client methods and what each one returns.

MethodReturnsDescription
add(content, options?)Promise<MemoryCreationResult>Extracts and stores memories from the text.
search(query, options?)Promise<SearchResult[]>Finds memories that match the query.
get(memoryId)Promise<Memory>Returns one memory by ID.
delete(memoryId)Promise<void>Deletes one memory by ID.

The getAll method exists but throws an error. Use search to find memories.

Add options

The table lists the options that add accepts.

OptionTypeDescription
scopeMemoryScopeWho and what the memory belongs to.
metadataRecord<string, ...>Values must be strings, integers or floats.
eventOccurredAtstringAn RFC 3339 string, such as 2026-11-05T10:00:00Z. Smritea uses it to resolve words like "yesterday" and to date the memory.
relativeStandingobjectThe importance and decay settings for the memory.

Pass relativeStanding as an object literal, such as { importance: 0.9, decayFactor: 0.5, decayFunction: 'exponential' }. The package does not export a type for it, so pass the literal inline or add as const. importance ranges from 0 to 1. decayFactor is 0 or higher. decayFunction takes 'exponential', 'gaussian' or 'linear'. Decay affects quick_search, context_aware_search and deep_search with temporal or rrf_temporal; importance affects deep_search with rrf or rrf_temporal.

Search options

The table lists the options that search accepts.

OptionTypeDescription
scopeMemoryScopeLimits results to this scope.
speakerActorIdstringWho is asking. It never filters results.
limitnumberMost results to return. Omit it to use the app default.
methodstringquick_search, deep_search or context_aware_search.
rerankerTypestringApplies to deep_search only. See Search methods and rerankers.
graphDepthnumberA value from 1 to 5.
validAtstringAn RFC 3339 time. Returns memories valid at that moment.
fromTime, toTimestringAn RFC 3339 range. Use either one alone for an open range.
metadataFilterobjectSee Filter by metadata.

You cannot combine validAt with fromTime or toTime. Put actor and conversation fields inside scope. The client ignores them anywhere else.

Memory scope

MemoryScope decides who a memory belongs to. Every field is optional. See Memory scope for the rules.

FieldDescription
actorIdThe actor's ID, up to 64 characters. Set it with actorType.
actorTypeuser, agent or system.
actorNameA display name, up to 255 characters. Used by add only.
conversationIdA conversation ID, up to 64 characters.
sourceTypeconversation, document or api. Defaults to api.
participantIdsAn array of one or more IDs. Search only.

Results

search returns an array of SearchResult. Each one has a score and a memory. The memory field is optional in the type, so read it with ?..

FieldDescription
scoreThe relevance score.
memory.contentThe memory text.
memory.idThe memory ID.
memory.metadataThe metadata you stored.
memory.scopeThe scope fields of the memory.

add returns a MemoryCreationResult.

FieldDescription
memoriesThe memories the call stored. Empty when explicitSkip is true.
factsExtractedHow many facts the text held.
skippedCountHow many facts the call skipped.
updatedCountHow many existing memories the call updated.
explicitSkipTrue when nothing was worth storing.

Exceptions

Every error derives from SmriteaError. The SDK picks the class from the HTTP status.

ExceptionHTTP statusWhen
SmriteaBadRequestError400A parameter is invalid.
SmriteaUnauthorizedError401The API key is missing or wrong.
SmriteaPaymentRequiredError402Your plan quota has run out.
SmriteaForbiddenError403The key cannot do this.
SmriteaNotFoundError404The memory does not exist.
SmriteaConflictError409The request conflicts with current state.
SmriteaUnprocessableError422The request is well formed but not allowed.
SmriteaTooManyRequestsError429You hit a rate limit.
SmriteaErrorotherAny other failure, including 5xx.

Each exception has httpStatus, code, retryable, body and requestId. SmriteaTooManyRequestsError also has retryAfter, in seconds.

The SDK retries a 429 up to maxRetries times. It never retries a 402. For every code, see Errors and codes.

Example

This script stores a memory, searches for it and handles the failures.

import {
  SmriteaClient,
  SmriteaError,
  SmriteaPaymentRequiredError,
  SmriteaTooManyRequestsError,
} from 'smritea-sdk';

const client = new SmriteaClient({
  apiKey: process.env.SMRITEA_API_KEY!,
  appId: process.env.SMRITEA_APP_ID!,
});
const scope = { actorId: 'alice', actorType: 'user' as const };

try {
  await client.add('Alice is vegetarian and loves hiking', { scope });
  const results = await client.search('What does Alice eat?', { scope });
  for (const r of results) {
    console.log(r.score, r.memory?.content);
  }
} catch (e) {
  if (e instanceof SmriteaPaymentRequiredError) {
    console.log('Plan quota used up (402)');
  } else if (e instanceof SmriteaTooManyRequestsError) {
    console.log(`Rate limited. Retry in ${e.retryAfter}s`);
  } else if (e instanceof SmriteaError) {
    console.log(e.httpStatus, e.code, e.requestId);
  } else {
    throw e;
  }
}

Don't see your language? Request it on GitHub. Search existing requests first and add a 👍 if yours is there. That helps the Smritea team rank requests.

Last updated on