# {{projectName}}

A semantic search API powered by Voyage AI embeddings and MongoDB Atlas Vector Search.

## Configuration

| Setting | Value |
|---------|-------|
| Embedding Model | `{{model}}` |
| Dimensions | {{dimensions}} |
| Database | `{{db}}` |
| Collection | `{{collection}}` |
| Vector Index | `{{index}}` |
{{#if rerank}}
| Rerank Model | `{{rerankModel}}` |
{{/if}}

## Setup

### 1. Install dependencies

```bash
npm install
```

### 2. Configure environment

Copy `.env.example` to `.env` and fill in your credentials:

```bash
cp .env.example .env
```

Required variables:
- `VOYAGE_API_KEY` - Your Voyage AI API key from [dash.voyageai.com](https://dash.voyageai.com)
- `MONGODB_URI` - Your MongoDB Atlas connection string

### 3. Create vector index

In MongoDB Atlas, create a vector search index on your collection:

```json
{
  "fields": [
    {
      "type": "vector",
      "path": "{{field}}",
      "numDimensions": {{dimensions}},
      "similarity": "cosine"
    }
  ]
}
```

Name the index `{{index}}`.

### 4. Ingest documents

```bash
# Ingest a directory of markdown/text files
npm run ingest -- ./docs

# Or ingest a single file
npm run ingest -- ./docs/guide.md
```

### 5. Start the server

```bash
npm start
# or for development with auto-reload
npm run dev
```

## API Endpoints

### POST /api/search

Search for relevant documents.

```bash
curl -X POST http://localhost:3000/api/search \
  -H "Content-Type: application/json" \
  -d '{"query": "How does vector search work?", "limit": 5}'
```

Response:
```json
{
  "results": [
    {
      "text": "Vector search uses...",
      "score": 0.95,
      "metadata": { "source": "docs/guide.md" }
    }
  ],
  "meta": {
    "model": "{{model}}",
    "took": 123
  }
}
```

### POST /api/ingest

Ingest text or a file.

```bash
# Ingest text
curl -X POST http://localhost:3000/api/ingest \
  -H "Content-Type: application/json" \
  -d '{"text": "Your document content...", "metadata": {"source": "api"}}'

# Ingest a file
curl -X POST http://localhost:3000/api/ingest \
  -H "Content-Type: application/json" \
  -d '{"path": "./docs/new-doc.md"}'
```

### GET /api/health

Check API health and database connection.

```bash
curl http://localhost:3000/api/health
```

## Project Structure

```
{{projectName}}/
├── server.js           # Express server entry point
├── lib/
│   ├── client.js       # Voyage AI API client
│   ├── connection.js   # MongoDB connection helper
│   ├── retrieval.js    # RAG retrieval module
│   ├── ingest.js       # Document ingestion pipeline
│   └── search-api.js   # Express API routes
├── .env.example
├── package.json
└── README.md
```

## Chunking Configuration

Documents are chunked with the following settings:

| Setting | Value |
|---------|-------|
| Strategy | `{{chunkStrategy}}` |
| Chunk Size | {{chunkSize}} characters |
| Overlap | {{chunkOverlap}} characters |

---

Generated by [vai](https://github.com/mrlynn/voyageai-cli) v{{vaiVersion}}
