Documentation Chat Bot

Documentation is a crucial part of any software product, but making it easily accessible can be challenging. This is where documentAI and conversational chatbots can help. In this post we will go over how you can integrate documentAI with your existing documentation to allow your users to converse with your docs.

Make sure to check out our integration for our documentation.

Benefits of a chat interface

A chat interface for documentation has several advantages:

  • 24/7 availability - Chatbots can provide documentation access 24/7 without human support staffing required. Users can get answers anytime.
  • Reduced support tickets - By providing an initial layer of documentation assistance, chatbots can reduce the number of support tickets needed to resolve issues. Simple queries are handled automatically.
  • Onboarding assistance - Chatbots are great for assisting users just getting started. They can provide overview information and point new users in the right direction.
  • Personalization - Conversations allow the chatbot to understand the user's specific context and needs. Responses can be tailored and examples personalized.
  • Quick feedback - Chatbots provide rapid conversational feedback. There's no need to submit a request and wait for response. Answers are immediate.
  • User analytics - Chatbot conversations provide valuable analytics on user pain points and documentation gaps based on query patterns.
  • Accessibility - Chatbots increase documentation access for those more comfortable with conversational interfaces or with disabilities.
  • Multi-language support - Chatbots can seamlessly provide documentation in the user's preferred language through machine translation. This is also true for user's questions.
  • Reduced documentation maintenance - By leveraging LLM knowledge, chatbots reduce the amount of documentation content that needs to be manually written and maintained.

Get your API key

First get your API key from the console. Authenticate requests by passing this key in the X-API-KEY header. Learn more about authentication here.

Ingest your documentation

There are 2 options to ingest the documentation, you can either crawl your existing documentation or you can upload it directly.

Crawling

The easiest way to ingest docs is via crawling. This entails programmatically visiting each page and processing its content. See documentation for details.

Crawl documentation
curl -X POST https://api.documentai.dev/v1/collections/[COLLECTION ID]/crawl \
     -H 'X-API-KEY: [YOUR API KEY]' \
     -d '{"url": "[YOUR DOCUMENTATION ROOT URL]", "maxDepth": 5, "maxDocuments": 100}'

Where:

  • COLLECTION ID - ID of the collection, reuse existing or specify new.
  • API KEY - the API key from the console.
  • DOCUMATATION ROOT URL - Root of your documentation, e.g. https://documentai.dev/docs.
  • MAX DEPTH - limits the how far the crawler will recurse. For example starting at /docs the page at /docs/foo/bar is considered to be at depth 2.
  • MAX DOCUMENTS - limits how many documents to crawl.

Crawling is asynchronous, the response will contain a crawlId, using which you can check status as per documentation.

Crawl response
{
  "collectionId": "[COLLECTION ID]",
  "crawlId": "f08594bd-4486-4918-b237-0017b1fd2d6c",
  "status": {
    "date": "2023-09-03T12:22:36.291790Z",
    "status": "CRAWLING"
  }
}

Uploading files

If your documentation is in offline files you can also upload them directly. To do this you can use the upload API, full reference here.

Upload documentation
curl -X PUT https://api.documentai.dev/v1/collections/[COLLECTION ID]/upload \
     -H 'X-API-KEY: [YOUR API KEY]' \
     --form file=doc1.pdf \
     --form file=doc2.docx

Where:

  • COLLECTION ID - ID of the collection, reuse existing or specify new.
  • API KEY - the API key from the console.

You can upload multiple files if needed in a single request. The upload is asynchronous and you can monitor the status of your upload job using check upload API. The response will contain an uploadId.

Upload response
{
  "collectionId": "[COLLECTION ID]",
  "uploadId": "6f207f16-c30b-47ef-9a58-efea9df9ae73"
}

Integrate chatbot

After the crawl is completed you can integrate with the chat API. Full reference is available here. The chat interface exposes a conversational UX for your users to ask questions about your documentation and they can also leverage LLM's knowledge to easily understand your product and how to use it.

Send Message
curl -X POST https://api.documentai.dev/v1/collections/[COLLECTION ID]/chat/[CHAT ID] \
     -H 'X-API-KEY: [YOUR API KEY}' \
     -d '{"message": [YOUR MESSAGE]}'

Where:

  • COLLECTION ID - ID of the collection, reuse existing or specify new.
  • API KEY - the API key from the console.
  • CHAT ID - the id of the chat. You decide the id of the chat and do not need to explicitly create it. All previous messages in a chat will be evaluated by the LLM.
  • MESSAGE - the message you want to send.

