Skip to content

RAG with ollama support#104

Open
lordbeerus0505 wants to merge 1 commit intoNirDiamant:mainfrom
lordbeerus0505:rag-ollama
Open

RAG with ollama support#104
lordbeerus0505 wants to merge 1 commit intoNirDiamant:mainfrom
lordbeerus0505:rag-ollama

Conversation

@lordbeerus0505
Copy link
Copy Markdown
Contributor

@lordbeerus0505 lordbeerus0505 commented Jun 1, 2025

I assume multiple readers of this repository such as myself do not have access to OpenAI, Groq or Anthropic's API keys and don't want to spend money on them. Further, many organizations, such as the one I work in, would prefer our models do not share our proprietary data to OpenAI. A local model would come in clutch in such scenarios.

Has been tested on my macos 15 (M1 Macbook Air) laptop.

Summary by CodeRabbit

  • New Features

    • Added local model execution capability, enabling users to work with an alternative workflow that operates entirely without API keys or external service dependencies.
  • Documentation

    • Added instructional content and tutorial references to guide users through setup and usage of the new local workflow alternative.

@NirDiamant
Copy link
Copy Markdown
Owner

I'll approve this one in about two weeks. I created a new tutorial of Ollama which I want to refer to

@NirDiamant
Copy link
Copy Markdown
Owner

can you please refer to https://github.com/NirDiamant/agents-towards-production/blob/main/tutorials/on-prem-llm-ollama/ollama_tutorial.ipynb in this tutorial?

@lordbeerus0505
Copy link
Copy Markdown
Contributor Author

Apologies for the delay. Done ✅

@NirDiamant
Copy link
Copy Markdown
Owner

Several things:

  • Please combine everything into one file by adding the Ollama option to the current CSV tutorial.
  • Refer only to the link I’ve attached, and avoid linking to other Medium posts.
  • Remove any unnecessary cell outputs.

@NirDiamant
Copy link
Copy Markdown
Owner

@lordbeerus0505 will you make the changes?

@lordbeerus0505 lordbeerus0505 force-pushed the rag-ollama branch 2 times, most recently from 2a6076e to 4c38bc1 Compare August 8, 2025 18:57
@NirDiamant
Copy link
Copy Markdown
Owner

hey @lordbeerus0505 did you make the changes? Sorry for the super late response :)

@lordbeerus0505
Copy link
Copy Markdown
Contributor Author

Hey, yes the changes were made.

Copy link
Copy Markdown
Owner

