Code Monkey home page Code Monkey logo

ai-discipline-ollama-rag's Introduction

AI Discipline Code-Along: Ollama RAG

27 Mar 2024

This code-along will focus on a simple RAG implementation that runs locally on your machine using Ollama. In addition to installing the dependencies below, choose a document with text content that you want to chat with the model about, and store it as a PDF in the documents directory. Haystack has support for other document converters as well, although you may need to install additional dependencies. This code-along will assume you're using a PDF.

Dependencies

  • Python 3.11+ (Rye will automatically use 3.11 by default; see below)
  • VS Code (https://code.visualstudio.com/) with the Python extension (search in Extensions in the side bar)
  • Rye (https://rye-up.com/), to manage the project’s Python third-party dependencies and Python interpreter version. For Windows users, you’ll likely want to use the 64-bit installer.
  • Ollama (https://ollama.com/)

Setup

First, clone this repo, and open the ollama-rag.code-workspace file in VS Code.

From the terminal in VS Code, install the Python dependencies using Rye:

$ rye sync

This will install the following Python dependencies in a virtual environment: gradio ollama haystack-ai ollama-haystack pypdf. If VS Code prompts you to select the new environment for the workspace, say yes.

Next, use Ollama to pull down the models you want to use. Do these two, at least:

$ ollama pull llama2
$ ollama pull nomic-embed-text

Test it out by chatting with it on the command line:

$ ollama run llama2

If you’d like, check out the supported models at https://ollama.com/library and pull any that you’d like to try. Unless you have a powerful GPU, it’s recommended that you use models in the 7b-parameter and under category. If your machine only supports running on CPU and you want to speed that up, there are smaller models such as gemma:2b that you can try, although the performance will not be as good. In general, the more parameters the model has, the better its accuracy, the more resources it requires, and the more slowly it runs. I’ll be doing the code-along with the llama2:7b model, but feel free to experiment and use what you like best!

ai-discipline-ollama-rag's People

Contributors

kylealanhale avatar

Stargazers

Utkarsh Thakkar avatar Ashton Sax avatar paul mathai avatar Gabriel Streza avatar Ajay Khampariya avatar Matthew Simo avatar

Watchers

 avatar  avatar

ai-discipline-ollama-rag's Issues

issues during setup that I resolved but documenting here

I had some issues on my mac during the setup process that I wanted to list out here. Probably should put in PR instead of an issue but don't have time

Note: This was the first time I ever used Python on my work laptop

Rye

Don't install rye via homebrew, I did and it skipped a few important steps. Install it using the official guide on the website: https://rye-up.com/

Allow it to install Python for you and don't forget to "Add Shims to Path": https://rye-up.com/guide/installation/#add-shims-to-path
The install script will prompt you to do it for you, but I said no and did it myself.

Ryn Sync Cert failure

running rye sync got me a Cert issue caused by our Zscaler cert.

Screenshot 2024-03-27 at 12 08 30 PM

easy fix that I found in our product handbook

I added these variables to my bash/zsh profile (for me it's .bashrc)

# needed for Pip (python) to work
# https://help.zscaler.com/zia/adding-custom-certificate-application-specific-trust-store
export CERT_PATH=/etc/ssl/certs/ca-zscaler-plus-all.pem
export CERT_DIR=/etc/ssl/certs/
export SSL_CERT_FILE=${CERT_PATH} 
export SSL_CERT_DIR=${CERT_DIR}
export REQUESTS_CA_BUNDLE=${CERT_PATH} 

Ollama

I installed this via Homebrew, and then I had to start the service using brew services start ollama

This command didn't work for me at first

$ ollama run llama2

But it worked after I ran ollama serve for some reason. See screenshots below

Screenshot 2024-03-27 at 1 19 32 PM
Screenshot 2024-03-27 at 1 20 01 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.