Mem0 TS Spec/Docs Update (#2275)

This commit is contained in:
Saket Aryan
2025-02-28 21:43:51 +05:30
committed by GitHub
parent d9b48191de
commit c1aba35884
9 changed files with 157 additions and 78 deletions

View File

@@ -2,6 +2,9 @@
Mem0 is a self-improving memory layer for LLM applications, enabling personalized AI experiences that save costs and delight users. We offer both cloud and open-source solutions to cater to different needs.
See the complete [OSS Docs](https://docs.mem0.ai/open-source-typescript/quickstart).
See the complete [Platform API Reference](https://docs.mem0.ai/api-reference/overview).
## 1. Installation
For the open-source version, you can install the Mem0 package using npm:

View File

@@ -1,6 +1,6 @@
{
"name": "mem0ai",
"version": "2.0.0",
"version": "2.0.1",
"description": "The Memory Layer For Your AI Apps",
"main": "./dist/index.js",
"module": "./dist/index.mjs",

View File

@@ -1,4 +1,5 @@
export * from "./memory";
export * from "./memory/memory.types";
export * from "./types";
export * from "./embeddings/base";
export * from "./embeddings/openai";
@@ -9,4 +10,6 @@ export * from "./llms/anthropic";
export * from "./llms/groq";
export * from "./vector_stores/base";
export * from "./vector_stores/memory";
export * from "./vector_stores/qdrant";
export * from "./vector_stores/redis";
export * from "./utils/factory";

View File

@@ -24,6 +24,12 @@ import { Embedder } from "../embeddings/base";
import { LLM } from "../llms/base";
import { VectorStore } from "../vector_stores/base";
import { ConfigManager } from "../config/manager";
import {
AddMemoryOptions,
SearchMemoryOptions,
DeleteAllMemoryOptions,
GetAllMemoryOptions,
} from "./memory.types";
export class Memory {
private config: MemoryConfig;
@@ -69,13 +75,17 @@ export class Memory {
async add(
messages: string | Message[],
userId?: string,
agentId?: string,
runId?: string,
metadata: Record<string, any> = {},
filters: SearchFilters = {},
prompt?: string,
config: AddMemoryOptions,
): Promise<SearchResult> {
const {
userId,
agentId,
runId,
metadata = {},
filters = {},
prompt,
} = config;
if (userId) filters.userId = metadata.userId = userId;
if (agentId) filters.agentId = metadata.agentId = agentId;
if (runId) filters.runId = metadata.runId = runId;
@@ -87,7 +97,7 @@ export class Memory {
}
const parsedMessages = Array.isArray(messages)
? messages
? (messages as Message[])
: [{ role: "user", content: messages }];
const vectorStoreResult = await this.addToVectorStore(
@@ -260,12 +270,10 @@ export class Memory {
async search(
query: string,
userId?: string,
agentId?: string,
runId?: string,
limit: number = 100,
filters: SearchFilters = {},
config: SearchMemoryOptions,
): Promise<SearchResult> {
const { userId, agentId, runId, limit = 100, filters = {} } = config;
if (userId) filters.userId = userId;
if (agentId) filters.agentId = agentId;
if (runId) filters.runId = runId;
@@ -322,10 +330,10 @@ export class Memory {
}
async deleteAll(
userId?: string,
agentId?: string,
runId?: string,
config: DeleteAllMemoryOptions,
): Promise<{ message: string }> {
const { userId, agentId, runId } = config;
const filters: SearchFilters = {};
if (userId) filters.userId = userId;
if (agentId) filters.agentId = agentId;
@@ -358,12 +366,9 @@ export class Memory {
);
}
async getAll(
userId?: string,
agentId?: string,
runId?: string,
limit: number = 100,
): Promise<SearchResult> {
async getAll(config: GetAllMemoryOptions): Promise<SearchResult> {
const { userId, agentId, runId, limit = 100 } = config;
const filters: SearchFilters = {};
if (userId) filters.userId = userId;
if (agentId) filters.agentId = agentId;

View File

@@ -0,0 +1,26 @@
import { Message } from "../types";
import { SearchFilters } from "../types";
export interface Entity {
userId?: string;
agentId?: string;
runId?: string;
}
export interface AddMemoryOptions extends Entity {
metadata?: Record<string, any>;
filters?: SearchFilters;
prompt?: string;
}
export interface SearchMemoryOptions extends Entity {
query: string;
limit?: number;
filters?: SearchFilters;
}
export interface GetAllMemoryOptions extends Entity {
limit?: number;
}
export interface DeleteAllMemoryOptions extends Entity {}