# Assistant Knowledge Resource

Manage Knowledge sources connected to an Assistant

## Knowledge Properties

<OperationTable type="properties" data={{"type":"object","required":["id","name","type","date_created","date_updated"],"refName":"assistants.v1.service.knowledge","modelName":"assistants_v1_service_knowledge","properties":{"description":{"description":"The type of knowledge source.","type":"string"},"id":{"type":"string","pattern":"^aia_know_.+$","description":"The description of knowledge."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","description":"The SID of the [Account](/docs/iam/api/account) that created the Knowledge resource."},"knowledge_source_details":{"description":"The details of the knowledge source based on the type.","type":"object"},"name":{"description":"The name of the knowledge source.","type":"string"},"status":{"description":"The status of processing the knowledge source ('QUEUED', 'PROCESSING', 'COMPLETED', 'FAILED')","type":"string"},"type":{"description":"The type of knowledge source ('Web', 'Database', 'Text', 'File')","type":"string"},"url":{"type":"string","description":"The url of the knowledge resource."},"embedding_model":{"description":"The embedding model to be used for the knowledge source.","type":"string"},"date_created":{"description":"The date and time in GMT when the Knowledge was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"},"date_updated":{"description":"The date and time in GMT when the Knowledge was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"}}}} />

## List all Knowledge sources connected to an Assistant

`GET https://assistants.twilio.com/v1/Assistants/{assistantId}/Knowledge`

### Path parameters

```json
[{"in":"path","name":"assistantId","description":"The assistant ID.","required":true,"schema":{"type":"string"}}]
```

### Query parameters

```json
[{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"name":"PageSize","in":"query","description":"How many resources to return in each list page. The default is 50, and the maximum is 1000.","schema":{"type":"integer","minimum":1,"maximum":1000}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}]
```

List Knowledge sources connected to an Assistant

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function listKnowledgeByAssistant() {
  const assistantsKnowledges = await client.assistants.v1
    .assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    .assistantsKnowledge.list({ limit: 20 });

  assistantsKnowledges.forEach((a) => console.log(a.description));
}

listKnowledgeByAssistant();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

assistants_knowledges = client.assistants.v1.assistants(
    "aia_asst_00000000-1111-2222-3333-444444444444"
).assistants_knowledge.list(limit=20)

for record in assistants_knowledges:
    print(record.description)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Assistants.V1.Assistant;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var assistantsKnowledges = await AssistantsKnowledgeResource.ReadAsync(
            pathAssistantId: "aia_asst_00000000-1111-2222-3333-444444444444", limit: 20);

        foreach (var record in assistantsKnowledges) {
            Console.WriteLine(record.Description);
        }
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.assistant.AssistantsKnowledge;
import com.twilio.base.ResourceSet;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        ResourceSet<AssistantsKnowledge> assistantsKnowledges =
            AssistantsKnowledge.reader("aia_asst_00000000-1111-2222-3333-444444444444").limit(20).read();

        for (AssistantsKnowledge record : assistantsKnowledges) {
            System.out.println(record.getDescription());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	assistants "github.com/twilio/twilio-go/rest/assistants/v1"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &assistants.ListKnowledgeByAssistantParams{}
	params.SetLimit(20)

	resp, err := client.AssistantsV1.ListKnowledgeByAssistant("aia_asst_00000000-1111-2222-3333-444444444444",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			fmt.Println(resp[record].Description)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$assistantsKnowledges = $twilio->assistants->v1
    ->assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    ->assistantsKnowledge->read(20);

foreach ($assistantsKnowledges as $record) {
    print $record->description;
}
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

assistants_knowledges = @client
                        .assistants
                        .v1
                        .assistants('aia_asst_00000000-1111-2222-3333-444444444444')
                        .assistants_knowledge
                        .list(limit: 20)

assistants_knowledges.each do |record|
   puts record.description
end
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:assistants:v1:assistants:knowledge:list \
   --assistant-id aia_asst_00000000-1111-2222-3333-444444444444
```

```bash
curl -X GET "https://assistants.twilio.com/v1/Assistants/aia_asst_00000000-1111-2222-3333-444444444444/Knowledge?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "knowledge": [
    {
      "description": "description",
      "id": "aia_know_#",
      "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "knowledge_source_details": {},
      "name": "name",
      "status": "status",
      "type": "type",
      "url": "https://www.example.com",
      "embedding_model": "embedding_model",
      "date_created": "2009-07-06T20:30:00Z",
      "date_updated": "2009-07-06T20:30:00Z"
    }
  ],
  "meta": {
    "first_page_url": "https://www.example.com",
    "key": "key",
    "next_page_url": "https://www.example.com",
    "page": 42,
    "page_size": 42,
    "previous_page_url": "https://www.example.com",
    "url": "https://www.example.com"
  }
}
```

## Connect a Knowledge source to an Assistant

`POST https://assistants.twilio.com/v1/Assistants/{assistantId}/Knowledge/{id}`

After you've [**created a Knowledge source**](/docs/alpha/ai-assistants/api/knowledge#create-new-knowledge-sources) using the `/v1/Knowledge` endpoint, you must connect it to an Assistant to allow that Assistant to use the Knowledge.

### Path parameters

```json
[{"in":"path","name":"assistantId","description":"The assistant ID.","required":true,"schema":{"type":"string"}},{"in":"path","name":"id","description":"The knowledge ID.","required":true,"schema":{"type":"string"}}]
```

Connect a Knowledge source to an Assistant

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function createAssistantKnowledgeAttachment() {
  await client.assistants.v1
    .assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    .assistantsKnowledge("aia_knowledge")
    .create();
}

createAssistantKnowledgeAttachment();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

client.assistants.v1.assistants(
    "aia_asst_00000000-1111-2222-3333-444444444444"
).assistants_knowledge("aia_knowledge").create()
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Assistants.V1.Assistant;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        await AssistantsKnowledgeResource.CreateAsync(
            pathAssistantId: "aia_asst_00000000-1111-2222-3333-444444444444",
            pathId: "aia_knowledge");
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.assistant.AssistantsKnowledge;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        AssistantsKnowledge.creator("aia_asst_00000000-1111-2222-3333-444444444444", "aia_knowledge").create();
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	err := client.AssistantsV1.CreateAssistantKnowledgeAttachment("aia_asst_00000000-1111-2222-3333-444444444444",
		"aia_knowledge")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$twilio->assistants->v1
    ->assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    ->assistantsKnowledge("aia_knowledge")
    ->create();
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

@client
  .assistants
  .v1
  .assistants('aia_asst_00000000-1111-2222-3333-444444444444')
  .assistants_knowledge('aia_knowledge')
  .create
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:assistants:v1:assistants:knowledge:update \
   --assistant-id aia_asst_00000000-1111-2222-3333-444444444444 \
   --id aia_knowledge
```

```bash
curl -X POST "https://assistants.twilio.com/v1/Assistants/aia_asst_00000000-1111-2222-3333-444444444444/Knowledge/aia_knowledge" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

## Detach a Knowledge source from an Assistant

`DELETE https://assistants.twilio.com/v1/Assistants/{assistantId}/Knowledge/{id}`

This endpoint removes a Knowledge source from your Assistant's configuration, so it can no longer be used by that Assistant.

### Path parameters

```json
[{"in":"path","name":"assistantId","description":"The assistant ID.","required":true,"schema":{"type":"string"}},{"in":"path","name":"id","description":"The knowledge ID.","required":true,"schema":{"type":"string"}}]
```

Detach a Knowledge source from an Assistant

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function deleteAssistantKnowledgeAttachment() {
  await client.assistants.v1
    .assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    .assistantsKnowledge("aia_knowledge")
    .remove();
}

deleteAssistantKnowledgeAttachment();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

client.assistants.v1.assistants(
    "aia_asst_00000000-1111-2222-3333-444444444444"
).assistants_knowledge("aia_knowledge").delete()
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Assistants.V1.Assistant;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        await AssistantsKnowledgeResource.DeleteAsync(
            pathAssistantId: "aia_asst_00000000-1111-2222-3333-444444444444",
            pathId: "aia_knowledge");
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.assistant.AssistantsKnowledge;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        AssistantsKnowledge.deleter("aia_asst_00000000-1111-2222-3333-444444444444", "aia_knowledge").delete();
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	err := client.AssistantsV1.DeleteAssistantKnowledgeAttachment("aia_asst_00000000-1111-2222-3333-444444444444",
		"aia_knowledge")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$twilio->assistants->v1
    ->assistants("aia_asst_00000000-1111-2222-3333-444444444444")
    ->assistantsKnowledge("aia_knowledge")
    ->delete();
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

@client
  .assistants
  .v1
  .assistants('aia_asst_00000000-1111-2222-3333-444444444444')
  .assistants_knowledge('aia_knowledge')
  .delete
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:assistants:v1:assistants:knowledge:remove \
   --assistant-id aia_asst_00000000-1111-2222-3333-444444444444 \
   --id aia_knowledge
```

```bash
curl -X DELETE "https://assistants.twilio.com/v1/Assistants/aia_asst_00000000-1111-2222-3333-444444444444/Knowledge/aia_knowledge" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```
