# Ingest documents

`POST https://ai.inovacc.dev/v1/vector/ingest`

Store passages in your organization's Vector Database, embedded and ready to be searched by meaning.

## Body params

- `scope` ("shared" | "local"), required: `shared`: visible to every service of your workspace. `local`: visible only to the API key that writes it.
- `documents` (array), required: 1 to 100 passages. A passage that cannot be stored is listed in `skipped` with a reason; the others are stored.
- `documents[].id` (string), required: Your id for the passage, 1 to 256 bytes. Ingesting an existing id in the same scope replaces it.
- `documents[].text` (string), required: The passage, returned by queries. With `id` and `metadata` it must fit in 10 KiB.
- `documents[].metadata` (object): Flat values: strings, numbers, booleans or arrays of strings. `kind`, `source`, `category`, `tag`, `language` and `created_at` can be filtered on.
- `documents[].document_id` (string): Groups passages into one document that can be deleted or replaced as a whole.
- `documents[].generation` (integer): Your version of the document. A higher generation replaces the older one; a deleted document only accepts a higher one.
- `documents[].content_sha256` (string): Your SHA-256 of the document's content, 64 lowercase hex characters, given back by `GET /v1/vector/documents`.

## Headers

- `Authorization` (string), required: Bearer <API key>
- `X-Operation-Id` (string), required: a unique id you choose, on every call except GET
- `Content-Type` (string), required: application/json, on a call with a body

## Request

**cURL**

```sh
curl -X POST "https://ai.inovacc.dev/v1/vector/ingest" \
  -H "Authorization: Bearer $INOVACC_API_KEY" \
  -H "X-Operation-Id: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
}'
```

**TypeScript**

```ts
import crypto from "node:crypto";

const body: Record<string, unknown> = {
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
};

const url = "https://ai.inovacc.dev/v1/vector/ingest";

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.INOVACC_API_KEY}`,
    "X-Operation-Id": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});

console.log(response.status, await response.text());
```

**Python**

```py
import json
import os
import urllib.request
import uuid

body = {
    "scope": "shared",
    "documents": [
        {
            "id": "handbook-leave-1",
            "text": "Employees accrue two and a half days of paid leave per month.",
            "metadata": {
                "category": "hr",
            },
            "document_id": "handbook-leave",
            "generation": 1,
        },
    ],
}

request = urllib.request.Request(
    "https://ai.inovacc.dev/v1/vector/ingest",
    data=json.dumps(body).encode(),
    method="POST",
    headers={
        "User-Agent": "inovacc-python-sample",
        "Authorization": "Bearer " + os.environ["INOVACC_API_KEY"],
        "X-Operation-Id": str(uuid.uuid4()),
        "Content-Type": "application/json",
    },
)

with urllib.request.urlopen(request) as response:
    print(response.status, response.read().decode())
```

**Go**

```go
package main

import (
	"crypto/rand"
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
)

const url = "https://ai.inovacc.dev/v1/vector/ingest"

const body = `{
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
}`

// newUUID returns a random (version 4) UUID, from the standard library alone.
func newUUID() string {
	b := make([]byte, 16)
	if _, err := rand.Read(b); err != nil {
		panic(err)
	}
	b[6] = b[6]&0x0f | 0x40
	b[8] = b[8]&0x3f | 0x80
	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}

func main() {
	req, err := http.NewRequest("POST", url, strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("INOVACC_API_KEY"))
	req.Header.Set("X-Operation-Id", newUUID())
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(out))
}
```

**Rust**

```rs
// Cargo.toml: reqwest = { version = "0.12", features = ["blocking", "json"] }
// Cargo.toml: serde_json = "1"
// Cargo.toml: uuid = { version = "1", features = ["v4"] }

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("INOVACC_API_KEY")?;
    let body = serde_json::json!({
        "scope": "shared",
        "documents": [
            {
                "id": "handbook-leave-1",
                "text": "Employees accrue two and a half days of paid leave per month.",
                "metadata": {
                    "category": "hr"
                },
                "document_id": "handbook-leave",
                "generation": 1
            }
        ]
    });
    let response = reqwest::blocking::Client::new()
        .post("https://ai.inovacc.dev/v1/vector/ingest")
        .bearer_auth(api_key)
        .header("X-Operation-Id", uuid::Uuid::new_v4().to_string())
        .json(&body)
        .send()?;
    println!("{} {}", response.status(), response.text()?);
    Ok(())
}
```

**JavaScript**

```mjs
import crypto from "node:crypto";

const body = {
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
};

const url = "https://ai.inovacc.dev/v1/vector/ingest";

const response = await fetch(url, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.INOVACC_API_KEY}`,
    "X-Operation-Id": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
});

console.log(response.status, await response.text());
```

**PHP**

