Home

Cognos AI Assistant

I built a chat assistant that sits inside Cognos reports and answers questions about the data on screen.

IBM CognosJupyter NotebookOpenAI SDKPlotly

The idea

In September 2023, I was working with the AImpacts team on possible uses for language models. Since we regularly built IBM Cognos reports, I wanted to put a chat assistant directly inside one. The idea was for it to answer questions about the report and the data currently on screen.

IBM had announced a similar feature for Cognos Dashboards, but not for Cognos Reports, which our customers used more often. So I tried building the Reports version myself.

Two incomplete options

Cognos supports Custom Components, which are JavaScript interfaces embedded inside a report. A Custom Component could provide the chat window, but it could not directly query report data or call an external service such as OpenAI.

Cognos also supports Jupyter Notebooks. Through an IBM SDK, a notebook could access Cognos data, run Python code, and call OpenAI. Its interface was not suitable for a chat inside a report.

Neither option could do the whole job. I needed the interface of a Custom Component and the access available inside a notebook.

Connecting them

I embedded a Jupyter Notebook as a second component in the report and reduced it to 1 × 1 pixel. It remained active, but users only saw the chat interface.

The awkward part was getting the two components to talk to each other. Cognos provided no direct connection between them, so the Custom Component located the notebook’s iframe and kept references to prepared cells and the execution button. It could then write values into those cells, start the code, and read the result through the iframe DOM.

From prompt to answer

When a user sent a message, the Custom Component wrote the prompt into a prepared notebook cell and triggered its execution. The notebook sent the request and relevant Cognos data to OpenAI, then wrote the answer back. The Custom Component read that result and displayed it in the chat. The same path could return an interactive Plotly chart instead of text.

The assistant started with a dataset configured in the report. If it needed more information, the notebook could request and load another dataset while the report was running.

State and recovery

The component used a separate notebook cell to store the conversation state. Because Cognos persisted that cell’s contents, the component could restore an earlier session and keep several chats separate.

If the notebook still had not returned a result after 30 seconds, the Custom Component stopped waiting and showed an error, leaving both components ready for another attempt.

The presentation

After 15 working days, I presented the prototype at a Cognos User Group event on 11 October 2023. Attendees asked questions about report data and saw the answers and generated charts inside Cognos.