> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# Calcola gli indici RAG in batch

POST https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index
Content-Type: application/json

Recupera e/o crea indici RAG per più documenti della knowledge base in un'unica richiesta. Massimo 100 elementi per richiesta.

Reference: https://elevenlabs.io/docs/eleven-agents/api-reference/knowledge-base/compute-rag-index-batch

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (application/json)

This endpoint expects an object.

- `items` (list of GetOrCreateRagIndexRequestModel, required) — Elenco degli indici RAG richiesti. Minimo 1, massimo 100 elementi.

## Response

### 200

Risposta riuscita

- `map from string to KnowledgeBaseGetOrCreateRagIndexesResponseValue`

## Errors

### 422 Knowledge Base Get or Create Rag Indexes Request Unprocessable Entity Error

Errore di convalida

- `detail` (list of ValidationError, optional)

## Types

### GetOrCreateRagIndexRequestModel

- `document_id` (string, required) — ID del documento della knowledge base di cui recuperare l'indice
- `create_if_missing` (boolean, required) — Indica se creare l'indice RAG se non esiste
- `model` (enum, required, default: e5_mistral_7b_instruct) — Modello di embedding da usare per l'indice RAG
  - Allowed values: `e5_mistral_7b_instruct`, `multilingual_e5_large_instruct`

### KnowledgeBaseGetOrCreateRagIndexesResponseValue

- `status`: `success`
  - `data` (RagDocumentIndexResponseModel, required)
- `status`: `failure`
  - `error_code` (integer, required)
  - `error_message` (string, required)
  - `error_status` (string, required)

### ValidationError

- `loc` (list of ValidationErrorLocItem, required)
- `msg` (string, required)
- `type` (string, required)

### RagDocumentIndexResponseModel

- `id` (string, required)
- `model` (enum, required, default: e5_mistral_7b_instruct)
  - Allowed values: `e5_mistral_7b_instruct`, `multilingual_e5_large_instruct`
- `status` (enum, required)
  - Allowed values: `new`, `created`, `processing`, `failed`, `succeeded`, `rag_limit_exceeded`, `document_too_small`, `cannot_index_folder`
- `progress_percentage` (double, required)
- `document_model_index_usage` (RagDocumentIndexUsage, required)

### ValidationErrorLocItem

### RagDocumentIndexUsage

- `used_bytes` (integer, required)

## Examples

**Request**

```json
{
  "items": [
    {
      "document_id": "document_id",
      "create_if_missing": true,
      "model": "e5_mistral_7b_instruct"
    }
  ]
}
```

**Response**

```json
{
  "key": {
    "status": "success",
    "data": {
      "id": "id",
      "model": "e5_mistral_7b_instruct",
      "status": "new",
      "progress_percentage": 1.1,
      "document_model_index_usage": {
        "used_bytes": 1
      }
    }
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index"

payload = { "items": [
        {
            "document_id": "document_id",
            "create_if_missing": True,
            "model": "e5_mistral_7b_instruct"
        }
    ] }
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"items":[{"document_id":"document_id","create_if_missing":true,"model":"e5_mistral_7b_instruct"}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index"

	payload := strings.NewReader("{\n  \"items\": [\n    {\n      \"document_id\": \"document_id\",\n      \"create_if_missing\": true,\n      \"model\": \"e5_mistral_7b_instruct\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"items\": [\n    {\n      \"document_id\": \"document_id\",\n      \"create_if_missing\": true,\n      \"model\": \"e5_mistral_7b_instruct\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index")
  .header("Content-Type", "application/json")
  .body("{\n  \"items\": [\n    {\n      \"document_id\": \"document_id\",\n      \"create_if_missing\": true,\n      \"model\": \"e5_mistral_7b_instruct\"\n    }\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index', [
  'body' => '{
  "items": [
    {
      "document_id": "document_id",
      "create_if_missing": true,
      "model": "e5_mistral_7b_instruct"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"items\": [\n    {\n      \"document_id\": \"document_id\",\n      \"create_if_missing\": true,\n      \"model\": \"e5_mistral_7b_instruct\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = ["items": [
    [
      "document_id": "document_id",
      "create_if_missing": true,
      "model": "e5_mistral_7b_instruct"
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/knowledge-base/rag-index")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```