```php
<?php

$body = <<<'JSON'
{
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
}
JSON;

function uuid4(): string
{
    $bytes = random_bytes(16);
    $bytes[6] = chr(ord($bytes[6]) & 0x0f | 0x40);
    $bytes[8] = chr(ord($bytes[8]) & 0x3f | 0x80);
    return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($bytes), 4));
}

$curl = curl_init('https://ai.inovacc.dev/v1/vector/ingest');
curl_setopt_array($curl, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('INOVACC_API_KEY'),
        'X-Operation-Id: ' . uuid4(),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);

$response = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE), ' ', $response, "\n";
curl_close($curl);
```

**Ruby**

```rb
require "net/http"
require "securerandom"
require "uri"

uri = URI('https://ai.inovacc.dev/v1/vector/ingest')
body = <<~'JSON'
{
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
}
JSON

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('INOVACC_API_KEY')}"
request["X-Operation-Id"] = SecureRandom.uuid
request["Content-Type"] = "application/json"
request.body = body

response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end

puts "#{response.code} #{response.body}"
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.UUID;

public class Main {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("INOVACC_API_KEY");
        String body = "{" +
                "\"scope\": \"shared\"," +
                "\"documents\": [" +
                "{" +
                "\"id\": \"handbook-leave-1\"," +
                "\"text\": \"Employees accrue two and a half days of paid leave per month.\"," +
                "\"metadata\": {" +
                "\"category\": \"hr\"" +
                "}," +
                "\"document_id\": \"handbook-leave\"," +
                "\"generation\": 1" +
                "}" +
                "]" +
                "}";

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://ai.inovacc.dev/v1/vector/ingest"))
                .header("Authorization", "Bearer " + apiKey)
                .header("X-Operation-Id", UUID.randomUUID().toString())
                .header("Content-Type", "application/json")
                .method("POST", HttpRequest.BodyPublishers.ofString(body))
                .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
                .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

**C#**

```cs
using System.Text;

var body = "{" +
    "\"scope\": \"shared\"," +
    "\"documents\": [" +
    "{" +
    "\"id\": \"handbook-leave-1\"," +
    "\"text\": \"Employees accrue two and a half days of paid leave per month.\"," +
    "\"metadata\": {" +
    "\"category\": \"hr\"" +
    "}," +
    "\"document_id\": \"handbook-leave\"," +
    "\"generation\": 1" +
    "}" +
    "]" +
    "}";

var url = "https://ai.inovacc.dev/v1/vector/ingest";
var apiKey = Environment.GetEnvironmentVariable("INOVACC_API_KEY");

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("Authorization", $"Bearer {apiKey}");
request.Headers.Add("X-Operation-Id", Guid.NewGuid().ToString());
request.Content = new StringContent(body, Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

**Kotlin**

```kt
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.util.UUID

fun main() {
    val apiKey = System.getenv("INOVACC_API_KEY")
    val body = "{" +
        "\"scope\": \"shared\"," +
        "\"documents\": [" +
        "{" +
        "\"id\": \"handbook-leave-1\"," +
        "\"text\": \"Employees accrue two and a half days of paid leave per month.\"," +
        "\"metadata\": {" +
        "\"category\": \"hr\"" +
        "}," +
        "\"document_id\": \"handbook-leave\"," +
        "\"generation\": 1" +
        "}" +
        "]" +
        "}"

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://ai.inovacc.dev/v1/vector/ingest"))
        .header("Authorization", "Bearer " + apiKey)
        .header("X-Operation-Id", UUID.randomUUID().toString())
        .header("Content-Type", "application/json")
        .method("POST", HttpRequest.BodyPublishers.ofString(body))
        .build()

    val response = HttpClient.newHttpClient()
        .send(request, HttpResponse.BodyHandlers.ofString())
    println("${response.statusCode()} ${response.body()}")
}
```

**Swift**

```swift
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

let body = #"""
{
  "scope": "shared",
  "documents": [
    {
      "id": "handbook-leave-1",
      "text": "Employees accrue two and a half days of paid leave per month.",
      "metadata": {
        "category": "hr"
      },
      "document_id": "handbook-leave",
      "generation": 1
    }
  ]
}
"""#

let apiKey = ProcessInfo.processInfo.environment["INOVACC_API_KEY"] ?? ""

let url = URL(string: "https://ai.inovacc.dev/v1/vector/ingest")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.setValue(UUID().uuidString, forHTTPHeaderField: "X-Operation-Id")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data(body.utf8)

let (data, response) = try await URLSession.shared.data(for: request)
let status = (response as? HTTPURLResponse)?.statusCode ?? 0
print(status, String(decoding: data, as: UTF8.self))
```

## Response

**200**

```json
{
  "ingested": 1,
  "skipped": []
}
```

**400**: invalid_body, unsupported_field

**403**: vector_database_disabled

**409**: vector_database_not_created, vector_database_deleting

**413**: request_too_large

**429**: rate_limited, quota_exceeded, concurrency_limited, budget_exhausted

**502**: upstream_error

**503**: service_unavailable

**504**: timeout_error

## See also

- [Authentication](https://developer.inovacc.dev/en/guides/authentication/)
- [Errors](https://developer.inovacc.dev/en/guides/errors/)
- [Limits](https://developer.inovacc.dev/en/guides/limits/)