@NirDiamant NirDiamant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ollama support has been requested multiple times (#113). Thanks for working on this.

This PR has been open for a while - is it still up to date with the current main branch? If there are merge conflicts, a rebase would help move this forward.

… access to

OpenAI keys, to try out RAGs locally for free.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

The notebook adds an alternative local workflow for CSV-based Retrieval Augmented Generation using Ollama instead of OpenAI. Documentation and code cells demonstrate ChatOllama LLM instantiation and OllamaEmbeddings for vector store creation alongside existing OpenAI implementations.

Changes

Cohort / File(s) Summary
Ollama Alternative Workflow
all_rag_techniques/simple_csv_rag.ipynb
Added instructional text and code cells demonstrating local Ollama-based RAG pipeline: ChatOllama(model="llama3.2") for LLM and OllamaEmbeddings(model="mxbai-embed-large") for FAISS vector store, with link to Ollama tutorial.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 No API keys? No worries, my friends!
Ollama whispers where OpenAI ends,
Local embeddings dance, FAISS takes the lead,
RAG workflows bloom from every seed! 🌱✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'RAG with ollama support' clearly and concisely summarizes the main change: adding Ollama as an alternative local LLM option to the RAG example notebook.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Ruff (0.15.9)
all_rag_techniques/simple_csv_rag.ipynb

Unexpected end of JSON input


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lordbeerus0505
Copy link
Copy Markdown
Contributor Author

Done 👍

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@all_rag_techniques/simple_csv_rag.ipynb`:
- Around line 122-124: The notebook imports langchain_ollama (symbols:
langchain_ollama, ChatOllama, OllamaEmbeddings) but the install step omits that
package; update the environment setup/install cell to add the langchain-ollama
package so fresh runs don't raise ImportError before using Ollama models, then
re-run the install cell and confirm imports succeed.
- Around line 117-125: The notebook currently reassigns llm and vector_store in
multiple cells (e.g., ChatOpenAI then ChatOllama, FAISS with OpenAIEmbeddings
then overwritten by OllamaEmbeddings), causing silent provider overrides;
consolidate provider selection by reading a single switch (e.g., an ENV var like
PROVIDER) and use it to conditionally initialize only one stack: instantiate llm
as either ChatOpenAI or ChatOllama and vector_store as FAISS with matching
embeddings (OpenAIEmbeddings or OllamaEmbeddings) in one place (look for symbols
llm, vector_store, ChatOpenAI, ChatOllama, FAISS, OpenAIEmbeddings,
OllamaEmbeddings) so running all cells does not overwrite the chosen provider.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1150d269-037e-400a-9604-95291c118ad2

📥 Commits

Reviewing files that changed from the base of the PR and between d889bee and 4186540.

📒 Files selected for processing (1)
  • all_rag_techniques/simple_csv_rag.ipynb

Comment on lines +117 to +125
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.document_loaders.csv_loader import CSVLoader\n",
"from langchain_ollama import ChatOllama, OllamaEmbeddings\n",
"llm = ChatOllama(model=\"llama3.2\")"
]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify unconditional provider overwrites in notebook cell order.
python - <<'PY'
import json
p="all_rag_techniques/simple_csv_rag.ipynb"
nb=json.load(open(p))
for i,c in enumerate(nb["cells"]):
    src="".join(c.get("source", []))
    if "llm = ChatOpenAI" in src or "llm = ChatOllama" in src or "vector_store = FAISS(" in src:
        print(f"cell[{i}] ->")
        for line in src.splitlines():
            if "llm = " in line or "vector_store = FAISS(" in line:
                print("   ", line)
PY

Repository: NirDiamant/RAG_Techniques

Length of output: 254


🏁 Script executed:

#!/bin/bash
# Extract cell boundaries and line numbers from the notebook
python - <<'PY'
import json
p="all_rag_techniques/simple_csv_rag.ipynb"
nb=json.load(open(p))

line_num = 1
for i, c in enumerate(nb["cells"]):
    cell_start = line_num
    src = "".join(c.get("source", []))
    cell_lines = len(src.splitlines())
    cell_end = line_num + cell_lines - 1
    
    # Check for llm or vector_store assignments
    has_llm_assign = "llm = ChatOpenAI" in src or "llm = ChatOllama" in src
    has_vs_assign = "vector_store = FAISS(" in src
    
    if has_llm_assign or has_vs_assign:
        print(f"cell[{i}]: lines {cell_start}-{cell_end} ({cell_lines} lines)")
        if has_llm_assign:
            for line_idx, line in enumerate(src.splitlines(), start=cell_start):
                if "llm = " in line:
                    print(f"  Line {line_idx}: {line.strip()}")
        if has_vs_assign:
            for line_idx, line in enumerate(src.splitlines(), start=cell_start):
                if "vector_store = FAISS(" in line:
                    print(f"  Line {line_idx}: {line.strip()}")
    
    line_num += cell_lines + 1  # Account for JSON structure

print("\n--- Checking line ranges mentioned in review ---")
# Check line 117-125 range
line_num = 1
for i, c in enumerate(nb["cells"]):
    src = "".join(c.get("source", []))
    cell_lines = len(src.splitlines())
    line_start = line_num
    line_end = line_num + cell_lines - 1
    if (line_start <= 125 and line_end >= 117):
        print(f"Lines 117-125 span cell[{i}] (lines {line_start}-{line_end})")
        print(src[:300])
    line_num += cell_lines + 1

# Check line range 376-385
line_num = 1
for i, c in enumerate(nb["cells"]):
    src = "".join(c.get("source", []))
    cell_lines = len(src.splitlines())
    line_start = line_num
    line_end = line_num + cell_lines - 1
    if (line_start <= 385 and line_end >= 376):
        print(f"Lines 376-385 span cell[{i}] (lines {line_start}-{line_end})")
        print(src[:500])
    line_num += cell_lines + 1
PY

Repository: NirDiamant/RAG_Techniques

Length of output: 766


🏁 Script executed:

#!/bin/bash
# Get complete notebook structure and line counts
python - <<'PY'
import json
p="all_rag_techniques/simple_csv_rag.ipynb"
nb=json.load(open(p))

# Calculate total lines in notebook
total_lines = 1
for i, c in enumerate(nb["cells"]):
    src = "".join(c.get("source", []))
    lines = len(src.splitlines())
    total_lines += lines + 1

print(f"Total notebook lines: ~{total_lines}")
print(f"Total cells: {len(nb['cells'])}\n")

# Print all cells with llm/vector_store assignments and their full content
line_num = 1
for i, c in enumerate(nb["cells"]):
    src = "".join(c.get("source", []))
    cell_lines = len(src.splitlines())
    cell_start = line_num
    cell_end = line_num + cell_lines - 1
    
    has_llm = "llm = " in src
    has_vs = "vector_store = " in src
    
    if has_llm or has_vs:
        print(f"\n=== cell[{i}] (lines {cell_start}-{cell_end}) ===")
        print(src)
    
    line_num += cell_lines + 1
PY

Repository: NirDiamant/RAG_Techniques

Length of output: 1729


Consolidate provider selection to avoid silent overrides from sequential cell execution.

The notebook unconditionally overwrites llm and vector_store across multiple cells: cell[5] initializes ChatOpenAI, but cell[7] unconditionally reinitializes llm to ChatOllama; similarly, cell[14] sets up FAISS with OpenAI embeddings, but cell[16] unconditionally overwrites it with Ollama embeddings. Running all cells shifts the entire stack to Ollama regardless of the initial provider choice. Use a single provider switch (e.g., environment variable) and initialize one consistent stack per notebook run.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@all_rag_techniques/simple_csv_rag.ipynb` around lines 117 - 125, The notebook
currently reassigns llm and vector_store in multiple cells (e.g., ChatOpenAI
then ChatOllama, FAISS with OpenAIEmbeddings then overwritten by
OllamaEmbeddings), causing silent provider overrides; consolidate provider
selection by reading a single switch (e.g., an ENV var like PROVIDER) and use it
to conditionally initialize only one stack: instantiate llm as either ChatOpenAI
or ChatOllama and vector_store as FAISS with matching embeddings
(OpenAIEmbeddings or OllamaEmbeddings) in one place (look for symbols llm,
vector_store, ChatOpenAI, ChatOllama, FAISS, OpenAIEmbeddings, OllamaEmbeddings)
so running all cells does not overwrite the chosen provider.

Comment on lines +122 to +124
"from langchain_community.document_loaders.csv_loader import CSVLoader\n",
"from langchain_ollama import ChatOllama, OllamaEmbeddings\n",
"llm = ChatOllama(model=\"llama3.2\")"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify notebook imports vs install command dependency list.
python - <<'PY'
import json, re
p="all_rag_techniques/simple_csv_rag.ipynb"
nb=json.load(open(p))
install_cells=[]
imports_ollama=False

for i,c in enumerate(nb["cells"]):
    src="".join(c.get("source", []))
    if "pip install" in src:
        install_cells.append((i, src.strip()))
    if re.search(r'from\s+langchain_ollama\s+import', src):
        imports_ollama=True

print("imports_langchain_ollama:", imports_ollama)
print("install_cells:")
for i,s in install_cells:
    print(f"  cell[{i}]: {s}")
print("has_langchain_ollama_in_install:",
      any("langchain-ollama" in s for _,s in install_cells))
PY

Repository: NirDiamant/RAG_Techniques

Length of output: 283


Add missing langchain-ollama dependency to install step.

Line 123 imports langchain_ollama, but the install cell currently omits langchain-ollama. Fresh runs will fail with an ImportError before the Ollama models are usable.

Suggested fix
- !pip install faiss-cpu langchain langchain-community langchain-openai pandas python-dotenv
+ !pip install faiss-cpu langchain langchain-community langchain-openai langchain-ollama pandas python-dotenv
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@all_rag_techniques/simple_csv_rag.ipynb` around lines 122 - 124, The notebook
imports langchain_ollama (symbols: langchain_ollama, ChatOllama,
OllamaEmbeddings) but the install step omits that package; update the
environment setup/install cell to add the langchain-ollama package so fresh runs
don't raise ImportError before using Ollama models, then re-run the install cell
and confirm imports succeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants