If you want to know if a class about a topic already exists asking a simple natural language question, it is possible now. Download and run the application https://openexchange.intersystems.com/package/langchain-iris-tool to know all about your project classes in a Chat.
Installation:
$ git clone https://github.com/yurimarx/langchain-iris-tool.git
$ docker-compose build
$ docker-compose up -d
Using:
1. Open the URL http://localhost:8501
2. Check out the Settings button used to the Agent connect the InterSystems IRIS
3. Ask about your developed classes (e.g.: Are there classes that inherit from Persistent?)
Solutions used:
- Ollama - private LLM and NLP Chat tool
- Lanchain - plataform to build AI agents
- Streamlit - Frontend framework
- InterSystems IRIS as a server to answer the questions about it
About Ollama
It is a free and on-premises LLM solution to be able running Generative AI with privacy and security because your data will be processed on-premises only. The project Ollama supports many models including mistral, Open AI models, Deepseek models and others running on-premises. This package used Ollama via docker compose with the model mistral:
ollama:
image: ollama/ollama:latest
deploy:
resources:
reservations:
devices:
- driver: nvidia
capabilities: ["gpu"]
count: all # Adjust count for the number of GPUs you want to use
ports:
- 11434:11434
volumes:
- ./model_files:/model_files
- .:/code
- ./ollama:/root/.ollama
container_name: ollama_iris
pull_policy: always
tty: true
entrypoint: ["/bin/sh", "/model_files/run_ollama.sh"] # Loading the finetuned Mistral with the GGUF file
restart: always
environment:
- OLLAMA_KEEP_ALIVE=24h
- OLLAMA_HOST=0.0.0.0
About Langchain:
Langchain it is a framework to build GenAI applications easily. The Langchain has the concept of tool. Tools are plug-ins (RAG applications) used by Langchain to complement the work of the LLMs. This application implemented a langchain tool to ask management and development questions for your IRIS server:
from langchain.llms import Ollama
from langchain.chains import RetrievalQA
from langchain.document_loaders import CSVLoader
from langchain.embeddings import OllamaEmbeddings
from langchain_iris import IRISVector
def get_insights(question, csv_file, iris_conn, collection_name):
# Load and process the CSV data
loader = CSVLoader(csv_file)
documents = loader.load()
llm = Ollama(
base_url="http://ollama:11434",
model="mistral",
temperature=0,
)
# Create embeddings
embeddings = OllamaEmbeddings(model="mistral", base_url="http://ollama:11434", temperature=0)
db = IRISVector.from_documents(
embedding=embeddings,
documents=documents,
connection_string=iris_conn,
collection_name=collection_name,
pre_delete_collection=True
)
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=db.as_retriever())
return qa({"query": question})
About Streamlit:
The streamlit solution it is used to develop frontends using python language. This application has a streamlit chat application to interact with the Ollama, Langchain and IRIS and get relevant responses:
import pandas as pd
import streamlit as st
from sqlalchemy import create_engine
import langchain_helper as lch
username = "_system"
password = "SYS"
hostname = "iris"
port = 51972
webport = 52773
namespace = "USER"
st.set_page_config(page_title="InterSystems IRIS Classes Demo", page_icon="📜")
st.title("Langchain IRIS Classes Chat")
with st.popover("Settings"):
with st.spinner(text="Connecting to the IRIS classes"):
engine = create_engine("iris://" + username + ":" + password + "@" + hostname + ":" + str(port) + "/" + namespace)
connection = engine.connect()
query = 'select * from %Dictionary.ClassDefinition where substring(ID,1,1) <> \'%\' and Copyright is null'
df = pd.read_sql(query, con=connection)
df.to_csv("classes.csv")
username = st.text_input("Username:", username)
password = st.text_input("Password:", password)
hostname = st.text_input("Hostname:", hostname)
port = int(st.text_input("Port:", port))
webport = int(st.text_input("Web port:", webport))
namespace = st.text_input("Namespace:", namespace)
# User query input
query = st.text_input(label="Enter your query")
# Submit button
if st.button(label="Ask IRIS Classes", type="primary"):
with st.spinner(text="Generating response"):
iris_conn_str = f"iris://{username}:{password}@{hostname}:{port}/{namespace}"
response = lch.get_insights(query, "classes.csv", iris_conn=iris_conn_str, collection_name="classes")
st.write(response['result'])