Back to Mastra

Insert embedding in pgvector

examples/basics/rag/insert-embedding-in-pgvector/README.md

2025-12-18869 B
Original Source

Insert embedding in pgvector

A simple example showing how to insert your embedding in pgvector using Mastra and OpenAI.

Prerequisites

  • Node.js 22.13.0 or later
  • pnpm (recommended) or npm
  • OpenAI API key
  • Pgvector DB

Getting Started

  1. Clone the repository and navigate to the project directory:

    bash
    git clone https://github.com/mastra-ai/mastra
    cd examples/basics/rag/insert-embedding-in-pgvector
    
  2. Copy the environment variables file and add your OpenAI API key:

    bash
    cp .env.example .env
    

    Then edit .env and add your OpenAI API key:

    env
    OPENAI_API_KEY=sk-your-api-key-here
    POSTGRES_CONNECTION_STRING=postgresql://your-username:your-password@your-host:your-port/your-database
    
  3. Install dependencies:

    pnpm install
    
  4. Run the example:

    bash
    pnpm start