/**
* Sample function to initialize Mastra storage and memory with Postgres.
* @param {string} connectionString - The PostgreSQL connection string.
*/
async function initializePostgresStorage(connectionString) {
// 1. Initialize the Postgres storage adapter for threads, messages, etc.
const storage = new PostgresStore({
connectionString: connectionString,
});
// 2. Initialize the Postgres vector store for memory/RAG.
// Using connection string provided and reading from env for memory vector configuration
const vectorStore = new PgVector({
connectionString: connectionString ,
});
// 3. Create a memory instance using the Postgres storage and vector store.
const memory = new Memory({
storage,
vectorStore,
options: {
lastMessages: 10,
},
});
// 4. Initialize a new agent using the memory instance.
const agent = new Agent({
id: 'weather-agent',
name: 'Weather Agent',
instructions: ``,
model: 'openai/gpt-4o',
tools: { weatherTool },
memory,
});
return { agent };
}
/**
* Sample function to initialize Mastra storage and memory with Postgres.
* @param {string} connectionString - The PostgreSQL connection string.
*/
async function initializePostgresStorage(connectionString) {
// 1. Initialize the Postgres storage adapter for threads, messages, etc.
const storage = new PostgresStore({
connectionString: connectionString,
});
// 2. Initialize the Postgres vector store for memory/RAG.
// Using connection string provided and reading from env for memory vector configuration
const vectorStore = new PgVector({
connectionString: connectionString ,
});
// 3. Create a memory instance using the Postgres storage and vector store.
const memory = new Memory({
storage,
vectorStore,
options: {
lastMessages: 10,
},
});
// 4. Initialize a new agent using the memory instance.
const agent = new Agent({
id: 'weather-agent',
name: 'Weather Agent',
instructions: ``,
model: 'openai/gpt-4o',
tools: { weatherTool },
memory,
});
return { agent };
}