In this tutorial, you will learn how to set up an external knowledge base for Dify — a popular open source AI automation tool — using your InfraNodus graph.
All you need to do is to
- Create an InfraNodus graph from any text data (PDF, URLs, plain text, ontology, YouTube videos)
- Get the API key at https://infranodus.com/api-access
- Add an External Knowledge Base to your Dify > Knowledge and then add the external knowledge base using this InfraNodus endpoint:
https://infranodus.com/api/v1/difyand provide the name of your InfraNodus graph and the API key - Connect that external knowledge base to your favorite LLM workflow in Dify.
How GraphRAG Knowledge Works
The advantage of using this setup is that you can add any content to your knowledge base via InfraNodus and regularly update it (or turn on automatic updates). Dify will simply query your InfraNodus graph and it will automatically use the underlying GraphRAG system increasing the quality of retrieval.
You will also be able to get a quick visual overview of your knowledge base thanks to the InfraNodus online graph visualization engine that shows you the main topics and concepts as well as the content gaps in your knowledge base. This helps you see how you can optimize your knowledge base and improve observability.
Finally, your InfraNodus graph can be used with other applications, so you're not locked into one system but can also expose this graph to your favorite LLMs via the InfraNodus MCP server, our n8n integrations, or directly via our API.
Below is a schema for a simple setup that uses the custom knowledge retrieval node in a Dify workflow: a user's query is sent directly to the knowledge retrieval node (the external InfraNodus knowledge node), the results are then sent to the LLM, which uses them as context to generate an answer and send it back to the user.
When the user's request arrives to the knowledge retrieval node, InfraNodus will query the part of the graph that relates to the user's query and retrieve both the graph relations that overlap with the user's query (GraphRAG) as well as additional statements using the standard RAG search:
The related statements will be returned back to the user via the knowledge base node and can then be used as additional context to improve LLM's responses.
Note, that if a user asks something general, like "What is it for?" a standard RAG flow would not pick up anything or pick up irrelevant statements. While GraphRAG in this case will still pick up the statements that correspond to the most relevant topical clusters in text. This is the advantage you have because even if the context provided is insufficient, you will still retrieve general contextual information from the knowledge base.
Also, it's easy to add new data into the graph using the text editor or the import option that can ingest files, URLs, Google search results, and more.
Step 1: Creating a Knowledge Graph in InfraNodus
The first step is to create a knowledge graph in InfraNodus that you will query using your custom Dify knowledge base. In order to do that, go to https://infranodus.com/apps and choose the plain text editor, file import app, or any external data import app (e.g. scrapping a website or a YouTube channel).
In our case, we will use the automatic ontology creator that is available via https://infranodus.com/import/ai-ontologies — we write a prompt asking InfraNodus to create an ontology for various body metrics that can be used for longevity:
create an ontology for various body metrics that can be used for longevityOnce the graph is generated, we're going to have something like this. This graph will then be used as the source of truth for our model. Of course, this could also be a set of imported PDF documents, URLs from a website, or manually uploaded text.
You might also want to improve the graph generated by selecting the nodes or topics that are not connected yet and using the built-in AI module to generate new statements that connect them. This is a great and easy way to optimize your knowledge base:
Once your graph is complete, you can be using to for your Dify external knowledge base.
You now have a GraphRAG-powered database of statements that relate to the topic you're interested in. And you can use this knowledge to improve the responses of your LLM and to guide its thinking using the custom ontology.
Step 2: How to Add an External Knowledge Base to Dify
Now that you have an InfraNodus graph saved, adding it as a knowledge base to Dify is easy.
1. Open your local or cloud Dify instance and go to the Knowledge Tab. There you click on Connect to External Knowledge:
2. Once connected, add the name and description of your new knowledge base and then click "+ Create a new External Knowledge API":
3. There you give another name to the knowledge base as well as provide the endpoint to the InfraNodus Dify knowledge base: https://infranodus.com/api/v1/dify and also add your InfraNodus API key which you can generate at https://infranodus.com/api-access
You will be able to use this connection to connect to all your different individual knowledge graphs.
IMPORTANT: At this step, you need to verify that you have the correct External Knowledge API listed in Dify and that your graph name corresponds to the graph that you want to be using as knowledge for your account.
For some reason, Dify sometimes chooses a different knowledge API, so you need to verify that it indeed selected the correct one.
4. The last step is to specify the name of the InfraNodus graph you want to query — this is the graph we created earlier in the Step 1 above:
5. You can optionally set retrieval settings in Dify knowledge. We recommend setting Top K (the number of results returned to 10) and the Score Threshold to 0.3. The reason is that this endpoint returns not only the statements matched by GraphRAG and RAG but also the top statements for each topic in the knowledge base which helps enhance the context. These statements will have a similarity_score of 0.3, so if you want to include them, you need to set the threshold accordingly. If you don't want to include those and only want the matched statements, you can leave the default value of 0.5 intact.
6. Now go to the Dify > Knowledge then reload this page (because sometimes Dify doesn't show the knowledge directly) and test this new external knowledge you created by entering a request and seeing how well the data is retrieved from your graph.
7. Once everything is ready, you can open the Dify Studio (menu above), then > Create from Blank > AI Workflow, then you create a simple workflow that contains the custom knowledge base you just added.
To add the Knowledge Retrieval node,
- click "+" on the left,
- choose Knowledge Retrieval, then
- in the Settings > Knowledge click +
- Select the external knowledge you just added
You can then connect the knowledge base to User Input node and to the LLM node that will provide the final Answer.
In this basic setup:
- User Input node receives the input from the user via a Dify chatbox or an API / webhook
- The input gets sent to the Knowledge Retrieval, InfraNodus provides the statements based on GraphRAG / RAG and the general context
- These statements are added as context in the LLM node which produces the responses
- These responses are then sent back to the user via the Answer node (back to the chat or API / webhook).
You can get this Dify template at our GitHub repo: https://github.com/infranodus/dify-infranodus
Comments
0 comments
Please sign in to leave a comment.