This project is a small end‑to‑end Retrieval-Augmented Generation (RAG) pipeline focused on InterSystems Business Services documentation.
It:
- Chunks and embeds documentation using OpenAI embeddings (
embed.py). - Uploads embeddings to InterSystems IRIS as a vector table (
upload_embeddings.py). - Searches the vector table for relevant chunks (
search.py). - Provides an interactive chat that uses OpenAI’s Responses API and your vector search as a tool (
business_service_chat.py).
- Source docs:
.txt/.mdfiles inDocumentation/BusinessService. - Chunking & embedding (
embed.py):- Split docs into overlapping chunks (paragraph/sentence-aware).
- Save chunks to
BusinessService.parquet. - Generate embeddings with
text-embedding-3-small. - Save embedded chunks to
BusinessService_embedded.parquet.
- Vector DB (InterSystems IRIS) (
upload_embeddings.py):- Create a vector table (
AIDemo.Embeddings). - Upload
chunk_text+embeddingasVECTOR(FLOAT, 1536).
- Create a vector table (
- Search API (
search.py):- Given a query, generate its embedding.
- Run a similarity search using
VECTOR_DOT_PRODUCTandTO_VECTOR. - Return top‑k matching chunks.
- RAG Chat (
business_service_chat.py):- CLI chat using OpenAI Responses API.
- Exposes
search_embeddingsas a tool (search_business_docs). - Model decides when to call the search tool to answer business-service questions.
Assuming a flat structure:
embed.pyupload_embeddings.pysearch.pybusiness_service_chat.pyDocumentation/BusinessService/
(your.txt/.mddocs go here)venv/dev.env
(your environment variables – notablyOPENAI_API_KEY)
- Python: 3.10+ recommended
- Install the following (adjust as needed):
pip install \
openai \
python-dotenv \
pandas \
pyarrow \
tiktoken \
langchain-text-splitters \
numpy \
irisNote:
pyarrow(orfastparquet) is needed for Parquet support;pandaswill use one if available.
- You need an OpenAI API key with access to:
text-embedding-3-smallgpt-5-nano(or your preferred Responses-capable model)
Set it either as a regular environment variable:
export OPENAI_API_KEY="sk-..."or in .env (see below).
You need an IRIS instance with:
- A namespace (in code:
VECTOR) - The ability to:
- Create tables
- Use
VECTORcolumn types - Use
VECTOR_DOT_PRODUCTandTO_VECTORfunctions
The defaults in code:
IRIS_HOST = "localhost"IRIS_PORT = 8881IRIS_NAMESPACE = "VECTOR"IRIS_USERNAME = "superuser"IRIS_PASSWORD = "sys"TABLE_NAME = "AIDemo.Embeddings"EMBEDDING_DIMENSIONS = 1536(matchestext-embedding-3-small)
Adjust these in the scripts if needed.
The scripts assume a .env file at:
venv/dev.env
At a minimum, put your OpenAI key there:
OPENAI_API_KEY=sk-...
# Optional: override default chat model
# OPENAI_RESPONSES_MODEL=gpt-5-nanoBoth embed.py and search.py load it via:
from dotenv import load_dotenv
load_dotenv(dotenv_path="venv/dev.env")If you prefer not to use .env, just export OPENAI_API_KEY directly in your shell.
Place your Business Service documentation as .txt or .md files in:
Documentation/BusinessService/
├── intro.md
├── settings.md
├── examples.txt
└── ...