> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myweave.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Knowledge Management

> Upload, search, and manage persona knowledge base files

## Overview

Manage a knowledge base for personas. Upload real human expertise, documents, and content to train personas with authentic knowledge for enhanced conversations.

## Upload Files

Upload documents containing real human expertise to a persona's knowledge base.

### Request

<ParamField query="coachId" type="string" required>
  Persona identifier
</ParamField>

<ParamField body="files" type="file[]" required>
  Files to upload to knowledge base. Supports:

  * **Documents**: PDF, DOCX, TXT, MD
  * **Images**: JPG, PNG, GIF, WEBP
  * **Videos**: MP4, AVI, MOV, WEBM
</ParamField>

### Response

<ResponseField name="uploadedFiles" type="array">
  Successfully uploaded files with metadata
</ResponseField>

<ResponseField name="failedFiles" type="array">
  Files that failed to upload with error details
</ResponseField>

<ResponseField name="totalUploaded" type="number">
  Count of successfully uploaded files
</ResponseField>

<ResponseField name="totalFailed" type="number">
  Count of failed uploads
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.myweave.ai/functions/v1/knowledge-handler?coachId=coach_xyz789" \
    -H "X-API-Key: your-api-key-here" \
    -F "files=@leadership_guide.pdf" \
    -F "files=@strategy_document.docx"
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append('files', file1);
  formData.append('files', file2);

  const response = await fetch(
    'https://api.myweave.ai/functions/v1/knowledge-handler?coachId=coach_xyz789',
    {
      method: 'POST',
      headers: {
        'X-API-Key': 'your-api-key-here'
      },
      body: formData
    }
  );

  const result = await response.json();
  console.log('Upload result:', result);
  ```

  ```python Python theme={null}
  import requests

  files = [
      ('files', ('leadership_guide.pdf', open('leadership_guide.pdf', 'rb'), 'application/pdf')),
      ('files', ('strategy_doc.docx', open('strategy_doc.docx', 'rb'), 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'))
  ]

  url = "https://api.myweave.ai/functions/v1/knowledge-handler"
  params = {
      "coachId": "coach_xyz789"
  }
  headers = {"X-API-Key": "your-api-key-here"}

  response = requests.post(url, params=params, headers=headers, files=files)
  print(response.json())
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "uploadedFiles": [
      {
        "fileId": "file_abc123",
        "filename": "leadership_guide.pdf",
        "size": 1048576,
        "contentType": "application/pdf",
        "uploadedAt": "2024-01-15T10:30:00Z",
        "category": "documents"
      }
    ],
    "failedFiles": [],
    "totalUploaded": 1,
    "totalFailed": 0
  }
  ```
</ResponseExample>

***

## Search Files

<api>GET [https://api.myweave.ai/functions/v1/knowledge-handler](https://api.myweave.ai/functions/v1/knowledge-handler)</api>

Retrieve files from the knowledge base with optional search and filtering.

### Query Parameters

<ParamField query="coachId" type="string" required>
  Persona identifier
</ParamField>

<ParamField query="search" type="string">
  Search term for file content and names
</ParamField>

<ParamField query="category" type="string">
  Filter by category: `documents`, `images`, or `videos`
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number for pagination (min: 1)
</ParamField>

<ParamField query="limit" type="integer" default="20">
  Files per page (min: 1, max: 100)
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.myweave.ai/functions/v1/knowledge-handler?coachId=coach_xyz789&search=leadership&category=documents&limit=20" \
    -H "X-API-Key: your-api-key-here"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.myweave.ai/functions/v1/knowledge-handler?coachId=coach_xyz789&search=leadership&category=documents&limit=20',
    {
      method: 'GET',
      headers: {
        'X-API-Key': 'your-api-key-here'
      }
    }
  );

  const searchResults = await response.json();
  console.log(searchResults);
  ```
</RequestExample>

***

## Delete File

<api>DELETE [https://api.myweave.ai/functions/v1/knowledge-handler/:fileId](https://api.myweave.ai/functions/v1/knowledge-handler/:fileId)</api>

Remove a file from the knowledge base.

### Path Parameters

<ParamField path="fileId" type="string" required>
  Unique file identifier
</ParamField>

### Query Parameters

<ParamField query="coachId" type="string" required>
  Persona identifier
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.myweave.ai/functions/v1/knowledge-handler/file_abc123?coachId=coach_xyz789" \
    -H "X-API-Key: your-api-key-here"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.myweave.ai/functions/v1/knowledge-handler/file_abc123?coachId=coach_xyz789',
    {
      method: 'DELETE',
      headers: {
        'X-API-Key': 'your-api-key-here'
      }
    }
  );

  const result = await response.json();
  console.log(result);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Success theme={null}
  {
    "message": "File deleted successfully",
    "fileId": "file_abc123"
  }
  ```
</ResponseExample>
