A Retrieval-Augmented Generation (RAG) application built with Next.js, using:
- Google Cloud Storage (GCS) for file storage
- Upstash Vector for vector database
- Google Gemini for embeddings and LLM (free tier)
- Cohere for reranking (free tier)
User Input (Text/PDF)
→ Upload to GCS
→ Chunk text
→ Generate Embeddings (Gemini)
→ Store in Upstash Vector
User Query
→ Embed query (Gemini)
→ Retrieve top-k from Upstash
→ Rerank with Cohere
→ Generate answer with citations (Gemini)
npm install- Go to Google AI Studio
- Create a new API key
- Copy the key
- Go to Upstash Console
- Create a new Vector Index
- Important: Set dimensions to
768(Gemini embedding size) - Copy the REST URL and REST Token
- Go to Cohere Dashboard
- Create a free API key
- Copy the key
- Go to GCP Console
- Create a bucket (or use existing:
process-venue-assignment) - For authentication, run in terminal:
OR download a service account JSON key and set path in env.
gcloud auth application-default login
# Gemini (Free)
GEMINI_API_KEY=your_gemini_api_key
# Upstash Vector (Free tier)
UPSTASH_VECTOR_REST_URL=https://your-index.upstash.io
UPSTASH_VECTOR_REST_TOKEN=your_token
# Google Cloud Storage
GCS_BUCKET_NAME=process-venue-assignment
# Optional: only if not using gcloud auth
# GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
# Cohere (Free tier)
COHERE_API_KEY=your_cohere_keynpm run devIngest documents into the knowledge base.
Request (FormData):
file: PDF or text filetext: Raw text input
Response:
{ "success": true, "chunks": 5 }Query the knowledge base.
Request:
{ "message": "What is..." }Response:
{
"answer": "Based on the documents, ... [1]",
"citations": [
{ "text": "...", "source": "document.pdf" }
]
}When creating your Upstash Vector index:
- Dimensions:
768(required for Gemini text-embedding-004) - Metric:
cosine(recommended)
- Gemini free tier: 60 requests/minute for embeddings
- Upstash free tier: 10K vectors, 10K queries/day
- Cohere free tier: 100 requests/minute
- Add streaming responses for better UX
- Implement batch embedding for large documents
- Add document management (list, delete)
- Add session history for multi-turn conversations