Chat response
{
  "sender": "ASSISTANT",
  "message": {
    "id": "553beb15-9f2b-4c97-857f-94963bbce84f",
    "date": "2023-09-03T12:24:09.026440Z",
    "content": "To upload a document using TypeScript, you can utilize the `axios` library to make HTTP requests to the documentAI API. Here's an example of how you can upload a document:\n\n```typescript\nimport axios from 'axios';\n\nasync function uploadDocument(collectionId: string, apiKey: string, filePath: string): Promise<void> {\n  try {\n    const url = `https://api.documentai.dev/v1/collections/${collectionId}/upload`;\n    const formData = new FormData();\n    formData.append('file', filePath);\n\n    const response = await axios.put(url, formData, {\n      headers: {\n        'Content-Type': 'multipart/form-data',\n        'X-API-KEY': apiKey,\n      },\n    });\n\n    const uploadId = response.data.uploadId;\n    console.log(`Document uploaded successfully. Upload ID: ${uploadId}`);\n  } catch (error) {\n    console.error('Failed to upload document:', error.response.data.error);\n  }\n}\n\n// Usage\nconst collectionId = 'mycollection';\nconst apiKey = 'your-api-key';\nconst filePath = '/path/to/your/document.pdf';\n\nuploadDocument(collectionId, apiKey, filePath);\n```\n\nMake sure to replace `'your-api-key'` with your actual API key and `'mycollection'` with the ID of the collection you want to upload the document to. Also, update `'your/document.pdf'` with the path to your actual document file.\n\nPlease note that you need to install the `axios` library if it's not already installed. You can install it by running `npm install axios` or `yarn add axios`.\n\nRemember to handle any errors that may occur during the upload process.",
    "context": [
      {
        "collectionId": "[COLECTION ID]",
        "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
        "chunkId": "348a8973-4fc6-42ba-a557-0d89ea8aef54",
        "content": "To upload a document use multipart/form-data. The maximum file size is 50MB. Documents can be uploaded in a batch.\n\nPUT/v1/collections/:collectionId/upload\n\ncurl -X PUT /v1/collections/mycollection/upload \\\n     -H 'X-API-KEY: 46n1Zwy48X95mIfbOjIFO99Dg613KjRu8iFA4bAr' \\\n     --form file=may_report.pdf \\\n     --form file=june_report.pdf\nResponse\n\n{\n\t\"collectionId\": \"mycollection\",\n\t\"uploadId\": \"6f207f16-c30b-47ef-9a58-efea9df9ae73\"\n}\nCheck Upload\n\nRetrieves the current status of an upload.\n\nGET/v1/collections/:collectionId/upload/:uploadId\n\ncurl -X GET /v1/collections/mycollection/upload/6f207f16-c30b-47ef-9a58-efea9df9ae73 \\\n     -H 'X-API-KEY: 46n1Zwy48X95mIfbOjIFO99Dg613KjRu8iFA4bAr'\nResponse",
        "metadata": {}
      },
      {
        "collectionId": "[COLECTION ID]",
        "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
        "chunkId": "bf3d056f-073b-46e2-b08b-7914fc511ba8",
        "content": "API Reference | documentAI\nIntroduction\n\nWelcome to the documentAI API! documentAI provides a retrieval augmented generation service that allows you to generate high-quality content using a combination of large language models and an information retrieval system.\n\nOur API provides easy access to documentAI's state-of-the-art AI models through a simple REST interface. You can integrate documentAI directly into your application to add powerful natural language generation capabilities.\n\nThis documentation provides complete reference material for using the documentAI API. We recommend reading the quick start guide to get up and running quickly. From there you can explore the available endpoints for generating text, managing knowledge sources, and more.\n\nAuthentication\n\nTo use the documentAI API, you'll need an API key. API keys can be created and managed from your documentAI console.",
        "metadata": {}
      },
      {
        "collectionId": "[COLECTION ID]",
        "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
        "chunkId": "858ec3d6-770f-40ac-a203-5dd219c1482d",
        "content": "\"metadata\": {\n        \"url\": \"https://documentai.dev/docs/documents\"\n      }\n    }\n  ]\n}\nGet Document",
        "metadata": {}
      }
    ]
  }
}

You can also retrive the whole conversation using get chat API.

Get Chat
curl -X GET https://api.documentai.dev/v1/collections/[COLLECTION ID]/chat/[CHAT ID] \
     -H 'X-API-KEY: [YOUR API KEY}'

Where:

  • COLLECTION ID - ID of the collection, reuse existing or specify new.
  • API KEY - the API key from the console.
  • CHAT ID - the id of the chat. You decide the id of the chat and do not need to explicitly create it. All previous messages in a chat will be evaluated by the LLM.

The response will include both your messages and assistant's messages with the relevant context so you can link back to the source.

