Query a knowledge base for documents – IBM Developer

Join the Digital Developer Conference: AIOps & Integration to propel your AI-powered automation skills Register for free

Query a knowledge base for documents

Note: This pattern is part of a composite pattern. These are code patterns that can be stand-alone applications or might be a continuation of another code pattern. This composite pattern consists of:


The management of unstructured data is recognized as one of the major unsolved problems in the information technology industry. The tools and techniques that have proved so successful in transforming structured data into business intelligence and actionable information don’t work when it comes to unstructured data. This code pattern shows a way to query a knowledge base and obtain the wanted answer to document-specific questions.


This code pattern is a continuation of an earlier pattern, Build a knowledge graph from documents. The pattern starts with building a knowledge graph from domain-specific documents, with a requirement of finding facts. The pattern uses an existing knowledge base to query and obtain the wanted answer to document-specific questions. The code pattern uses Watson Studio, Watson NLU, and Node-RED to provide a solution for someone who wants answers to questions related to a document.



  1. The unstructured data is brought into a 3-tuple of Entity-Relationship-Entity.
  2. A knowledge graph is built out of the obtained Entities and Relationship.
  3. The user enters a question through the UI.
  4. The question asked by the user is sent to the notebook through Node-RED, which helps integrate the UI with a notebook.
  5. The question gets queried and a suitable response is returned.
  6. The user receives the answer on the UI.


Find the detailed steps for this pattern in the README. Those steps will show you how to:

  1. Sign up for Watson Studio.
  2. Create IBM Cloud services.
  3. Import the Node-RED flow.
  4. Note the WebSocket URL.
  5. Update the WebSocket URL.
  6. Update the WebSocket URL in a Notebook.
  7. Access the user interface.
  8. Set up the Notebook.