Built for Cohere Collect Team Application
Full-stack semantic search and RAG chat using Next.js 14, TypeScript, and Cohere AI
# 1. Install dependencies
npm install
# 2. Set up environment variables
echo "COHERE_API_KEY=your_api_key_here" > .env.local
# 3. Start development server
npm run dev
# 4. Open browser
open http://localhost:3000- AI-powered search - Find documents by meaning, not just keywords
- Relevance scoring - Visual indicators showing match quality
- Smart filtering - Filter by category and tags
- Highlighted snippets - See exactly where your query matches
- Conversational AI - Ask questions in natural language
- Source citations - Every answer includes document references
- Context-aware - Maintains conversation history
- Reranking - Uses Cohere's rerank API for best results
- In-memory vectors - No database required
- Automatic caching - Embeddings cached after first generation
┌─────────────────────────────────────────────┐
│ Next.js 14 Frontend │
│ (React Server Components + Client) │
├─────────────────────────────────────────────┤
│ API Routes (Backend) │
│ /api/init - Initialize vector store │
│ /api/search - Semantic search │
│ /api/chat - RAG with citations │
├─────────────────────────────────────────────┤
│ Core Libraries │
│ VectorStore - In-memory search engine │
│ Cohere API - Embeddings, Chat, Rerank │
├─────────────────────────────────────────────┤
│ Data Layer │
│ 20 Sample Docs - Cohere documentation │
│ Embeddings - 1024-dim vectors (cached) │
└─────────────────────────────────────────────┘
- Next.js 14 - React framework with App Router
- TypeScript - Type safety and better DX
- Tailwind CSS - Utility-first styling
- Framer Motion - Smooth animations
- Lucide React - Beautiful icons
- Next.js API Routes - Serverless functions
- Cohere AI SDK - Official TypeScript SDK
- In-Memory Vector Store - Fast semantic search
- Embeddings -
embed-english-v3.0(1024 dimensions) - Chat -
command-r-plus-08-2024for RAG - Rerank -
rerank-english-v3.0for relevance
Create .env.local:
# Required: Your Cohere API key
COHERE_API_KEY=your_cohere_api_key_hereGet your API key: https://dashboard.cohere.com/api-keys
Update models (lib/cohere.ts):
const EMBEDDING_MODEL = 'embed-english-v3.0';
const CHAT_MODEL = 'command-r-plus-08-2024';
const RERANK_MODEL = 'rerank-english-v3.0';Add more documents (data/sample-docs.json):
{
"documents": [
{
"id": "doc-021",
"title": "Your New Doc",
"category": "Custom",
"content": "...",
"url": "https://...",
"tags": ["tag1", "tag2"]
}
]
}# Test initialization
curl -X POST http://localhost:3000/api/init
# Test search
curl -X POST http://localhost:3000/api/search \
-H "Content-Type: application/json" \
-d '{"query":"embeddings","topK":5}'
# Test chat
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"message":"How do rate limits work?"}'1. User types query: "How to deploy?"
↓
2. Query → Embedding (1024 numbers)
↓
3. Compare with all doc embeddings (cosine similarity)
↓
4. Sort by relevance score
↓
5. Return top 10 results
1. User asks: "What are best practices?"
↓
2. Semantic search finds relevant docs
↓
3. Rerank top 20 → best 5 docs
↓
4. Send docs + question to Cohere Chat API
↓
5. AI reads docs and generates answer
↓
6. Extract citations and sources
↓
7. Show answer with clickable references
- Fast: No database overhead
- Simple: No external dependencies
- Sufficient: 20 docs fit easily in memory