Quickly Build an Internal Knowledge Assistant for Enterprises Using Dify
![avatar](/assets/blog/avatar-6a4ca40794c0fbfe07035fb70bcaba86e87751a18a223a673cd6608a33983e4d.webp)
Today, let’s explore how to quickly build an internal knowledge assistant for enterprises using Dify, which can also be directly integrated into the company’s IM, enabling an intelligent robot for internal use.
We’ll start with simple administrative regulations such as company work, leave requests, and reimbursements. Most employees struggle to remember this information, processes, and regulations, leading them to repeatedly search for records or ask relevant personnel. This not only reduces efficiency but also creates negative emotions due to excessive repetitive inquiries.
Note: This assistant setup is based on the Dify official website; we’ll discuss independent deployment later.
What is Dify
Dify is an open-source LLM application development platform. It provides capabilities ranging from agent construction to AI workflow orchestration, RAG retrieval, and model management, making it easy to build and operate generative AI native applications.
Enterprise Knowledge Base
Organizing Materials
The first step is to organize the internal materials of the enterprise into documents. The Dify knowledge base supports various document formats.
Supported formats include TXT, MARKDOWN, PDF, HTML, XLSX, XLS, DOCX, CSV, EML, MSG, PPTX, PPT, XML, EPUB, with each file not exceeding 15MB.
For Q&A type documents, it’s best to organize them in a Q&A format for better results. For example:
Q: How to submit a reimbursement?
A: Submit a reimbursement request on Feishu, filling in the amount, item, supplementary explanation, etc., and attach necessary information such as invoices.
Creating a Dify Knowledge Base
The second step is to open the Dify knowledge base page, create a knowledge base, and upload the material documents.
After uploading the files, proceed to the “Text Segmentation and Cleaning” step.
On the right side of the page, you can preview the text segmentation.
Here’s a brief introduction to the specific segmentation settings:
- Segmentation Settings:
- Automatic Segmentation and Cleaning: Automatically completes segmentation. If the document lacks unified segmentation information or if you are not familiar with the document, you can choose automatic segmentation.
-
Custom: If you are familiar with the document and have high requirements for segmentation, you can choose custom segmentation.
- Indexing Method:
-
High Quality: Completed by third-party vendor embedding models, such as OpenAI’s text embedding model, which offers higher accuracy but consumes tokens. The model can be configured in personal settings.
-
Economic: Offline vector engine, lower accuracy but does not consume tokens.
-
- Retrieval Settings: We can stick with the default settings for now; we will discuss retrieval settings in detail later, including mixed retrieval, reranking, and other concepts.
After completing the settings, save to finish document processing.
If there are document updates later, you can add files at any time.
Enterprise Assistant
With the knowledge base in place, we can now create an internal chat assistant for the enterprise.
A simple enterprise information assistant can be created using basic orchestration, requiring only a simple prompt.
Prompt Writing and Optimization
Not sure how to write a prompt? No worries! I recommend a prompt optimization tool https://promptperfect.jina.ai. You just need to write down what you want the AI to do in simple language, and using the Prompt Perfect tool, you can get an optimized prompt.
For example, I have a simple prompt as follows:
You are an internal information assistant for the enterprise.
You need to help employees quickly obtain the information they want.
Do not answer any questions related to outside the enterprise.
Here’s the optimization process from the Prompt Optimizer:
After optimization, it will also suggest improvements and additional questions. If there are further additions, just continue chatting with it to include them. Let’s look at the optimized version:
As an internal information assistant for the enterprise, your task is to help employees quickly obtain various information they need in their work. Your responses must be limited to internal enterprise issues, refusing to answer any questions related to external matters.
Please refer to the following examples:
Example Question 1: "Please help me find the latest company policy document."
Example Answer 1: "The latest company policy document can be found in the policy section of the company intranet. The specific path is: Intranet Homepage -> Policies and Regulations."
Example Question 2: "Where can I find the recruitment announcement from the HR department?"
Example Answer 2: "The recruitment announcement from the HR department is published in the 'Recruitment Information' section of the intranet. You can visit: Intranet Homepage -> HR Department -> Recruitment Information."
Example Question 3: "Where can I obtain the latest financial report of the company?"
Example Answer 3: "The latest financial report of the company is usually updated on the finance department's page. The path is: Intranet Homepage -> Finance Department -> Financial Reports."
Now, please ask for the internal information you need, and I will do my best to find it for you.
Paste the optimized prompt into the chat assistant’s prompt field.
Referencing the Knowledge Base
Next, we will introduce the knowledge base we just added. Simply go to ‘Context - Add - Select Knowledge Base - Click Add’.
Debugging and Previewing
Once the knowledge base, prompt, and other settings are ready, we can directly test the effects on the right side of the page.
By comparing the content output by the assistant with the original content of the enterprise documents, you can verify the final effect. The debugging page will show whether the assistant’s output references the knowledge base, which can also help assess the effectiveness.
Thus, a simple internal information assistant for the enterprise is configured.
Publishing and Application
Once the enterprise chat assistant is configured, we can publish this application. Dify offers three publishing methods (all provided simultaneously).
- Run: A website based on Dify that is directly accessible and usable.
- Embed Website: A segment of HTML Iframe code that can be embedded into your own website.
- Access API: You can integrate the chat robot into the enterprise internally through the Dify dialogue application API, integrating it into internal websites, IM robots, etc.
In the future, we will discuss how to conduct recall tests for the knowledge base and how to use web searches for real-time enhanced retrieval.