Skip to content

hyunnaye/cohere-docs

Repository files navigation

CohereDocs - AI-Powered Documentation Search

Built for Cohere Collect Team Application
Full-stack semantic search and RAG chat using Next.js 14, TypeScript, and Cohere AI


SEARCH

image

CHAT

image

Quick Start

# 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

Features

Semantic Search

  • 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

RAG Chat

  • 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

Performance

  • In-memory vectors - No database required
  • Automatic caching - Embeddings cached after first generation

Architecture

┌─────────────────────────────────────────────┐
│           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)     │
└─────────────────────────────────────────────┘

Tech Stack

Frontend

  • 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

Backend

  • Next.js API Routes - Serverless functions
  • Cohere AI SDK - Official TypeScript SDK
  • In-Memory Vector Store - Fast semantic search

Cohere AI Features

  • Embeddings - embed-english-v3.0 (1024 dimensions)
  • Chat - command-r-plus-08-2024 for RAG
  • Rerank - rerank-english-v3.0 for relevance

Configuration

Environment Variables

Create .env.local:

# Required: Your Cohere API key
COHERE_API_KEY=your_cohere_api_key_here

Get your API key: https://dashboard.cohere.com/api-keys

Customization

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"]
    }
  ]
}

Testing

Manual Testing

# 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?"}'

How It Works

Semantic Search Flow

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

RAG Chat Flow

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

Design Decisions

Why In-Memory Vector Store?

  • Fast: No database overhead
  • Simple: No external dependencies
  • Sufficient: 20 docs fit easily in memory

Thank you for your time!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages