ChatPPC is a tool to help staff at Gardner Packard Children's Health Center navigate patient care resources, built with Next.js, Vercel AI SDK, and LangChain. This project also uses Supabase as a vector database for retrieval augmented generation (RAG).
- Node.js 18+
- Docker Desktop (for local Supabase development)
- OpenAI API key (for document ingestion and embeddings)
- Install the Supabase CLI:
yarn global add supabase- Clone the repository:
git clone https://github.com/StanfordBDHG/ChatPPC
cd ChatPPC- Install dependencies:
yarn install- Initialize Supabase in your project:
supabase init- Start the Supabase emulator:
supabase startIf this step succeeded, you should see a message that begins with
supabase local development setup is running.
Note the API URL and service_role key that are printed out below this message when the emulator starts, which you will use in the next step.
- Create a
.env.localfile in the root directory with these variables:
OPENAI_API_KEY=your_openai_api_key
SUPABASE_URL={API URL}
SUPABASE_PRIVATE_KEY={service_role key}- Apply database migrations:
supabase migration up- Run the development server:
yarn run dev- Open http://localhost:3000 to view the ChatPPC application. You can also access the Supabase Studio at http://localhost:54323 to view and manage your local database.
Tip
At this point, you can follow the instructions below in the Document Ingestion and Vector Search Optimization sections to add documents and optimize search performance.
├── scripts/ # Executable Node.js scripts
│ ├── ingest.mjs # Document ingestion script
│ └── optimize.mjs # Vector search optimization script
├── tests/ # All test files
│ ├── ingest.test.mjs # Ingestion functionality tests
│ ├── optimize.test.mjs # Optimization script tests
│ └── database.test.mjs # Database connectivity tests
├── supabase/ # Database-related files
│ ├── migrations/ # Database schema changes
│ ├── scripts/ # SQL utility scripts
│ │ ├── optimize-vector-search.sql
│ │ └── verify-indexes.sql
│ └── seed.sql # Initial data seeding
├── app/ # Next.js application pages
├── components/ # React components
└── docs/ # Documentation files for ingestion
The project includes a comprehensive test suite covering document ingestion, vector search optimization, and end-to-end workflows:
# Run all tests (unit + database)
yarn test
# Run only unit tests (fast, no database required)
yarn test:unit
# Run database tests (requires Supabase setup)
yarn test:database
# Run complete test suite including app tests
yarn test:all- Ingestion Tests (
yarn test:ingest): Document processing, hash generation, file handling - Optimization Tests (
yarn test:optimize): Vector index setup, SQL validation, script functionality
- Database Connectivity (
yarn test:database): Supabase connection and vector search functionality - Function Validation: Tests the
match_documentsfunction with various parameters - Performance Testing: Vector search speed and result accuracy
- Unit tests: No external dependencies (always runnable)
- Database tests: Require
SUPABASE_URLandSUPABASE_PRIVATE_KEYenvironment variables - All tests: Node.js 18+ and project dependencies installed
Once you have the development environment set up, follow this workflow:
- Ingest Documents:
yarn ingest docs(add your.mdfiles to thedocsfolder first) - Optimize Search (optional):
yarn optimize(creates database indexes for better performance with larger numbers of documents) - Test Everything:
yarn test(runs comprehensive test suite) - Start Development:
yarn dev(application ready at http://localhost:3000)
The project includes an ingestion script that processes markdown files and stores them in your Supabase vector database for AI retrieval.
Add your markdown files to the docs directory. Each document should be a properly formatted markdown file (.md).
To ingest documents from the docs folder, use the following command:
yarn ingest docsThe script will:
- Scan the specified directory for markdown (
.md) files - Split the content into chunks with appropriate overlap
- Generate embeddings using OpenAI
- Store the embeddings in your Supabase vector database
Note
This section describes optional optimization techniques that may be helpful if encountering slow queries when ingesting larger numbers of documents.
After running document ingestion, you can create vector indexes by running the following script:
yarn optimizeThis script will create and verify:
- HNSW index on embeddings for fast vector similarity search
- GIN index on metadata for efficient filtering
To access the admin dashboard for viewing conversation analytics and managing documents:
- Navigate to the Supabase dashboard and add a new user under
Authenticationwith an email and password. Currently only admins have individual user accounts, whereas users access without an account, therefore any user created in Supabase Authentication is automatically considered an admin. - Navigate to
/adminor click the 📄 icon in the top right of the navbar, then sign in with your admin credentials.

