Documents API

The Documents API allows you to manage documents in your knowledge base. You can upload files, articles, and website content, search through documents, and manage document metadata.

Base URL

https://api.aloochat.ai/api/public

Authentication

All requests require an API key in the x-api-key header:

x-api-key: your_api_key_here

Endpoints

Get Document

Retrieve a specific document by ID.

Endpoint: GET /documents/{documentId}

Parameters

ParameterTypeRequiredDescription
documentIdstring (UUID)YesThe ID of the document

Example Requests

curl -X GET "https://api.aloochat.ai/api/public/documents/123e4567-e89b-12d3-a456-426614174000" \
  -H "x-api-key: your_api_key_here"

List Documents

Get a paginated list of documents with optional filtering.

Endpoint: POST /documents/list

Request Body

FieldTypeRequiredDescription
categoriesarrayNoFilter by categories
start_datestring (datetime)NoFilter documents created after this date
end_datestring (datetime)NoFilter documents created before this date
collection_idstring (UUID)NoFilter by collection ID
pageintegerNoPage number (default: 1)
limitintegerNoItems per page (default: 10)

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/list" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "categories": ["tech", "documentation"],
    "page": 1,
    "limit": 20,
    "collection_id": "456e7890-e89b-12d3-a456-426614174001"
  }'

Search Documents

Search through documents using various search methods.

Endpoint: POST /documents/search

Request Body

FieldTypeRequiredDescription
querystringYesSearch query
search_methodobjectYesSearch method configuration
top_kintegerNoNumber of results to return (default: 4)
categoriesarrayYesCategories to search within
start_datestring (datetime)NoFilter documents created after this date
end_datestring (datetime)NoFilter documents created before this date
collection_idstring (UUID)NoFilter by collection ID

Search Method Object

FieldTypeRequiredDescription
enable_vectorsearchbooleanNoEnable vector search (default: true)
enable_elasticsearchbooleanNoEnable Elasticsearch (default: true)
enable_mongosearchbooleanNoEnable MongoDB search (default: true)

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/search" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "API documentation",
    "search_method": {
      "enable_vectorsearch": true,
      "enable_elasticsearch": true,
      "enable_mongosearch": true
    },
    "top_k": 5,
    "categories": ["tech", "documentation"]
  }'

Upload File

Upload a document file (PDF, DOCX) for processing.

Endpoint: POST /documents/upload/file

Form Data Parameters

ParameterTypeRequiredDescription
filefileYesPDF or DOCX file to upload
document_titlestringYesTitle for the document
categoriesstringNoJSON array of category strings
collection_idstring (UUID)NoCollection ID to associate with the document

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/upload/file" \
  -H "x-api-key: your_api_key_here" \
  -F "file=@document.pdf" \
  -F "document_title=API Documentation" \
  -F "categories=[\"tech\", \"documentation\"]" \
  -F "collection_id=456e7890-e89b-12d3-a456-426614174001"

Example Response

{
  "task_id": "task_123e4567-e89b-12d3-a456-426614174000",
  "document_id": "doc_456e7890-e89b-12d3-a456-426614174001",
  "status": "pending"
}

Upload Article

Upload plain text content as a document.

Endpoint: POST /documents/upload/article

Request Body

FieldTypeRequiredDescription
contentstringYesThe article text content
document_titlestringYesTitle for the document
categoriesarrayNoList of category strings
collection_idstring (UUID)NoCollection ID to associate with the document

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/upload/article" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "This is the content of the article...",
    "document_title": "Getting Started Guide",
    "categories": ["guide", "tutorial"],
    "collection_id": "456e7890-e89b-12d3-a456-426614174001"
  }'

Upload Website

Upload content from a website URL.

Endpoint: POST /documents/upload/website

Request Body

FieldTypeRequiredDescription
urlstringYesWebsite URL to scrape
document_titlestringYesTitle for the document
categoriesarrayNoList of category strings
collection_idstring (UUID)NoCollection ID to associate with the document

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/upload/website" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/documentation",
    "document_title": "External Documentation",
    "categories": ["external", "reference"],
    "collection_id": "456e7890-e89b-12d3-a456-426614174001"
  }'

Update Document

Update an existing document’s metadata or content.

Endpoint: PUT /documents/{documentId}

Parameters

ParameterTypeRequiredDescription
documentIdstring (UUID)YesThe ID of the document to update

Request Body

All fields are optional for updates:

FieldTypeRequiredDescription
document_titlestringNoNew title for the document
contentstringNoNew content for the document
categoriesarrayNoNew list of categories
collection_idstring (UUID)NoNew collection ID

Example Requests

curl -X PUT "https://api.aloochat.ai/api/public/documents/123e4567-e89b-12d3-a456-426614174000" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "document_title": "Updated API Documentation",
    "categories": ["tech", "documentation", "updated"]
  }'

Delete Document

Delete a document from the knowledge base.

Endpoint: DELETE /documents/{documentId}

Parameters

ParameterTypeRequiredDescription
documentIdstring (UUID)YesThe ID of the document to delete

Example Requests

curl -X DELETE "https://api.aloochat.ai/api/public/documents/123e4567-e89b-12d3-a456-426614174000" \
  -H "x-api-key: your_api_key_here"

Check Task Status

Check the status of a document processing task.

Endpoint: GET /documents/task/{taskId}

Parameters

ParameterTypeRequiredDescription
taskIdstring (UUID)YesThe ID of the task to check

Example Requests

curl -X GET "https://api.aloochat.ai/api/public/documents/task/task_123e4567-e89b-12d3-a456-426614174000" \
  -H "x-api-key: your_api_key_here"

Example Response

{
  "task_id": "task_123e4567-e89b-12d3-a456-426614174000",
  "document_id": "doc_456e7890-e89b-12d3-a456-426614174001",
  "status": "completed",
  "error": null,
  "created_at": "2024-01-15T10:30:00Z",
  "completed_at": "2024-01-15T10:32:15Z"
}

Check Document Similarity

Check similarity between documents to avoid duplicates.

Endpoint: POST /documents/check-similarity

Request Body

FieldTypeRequiredDescription
documentstringYesDocument content to check
customer_idstringYesCustomer ID for comparison
similaritynumberNoSimilarity threshold (0.0-1.0, default: 0.9)

Example Requests

curl -X POST "https://api.aloochat.ai/api/public/documents/check-similarity" \
  -H "x-api-key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "document": "This is the content to check for similarity...",
    "customer_id": "123e4567-e89b-12d3-a456-426614174000",
    "similarity": 0.85
  }'

Get Knowledge Base Stats

Get statistics about the knowledge base.

Endpoint: GET /documents/stats

Example Requests

curl -X GET "https://api.aloochat.ai/api/public/documents/stats" \
  -H "x-api-key: your_api_key_here"

Error Responses

The API uses standard HTTP status codes to indicate success or failure:

  • 200 - Success
  • 201 - Created successfully
  • 202 - Accepted (for async operations)
  • 400 - Bad request (invalid parameters)
  • 401 - Unauthorized (invalid API key)
  • 403 - Forbidden (insufficient permissions)
  • 404 - Not found
  • 500 - Internal server error

Error responses include a JSON object with error details:

{
  "detail": "Document not found"
}