GET Chat response
{
  "messages": [
    {
      "sender": "USER",
      "id": "d595de0e-4664-43a6-b03b-396bb05933a4",
      "date": "2023-09-03T11:24:09.026440Z",
      "content": "How can I upload a document using TypeScript?",
      "context": []
    },
    {
      "sender": "ASSISTANT",
      "message": {
        "id": "553beb15-9f2b-4c97-857f-94963bbce84f",
        "date": "2023-09-03T12:24:09.026440Z",
        "content": "To upload a document using TypeScript, you can utilize the `axios` library to make HTTP requests to the documentAI API. Here's an example of how you can upload a document:\n\n```typescript\nimport axios from 'axios';\n\nasync function uploadDocument(collectionId: string, apiKey: string, filePath: string): Promise<void> {\n  try {\n    const url = `https://api.documentai.dev/v1/collections/${collectionId}/upload`;\n    const formData = new FormData();\n    formData.append('file', filePath);\n\n    const response = await axios.put(url, formData, {\n      headers: {\n        'Content-Type': 'multipart/form-data',\n        'X-API-KEY': apiKey,\n      },\n    });\n\n    const uploadId = response.data.uploadId;\n    console.log(`Document uploaded successfully. Upload ID: ${uploadId}`);\n  } catch (error) {\n    console.error('Failed to upload document:', error.response.data.error);\n  }\n}\n\n// Usage\nconst collectionId = 'mycollection';\nconst apiKey = 'your-api-key';\nconst filePath = '/path/to/your/document.pdf';\n\nuploadDocument(collectionId, apiKey, filePath);\n```\n\nMake sure to replace `'your-api-key'` with your actual API key and `'mycollection'` with the ID of the collection you want to upload the document to. Also, update `'your/document.pdf'` with the path to your actual document file.\n\nPlease note that you need to install the `axios` library if it's not already installed. You can install it by running `npm install axios` or `yarn add axios`.\n\nRemember to handle any errors that may occur during the upload process.",
        "context": [
          {
            "collectionId": "[COLECTION ID]",
            "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
            "chunkId": "348a8973-4fc6-42ba-a557-0d89ea8aef54",
            "content": "To upload a document use multipart/form-data. The maximum file size is 50MB. Documents can be uploaded in a batch.\n\nPUT/v1/collections/:collectionId/upload\n\ncurl -X PUT /v1/collections/mycollection/upload \\\n     -H 'X-API-KEY: 46n1Zwy48X95mIfbOjIFO99Dg613KjRu8iFA4bAr' \\\n     --form file=may_report.pdf \\\n     --form file=june_report.pdf\nResponse\n\n{\n\t\"collectionId\": \"mycollection\",\n\t\"uploadId\": \"6f207f16-c30b-47ef-9a58-efea9df9ae73\"\n}\nCheck Upload\n\nRetrieves the current status of an upload.\n\nGET/v1/collections/:collectionId/upload/:uploadId\n\ncurl -X GET /v1/collections/mycollection/upload/6f207f16-c30b-47ef-9a58-efea9df9ae73 \\\n     -H 'X-API-KEY: 46n1Zwy48X95mIfbOjIFO99Dg613KjRu8iFA4bAr'\nResponse",
            "metadata": {}
          },
          {
            "collectionId": "[COLECTION ID]",
            "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
            "chunkId": "bf3d056f-073b-46e2-b08b-7914fc511ba8",
            "content": "API Reference | documentAI\nIntroduction\n\nWelcome to the documentAI API! documentAI provides a retrieval augmented generation service that allows you to generate high-quality content using a combination of large language models and an information retrieval system.\n\nOur API provides easy access to documentAI's state-of-the-art AI models through a simple REST interface. You can integrate documentAI directly into your application to add powerful natural language generation capabilities.\n\nThis documentation provides complete reference material for using the documentAI API. We recommend reading the quick start guide to get up and running quickly. From there you can explore the available endpoints for generating text, managing knowledge sources, and more.\n\nAuthentication\n\nTo use the documentAI API, you'll need an API key. API keys can be created and managed from your documentAI console.",
            "metadata": {}
          },
          {
            "collectionId": "[COLECTION ID]",
            "documentId": "b0dd63b1-f78c-4989-94f9-f73768bb12dd",
            "chunkId": "858ec3d6-770f-40ac-a203-5dd219c1482d",
            "content": "\"metadata\": {\n        \"url\": \"https://documentai.dev/docs/documents\"\n      }\n    }\n  ]\n}\nGet Document",
            "metadata": {}
          }
        ]
      }
    }
  ]
}

Summary

Hopefully this post demonstrated the benefits of using documentAI to make your documantation easier and more accessible only with a few API calls. Remember you can checkout an example running on our documentation.