# Knowledge base

## Create a Knowledge base.

1. Login to PropulsionAI
2. Goto Knowledge base.
3. Create a new Knowledge base.
4. Upload documents to Knowledge base.

{% hint style="info" %}
For large documents, wait for document processing to be completed.
{% endhint %}

## Inference

{% tabs %}
{% tab title="NodeJS (TS)" %}

```javascript
import PropulsionAI from 'propulsionai';
import {
  ModelChatResponse,
  ModelChatParams
} from 'propulsionai/resources/models';

const p8n = new PropulsionAI({
  bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'] as string,
});

async function main() {
  try {
    let deployment_tag: string = '<deployment_tag>';
    let knowledgebases: Array<string> = ["<knowledgebase_id>"]
    let params: ModelChatParams = {
      knowledgebases: knowledgebases,
      messages: [
        {
          role: 'user',
          content: "What are the key improvements in US-X2090249-B00?",
        },
      ],
      model: 'auto',
      stream: false,
      wait: true,
    };
    let response: ModelChatResponse;
    try{
      response = await p8n.models.ep(deployment_tag, params);
    }catch(e){
      console.log('Error:', e);
      return;
    }
    console.log("Task ID:", response.task_id);
    if(response.choices) {
      response.choices.forEach((choice) => {
        console.log(`${choice.message?.role}: ${choice.message?.content}`);
      });
    }
  } catch (error) {
    console.error('Error during model call:', error);
  }
}

main();

```

{% endtab %}

{% tab title="NodeJS (JS)" %}

```
import PropulsionAI from 'propulsionai';

const p8n = new PropulsionAI({
  bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'],
});

async function main() {
  try {
    let deployment_tag = '<deployment_tag>';
    let knowledgebases = ["<knowledgebase_id>"]
    let params = {
      knowledgebases: knowledgebases,
      messages: [
        {
          role: 'user',
          content: "What are the key improvements in US-X2090249-B00?",
        },
      ],
      model: 'auto',
      stream: false,
      wait: true,
    };
    let response;
    try{
      response = await p8n.models.ep(deployment_tag, params);
    }catch(e){
      console.log('Error:', e);
      return;
    }
    console.log("Task ID:", response.task_id);
    if(response.choices) {
      response.choices.forEach((choice) => {
        console.log(`${choice.message?.role}: ${choice.message?.content}`);
      });
    }
  } catch (error) {
    console.error('Error during model call:', error);
  }
}

main();

```

{% endtab %}

{% tab title="Python" %}

```python
import os
from propulsionai import AsyncPropulsionAI
from propulsionai.models import ModelChatResponse

# Initialize AsyncPropulsionAI with bearer token from environment variables
p8n = AsyncPropulsionAI(
    bearer_token=os.environ.get("PROPULSIONAI_BEARER_TOKEN"),
)

async def main() -> None:
    try:
        response: ModelChatResponse = await p8n.models.ep_auto(
            '<deployment_tag>',
            knowledgebases=[<knowledgebase_id_1>, <knowledgebase_id_2>],
            messages=[
                {
                    "role": "user",
                    "content": "Share 3 key features about under-development KB-9982 drone.",
                },
            ],
            model="auto",
            stream=False,
            wait=True,
        )
        print(response)
    except Exception as e:
        print(f"Error during model call: {e}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

```

{% endtab %}

{% tab title="cURL" %}

```bash
# Inference Call
curl -X "POST" "https://api.propulsionhq.com/api/v1/chat/<deployment_tag>?wait=true" \
     -H 'Authorization: Bearer <PROPULSIONAI_BEARER_TOKEN>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d '{
  "knowledgebases": [<knowledgebase_id_1>, <knowledgebase_id_2>],
  "messages": [
    {
      "role": "user",
      "content": "Share 3 key features about under-development KB-9982 drone."
    }
  ],
  "model": "auto",
  "stream": false
}'

```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.propulsionhq.com/developer-guide/knowledge-base.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
