Skip to documentation
Docs navigation
Docs/Configure database, model, embedding, and optional Redis settings
Setup

Configure database, model, embedding, and optional Redis settings.

MemoGrafter resolves database and Studio settings from CLI flags, environment variables, and generated config.

Environment variables

.env
# MemoGrafter stores graph memory in PostgreSQL.
DATABASE_URL=postgres://postgres:postgres@localhost:5432/memo_grafter
# Add only the providers your adapters use.
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=...
# Required only for queue mode or recall caching.
REDIS_URL=redis://localhost:6379

Generated mg.config.ts

npx memo-grafter init creates src/memo-grafter/mg.config.ts. The CLI loads this project-local file for database access, embeddings, and optional Redis-backed features.

The generated configuration reads credentials from the server environment. Commit the configuration structure, but never place database passwords, provider keys, or Redis credentials directly in the file.

src/memo-grafter/mg.config.ts
declare const process: {
  env: {
    DATABASE_URL?: string;
    OPENAI_API_KEY?: string;
    MEMO_GRAFTER_EMBEDDING_MODEL?: string;
    REDIS_URL?: string;
  };
};
const embeddingModel =
  process.env.MEMO_GRAFTER_EMBEDDING_MODEL ?? "text-embedding-3-small";
export default {
  db: {
    connectionString: process.env.DATABASE_URL,
  },
  // Optional recall cache. Falls back to PostgreSQL if Redis is unavailable.
  // cache: process.env.REDIS_URL
  //   ? { connectionString: process.env.REDIS_URL }
  //   : undefined,
  // Optional Redis-backed ingestion; failed enqueues do not retry synchronously.
  // queue: process.env.REDIS_URL
  //   ? { redisUrl: process.env.REDIS_URL }
  //   : undefined,
  // Set OPENAI_API_KEY or replace this object with your own embedder.
  embedder: process.env.OPENAI_API_KEY
    ? {
        async embed(text: string): Promise<number[]> {
          const response = await fetch(
            "https://api.openai.com/v1/embeddings",
            {
              method: "POST",
              headers: {
                "content-type": "application/json",
                authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
              },
              body: JSON.stringify({
                model: embeddingModel,
                input: text,
              }),
            },
          );
          if (!response.ok) {
            throw new Error(
              `OpenAI embeddings request failed: ${response.status} ${await response.text()}`,
            );
          }
          const body = (await response.json()) as {
            data?: Array<{ embedding?: number[] }>;
          };
          const embedding = body.data?.[0]?.embedding;
          if (!embedding) {
            throw new Error(
              "OpenAI embeddings response did not include an embedding.",
            );
          }
          return embedding;
        },
      }
    : undefined,
};

Configuration options

db.connectionString selects the PostgreSQL database used by migration, Doctor, Studio, and the built-in store.
embedder supplies the embeddings used for topic and memory similarity search. The generated example calls OpenAI only when OPENAI_API_KEY is available.
MEMO_GRAFTER_EMBEDDING_MODEL overrides the generated default embedding model, text-embedding-3-small.
cache.connectionString optionally enables the Redis recall cache. Recall falls back to PostgreSQL when Redis is unavailable.
queue.redisUrl optionally enables Redis-backed ingestion. Queue acceptance and retry behavior should be monitored separately from foreground responses.

Resolution order

A supported CLI option such as --db takes precedence.
The project .env file or process environment is checked next.
The generated src/memo-grafter/mg.config.ts supplies project defaults and optional integrations.
Doctor, migration, and Studio follow the same database resolution order.