← All writing

Setup a local code assistant for Db2 for i, a developer guide

Setup a local assistant to help you write SQL!

As developers, we want tools that are help maximize productivity but also allow us to customize our experience for our specific use case. When it comes to AI tools such as code assistants, there are a number of options, but unfortunately many require premium subscriptions for models and LLM providers. Continue, the leading open source code assistant, offers a much more flexible code assistant solution. It seamlessly integrates with top LLM providers like OpenAI, Anthropic, and Gemini, while also supporting local hosting options such as Ollama and Llama.cpp, giving developers the freedom to choose the setup that best suits their workflow.

In this blog, we will go over how to setup a local code assistant specifically tailored for Db2 for i and SQL. Here are some of the main advantages of local code assistants:

  1. Data privacy: your code stays on your machine, not sent to 3rd-party servers
  2. Customization: choose which models to use for specific coding tasks
  3. Configuration control: choose exactly how you want the model to behave by configuring model parameters
  4. Offline usage: work offline or without an internet connection
  5. No subscription costs: experiment and use powerful open-source models without committing to premium subscriptions

Requirements

Step 1: install Ollama

Ollama allows you to run LLMs locally on your laptop. Here is how to set it up:

MacOS/Linux

curl -fsSL https://ollama.ai/install.sh | sh

Windows

Download installer from Ollama

Step 2: Pull model for SQL

Next, we need to pull a model to help us write SQL. Most modern models are fairly good at SQL. I find that the Granite family of models works well for small use cases:

ollama pull granite3.2:8b

This will download the model to your machine. To verify it works, test it out with this simple command:

ollama run granite3.2:8b "write a python function to convert a string to base64"

Other models that work well with SQL (from personal experience):

Step 3: Set up your Continue account

Before we setup the Db2 for i Assistant, first create your Continue Account

  • Visit: Sign up
  • Verify email address
  • Log in to access Continue Hub

What is Continue Hub?

Continue Hub is a platform for building and sharing open source developer tools like code assistants, models, prompts and MCP tools. Read more about the launch of Continue 1.0:

Step 4: Log into Continue in VS Code

Before we open up the assistant in VSCode, first install the Continue Extension

Once installed, log in with your Continue account created in step 3.

Step 5: Add the Db2 for i Assistant

Once your Continue account is setup, you can add the Db2 for i assistant

  1. From Continue Hub Explore page, search for “Db2 for i Assistant”, or follow this link:

The Db2 for i Assistant page on Continue Hub, listing its models (qwen2.5-coder 1.5b, Granite 3.2 and Ollama), rules, prompts and context

  1. Select “Add Assistant”

The Star, Remix and Add Assistant buttons on the Continue Hub assistant page

  1. Once added, the assistant will appear in your collection of custom assistants

Continue Hub after the assistant is added: the button reads Assistant Added and a side panel shows the Db2 for i Assistant with its models

  1. Select “Open VS Code” to add the assistant to your Continue extension

An arrow points to the Open VS Code button at the bottom of the Continue Hub side panel

Here is a quick demo:

Step 6: Connect to an IBM i system and invoke @Db2i context provider

Once we have the assistant added, now all we need to do is connect to an IBM i system and start asking questions!

  1. Install the Code for IBM i extensions:
    1. Code for i
    2. Db2 for i
  2. Connect to an IBM i system using the Code for i extension
    1. Quick Start
  3. Switch to Continue, and type @Db2i
  4. You can now ask questions about objects in your library list!

Quick Demo:

To reproduce this demo:

  • first install the SAMPLE schema
CALL QSYS.CREATE_SQL_SAMPLE('SAMPLE')
  • Add SAMPLE to your library list in the active SQL job:

The Db2 for i SQL Job Manager in VS Code, editing a job’s options with SAMPLE, QGPL and QTEMP in the library list

  • save the edited Job, then ask the following query:
 @Db2i how many employees are in each department?