- OpenAI API (embeddings and chat completions)
- Supabase (database and vector search)
- Nx
Inspired by: supabase-community/nextjs-openai-doc-search
Most code adjusted from Nx, specifically from:
Here is the Nx AI Assistant which this repo replicates (the functionality of).
You can read more about it in our blog post:
- A script to create embeddings from the Angular docs and then save these embeddings on Supabase. Here's what it does:
- Splits each markdown file into sections, based on the markdown headings.
- Creates an embedding for each section using the
text-embedding-ada-002
model fromopenai
. - Saves the section embedding on Supabase.
- A Nest.js app that does the following:
- Creates an embedding for the user query using the
text-embedding-ada-002
model fromopenai
. - Sends the query embedding to Supabase.
- Supabase tries to match the query embedding with the embeddings of the Angular docs sections. Using
pgvector
it tries to find the most similar embeddings. - It returns the most similar sections.
- It concatenates these sections to the user query, along with a prompt, and sends it to
openai
's chat completion API. - It gets back the answer from
openai
and returns it.
- Creates an embedding for the user query using the
- A super simple Angular interface and service and interacts with Nest.js (gets user input, sends it to the server, gets the answer, and displays it).
You need API keys for OpenAI and Supabase. So, you need to fill in the following env vars:
- OPENAI_KEY
- SUPABASE_SERVICE_ROLE_KEY
- PUBLIC_SUPABASE_URL
- Clone the repo, install the deps with
npm i
. - Run the server:
npx nx serve ai-api
- Run the Angular app:
npx nx serve ai-chat
- Navigate to
localhost:4200
and ask a question about Angular.
- Add the docs directory in your .env file.
- Run the script:
nx run embeddings:create
- Nx Docs AI assistant
- OpenAI - GPT Guide
- OpenAI - What are embeddings
- OpenAI - Chat reference
- OpenAI API Node lib GitHub
- OpenAI API Node lib reference
- Supabase vector search guide
- Assistants API blog post
This repo contains the final code from the ng-conf 2024 workshop by Katerina Skroumpelou. You can find the starter version here: https://github.com/mandarini/ai-ng-docs-starter.