{"id":45157391,"url":"https://github.com/couchbase-examples/mastra-nextjs-quickstart","last_synced_at":"2026-02-20T05:02:37.896Z","repository":{"id":300150037,"uuid":"1001239546","full_name":"couchbase-examples/mastra-nextJS-quickstart","owner":"couchbase-examples","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-07T10:40:01.000Z","size":4308,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-07T12:06:30.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/couchbase-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-13T03:55:17.000Z","updated_at":"2025-08-07T10:40:02.000Z","dependencies_parsed_at":"2025-06-20T05:39:05.991Z","dependency_job_id":null,"html_url":"https://github.com/couchbase-examples/mastra-nextJS-quickstart","commit_stats":null,"previous_names":["couchbase-examples/mastra-nextjs-quickstart"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/couchbase-examples/mastra-nextJS-quickstart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fmastra-nextJS-quickstart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fmastra-nextJS-quickstart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fmastra-nextJS-quickstart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fmastra-nextJS-quickstart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchbase-examples","download_url":"https://codeload.github.com/couchbase-examples/mastra-nextJS-quickstart/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase-examples%2Fmastra-nextJS-quickstart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29641929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T03:21:14.183Z","status":"ssl_error","status_checked_at":"2026-02-20T03:18:24.455Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-20T05:02:32.290Z","updated_at":"2026-02-20T05:02:37.890Z","avatar_url":"https://github.com/couchbase-examples.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Couchbase Mastra RAG\n\nA Next.js application that enables users to upload PDF documents and chat with their content using Couchbase vector search and OpenAI embeddings, built with the Mastra framework.\n\n## Quick Start\n\n### Prerequisites\n\n- **Node.js** 22+ and npm/yarn/pnpm\n- **Couchbase Capella** account or local Couchbase cluster\n- **OpenAI API** key for embeddings and chat\n\n### Installation\n\n1. **Clone and install dependencies**\n```bash\ngit clone https://github.com/couchbase-examples/mastra-nextJS-quickstart.git\ncd couchbase-mastra-rag\nnpm install\n```\n\n2. **Environment Configuration**\n\nCreate a `.env` file with these required variables:\n\n```bash\n# Couchbase Vector Store Configuration\nCOUCHBASE_CONNECTION_STRING=couchbase://localhost\nCOUCHBASE_USERNAME=Administrator\nCOUCHBASE_PASSWORD=your_password\nCOUCHBASE_BUCKET_NAME=your_bucket\nCOUCHBASE_SCOPE_NAME=your_scope\nCOUCHBASE_COLLECTION_NAME=your_collection\n\n# Embedding Configuration\nEMBEDDING_MODEL=text-embedding-3-small\nEMBEDDING_DIMENSION=1536\nEMBEDDING_BATCH_SIZE=100\n\n# Chunking Configuration\nCHUNK_SIZE=1000\nCHUNK_OVERLAP=200\n\n# Vector Index Configuration\nVECTOR_INDEX_NAME=document-embeddings\nVECTOR_INDEX_METRIC=cosine\n\n# OpenAI Configuration\nOPENAI_API_KEY=your_openai_api_key \n```\n\n### Setup Guide\n\n1. **Couchbase Setup**\n   - Create a Couchbase Capella account or local cluster\n   - Create a bucket and collection for document storage\n   - Get connection credentials and add to environment variables\n\n2. **OpenAI Setup**\n   - Get API key from [OpenAI Platform](https://platform.openai.com/api-keys)\n   - Add to environment variables\n\n### Running the Application\n\n```bash\n# Development Environment\nnpm run dev\n\n# Production Environment\nnpm run build\nnpm start\n```\n\nOpen [http://localhost:3000](http://localhost:3000) to access the application.\n\n## Screenshots\n\n### PDF Upload Interface\n\n![PDF Upload Page](./public/images/pdfUploader.jpg)\n\n### Chat Interface  \n\n![Chat Interface](./public/images/chatInterface.jpeg)\n\n## Usage\n\n1. **Upload PDF**: Drag and drop or select a PDF file (max 100MB)\n2. **Processing**: The app will extract text, create embeddings, and store in Couchbase\n3. **Chat**: Navigate to the chat interface to ask questions about your document\n4. **Search**: The system uses vector similarity search to find relevant content\n\n## Configuration Details\n\nThe application automatically validates all required environment variables on startup. Key configurations:\n\n- **Embedding Model**: Uses OpenAI's `text-embedding-3-small` by default\n- **Chunking**: Documents split into 100-character chunks with 50-character overlap\n- **Vector Search**: Cosine similarity for semantic search\n- **File Storage**: PDFs stored in `public/assets/` directory\n\n## Architecture\n\n### System Overview\nThe application follows a modern RAG (Retrieval-Augmented Generation) pattern with clear separation between frontend, backend, and data layers.\n\n### Frontend Layer\n- **Framework**: Next.js 15 with React 19\n- **Components**: \n  - `PDFUploader`: Drag-and-drop interface using react-dropzone\n  - `InfoCard`: Application information and instructions\n  - `chatPage`: Chat interface for document interaction\n- **Styling**: Tailwind CSS for responsive design\n- **File Handling**: Client-side PDF validation and FormData submission\n\n### Backend Layer\n- **API Routes**: \n  - `/api/ingestPdf`: Handles PDF upload, text extraction, chunking, and vector storage\n  - `/api/chat`: Chat endpoint for conversational AI functionality\n- **Document Processing**: \n  - PDF text extraction using `pdf-parse`\n  - Text chunking with configurable size and overlap\n  - Embedding generation via OpenAI's text-embedding-3-small\n\n### Data Layer\n- **Vector Database**: Couchbase for high-performance vector search\n  - Stores document embeddings with metadata\n  - Supports cosine similarity search\n  - Auto-creates vector indexes for semantic search\n- **File Storage**: Local filesystem (`public/assets/`) for uploaded PDFs\n\n### AI \u0026 ML Components\n- **Embedding Model**: OpenAI text-embedding-3-small (1536 dimensions)\n- **Agent Framework**: Mastra for AI agent orchestration\n- **Vector Search**: Semantic similarity matching for relevant content retrieval\n\n### Data Flow\n1. **Upload**: User uploads PDF → stored locally + FormData sent to API\n2. **Processing**: PDF text extracted → chunked → embeddings generated → stored in Couchbase\n3. **Query**: User chat input → embedded → vector search → relevant chunks retrieved → LLM response\n4. **Response**: Generated answer returned to user interface\n\n### Configuration Management\n- Environment-based configuration with validation\n- Automatic index creation and management\n- Error handling with graceful fallbacks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fmastra-nextjs-quickstart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchbase-examples%2Fmastra-nextjs-quickstart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase-examples%2Fmastra-nextjs-quickstart/lists"}