Run DeepSeek-R1 Locally & Build RAG Applications!
Pavan Belagatti

Pavan Belagatti @pavanbelagatti

About: Developer Advocate| Learning AI/ML/DataScience

Joined:
Apr 22, 2018

Run DeepSeek-R1 Locally & Build RAG Applications!

Publish Date: Jan 29
2822 27

DeepSeek-R1 has been creating quite a buzz in the AI community. Developed by a Chinese AI company DeepSeek, this model is being compared to OpenAI's top models. The excitement around DeepSeek-R1 is not just because of its capabilities but also because it is open-sourced, allowing anyone to download and run it locally. In this blog, I'll guide you through setting up DeepSeek-R1 on your machine using Ollama.

Why DeepSeek-R1?

DeepSeek R1

DeepSeek-R1 stands out for several reasons. Not only is it cheaper than many other models, but it also excels in problem-solving, reasoning, and coding. Its built-in chain of thought reasoning enhances its efficiency, making it a strong contender against other models. Let's dive into how you can get this model running on your local system.

Getting Started with Ollama

ollama logo
Before we begin, let's discuss Ollama. Ollama is a free, open-source tool that allows users to run Natural Language Processing models locally. With Ollama, you can easily download and run the DeepSeek-R1 model.

Here's how you can get started:

Step 1: Install Ollama

First, you'll need to download and install Ollama. Visit the Ollama website and download the version that matches your operating system.
Follow the installation instructions provided on the site.

install ollama

Step 2: Download DeepSeek-R1

step 2 download deepseek-R1

As you can see when you go to Ollama website, you can run the different parameters of DeepSeek-R1. You can find the details of requirements here (as shown above in the screenshot)

You can run 1.5b, 7b, 8b, 14b, 32b, 70b, 671b and obviously the hardware requirements increase as you choose bigger parameter. I used 7b one in my tutorial.

Once Ollama is installed, open your terminal and type the following command to download the DeepSeek-R1 model:

DeepSeek-7b

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

This command tells Ollama to download the model. Depending on your internet speed, this might take some time. Grab a coffee while it completes!

Step 3: Verify Installation

After downloading, verify the installation by running:

ollama list
Enter fullscreen mode Exit fullscreen mode

You should see deepseek-r1 in the list of available models. If you do, great job! You're ready to run the model.

Step 4: Run DeepSeek-R1

Now, let's start the model using the command:

ollama run deepseek-r1
Enter fullscreen mode Exit fullscreen mode

And just like that, you're interacting with DeepSeek-R1 locally. It's that simple!

Step 5: Ask a Query

ask a query

Chain-of-thought reasoning by the model.

chain of thought

The model looks good with coding tasks also. Let's check that approach too.

deepseek code generation

The detailed anwer for the above code related query.

code gen R1

Below is a complete step-by-step video of using DeepSeek-R1 for different use cases.

My first impression about DeepSeek-R1 is just mind blowing:)

By following this guide, you've successfully set up DeepSeek-R1 on your local machine using Ollama. This setup offers a powerful solution for AI integration, providing privacy, speed, and control over your applications. Enjoy experimenting with DeepSeek-R1 and exploring the potential of local AI models. BTW, having a robust database for your AI/ML applications is a must. I recommend using an all-in-one data platform like SingleStore.


Let's Build a RAG Application using DeepSeek and SingleStore

If you like to extend your learning and build a simple RAG application, you can follow this tutorial.

We will set the DeepSeek API key from NVIDIA NIM microservice (Yes, I'll show you how). NVIDIA NIM (Inference Microservices) is a set of microservices that help deploy AI models across clouds, data centers, and workstations. We will be using LangChain as our LLM framework to bind everything. We will be using SingleStore as our vector database.

Let's Get Started (Follow Along)

1. Prerequisites [All are FREE]

First thing is to create a free SingleStore account. Login to your account and create a workspace and a database for yourself.

singlestore workspace

After creating a workspace, create a database attached to that workspace. Click on create a database as shown in the dashboard screenshot to create a database.

singlestore db

Cool. Now, we created our database to store our custom documents for our RAG application.

The next step is to create a Notebook. Yes, a free notebook environment. SingleStore has this cool integrated feature where you can use their Notebooks [Just like your Google collab]

Go to Data Studio and then create a new Notebook.
SingleStore Notebooks

Give a name to your Notebook
notebook name

This is where you will land.
ss dashboard

Make sure to select your workspace and database you created from the dropdown as shown below. My workspace name is 'pavappy-workspace-1' and the database I created is 'DeepSeek'. So I have selected both.

workspace ss

Now we are all set to code our RAG application. Start adding all the below code step-by-step into the newly created notebook (make sure to run each code snippet aswell)

Start with installing all the required libraries and dependencies.

!pip install langchain --quiet
!pip install pdf2image --quiet
!pip install pdfminer.six --quiet
!pip install singlestoredb --quiet
!pip install tiktoken --quiet
!pip install --upgrade unstructured==0.10.14 --quiet
!pip install -qU pypdf langchain_community
!pip install langchain-nvidia-ai-endpoints --quiet
!pip install langchain-deepseek-official --quiet
Enter fullscreen mode Exit fullscreen mode

Import libraries

from langchain.document_loaders import PyPDFLoader
from langchain_nvidia_ai_endpoints import ChatNVIDIA
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.chains import RetrievalQA
from langchain.vectorstores import SingleStoreDB
import os
Enter fullscreen mode Exit fullscreen mode

Load your custom document [I have used a publicly available pdf, you can replace and use your own)

file_path = "https://unctad.org/system/files/official-document/wesp2023_en.pdf"
loader = PyPDFLoader(file_path)
data = loader.load()
Enter fullscreen mode Exit fullscreen mode

Split document into chunks

text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, chunk_overlap=0)
texts = text_splitter.split_documents(data)
Enter fullscreen mode Exit fullscreen mode

Set up OpenAI embeddings (for vectorization)

os.environ["OPENAI_API_KEY"] = "Add your OpenAI API key"
embedding = OpenAIEmbeddings()
Enter fullscreen mode Exit fullscreen mode

Store embeddings in SingleStore

docsearch = SingleStoreDB.from_documents(
    texts,
    embedding,
    table_name="deepseek_rag", # Replace table name with any name
    host="admin:password@host_url:3306/database_name",  # Replace with your SingleStore connection
    port=3306
)
Enter fullscreen mode Exit fullscreen mode

In the above code, admin is constant and don't change that. You can get your password from the access tab and host url can get as shown below. Go to your deployments tab, you should see your workspace, click on connect and then see the dropdown as below. Select 'SQL IDE' from there and you will see all the required details.

singlestore connect

Next, Initialize DeepSeek through NVIDIA NIM
Get your DeepSeek-R1 API Key for free from NVIDIA NIM microservice. Get it from HERE.

client = ChatNVIDIA(
    model="deepseek-ai/deepseek-r1",
    api_key="Add your DeepSeek-R1 API key you received from NVIDIA NIM microservice",  # Replace with your NVIDIA API key
    temperature=0.7,
    top_p=0.8,
    max_tokens=4096
)
Enter fullscreen mode Exit fullscreen mode

Create RAG chain

qa_chain = RetrievalQA.from_chain_type(
    llm=client,
    chain_type="stuff",
    retriever=docsearch.as_retriever(search_kwargs={"k": 3}),
    return_source_documents=True
)
Enter fullscreen mode Exit fullscreen mode

Query the RAG system

query = "What India's GDP growth is projected to be?"
result = qa_chain.invoke({"query": query})
Enter fullscreen mode Exit fullscreen mode

Display results

print("Answer:", result["result"])
print("\nSources:")
for doc in result["source_documents"]:
    print(f"- Page {doc.metadata['page']}: {doc.page_content[:100]}...")
Enter fullscreen mode Exit fullscreen mode

You should see a fine response from the model:)

deepseek model response

You can go check your database to see how the data has been chunked and stored in the vector embeddings format.

data in embeddings

Here is the complete code repo you can try:)

RAG Application With DeepSeek-R1, LangChain and SingleStore

We will set the DeepSeek API key from NVIDIA, as we will be using NVIDIA NIM Microservice. NVIDIA NIM (Inference Microservices) is a set of microservices that help deploy AI models across clouds, data centers, and workstations. We will be using LangChain as our LLM framework to bind everything. We will be using SingleStore as our vector database.

Prerequisites

  • Free SingleStore account

  • Free NVIDIA NIM account

    Refer to my article on devto to know more about how you can run DeepSeek-R1 locally. I have also included this repo in the article and explained how you can create a simple RAG application.




Thank you for reading my article. Hope you tried the entire tutorial. You can also follow me through my Youtube channel. I create AI/ML/Data related videos on a weekly basis.

Comments 27 total

  • Aman Singh
    Aman SinghJan 29, 2025

    What is the minimum Requirements of Hardware to run this?

    • Pavan Belagatti
      Pavan BelagattiJan 29, 2025

      As you can see when you go to Llama website, you can run the different parameters of DeepSeek-R1. You can find the details of requirements here: ollama.com/library/deepseek-r1

      You can run 1.5b, 7b, 8b, 14b, 32b, 70b, 671b and obviously the hardware requirements increase as you choose bigger parameter. I used 7b one in the above tutorial.

      • Johnny
        JohnnyJan 30, 2025

        Maybe be clearer about that in the article. It is deceiving to not specifically say what model you are running. "Running R1 locally" sounds like you are running their best OpenAI o1 equivalent locally, which is not the case.

        • Pavan Belagatti
          Pavan BelagattiJan 30, 2025

          It is the same but with less parameter one. Done. Updated the article with 7b.

      • Christian A
        Christian AFeb 1, 2025

        You literally need a tank for running 671b.
        70b and smaller ones are possible at home. You can run it on CPU or on GPU, whicht is a lot faster. A cool one would be an NVIDIA 3090, you can rebuy it for around 700 euros atm.

  • Moeed Anjum
    Moeed AnjumJan 29, 2025

    Good one, it helped me a lot.

    Say hello to DeepSeek R1—the AI-powered platform that’s changing the rules of data analytics!

    🔍 What makes DeepSeek R1 a game-changer?
    ✅ Real-time data processing for instant insights
    ✅ Advanced machine learning & NLP capabilities
    ✅ Scalable, secure, and user-friendly
    ✅ Perfect for industries like healthcare, finance, e-commerce, and more
    Whether you're a data scientist, business leader, or tech enthusiast, DeepSeek R1 is your ultimate tool to unlock the true potential of your data.

    📖 Want to learn more? Dive into the full blog to discover how DeepSeek R1 can transform your business:

    👉 myappranking.com/deepseek-r1

  • Muhamed-Kanapiya
    Muhamed-KanapiyaJan 29, 2025

    is there GUi for local version?

    • Pavan Belagatti
      Pavan BelagattiJan 29, 2025

      No idea, need to check.

    • youssefma6
      youssefma6Jan 29, 2025

      yeah there is one ! you can pair Ollama with Open WebUI – a graphical user interface (GUI) tool
      just go to docs.openwebui.com

    • Jody Elliott
      Jody ElliottJan 29, 2025

      MSTY.app is a great one and my favorite. LMStudio is nice as well.

  • rakesh manchanda
    rakesh manchandaJan 29, 2025

    What happened at tinanimun Square

  • Eugénio Correia
    Eugénio CorreiaJan 29, 2025

    My name is Eugénio Correia

    • Luis F
      Luis FFeb 3, 2025

      Hola eugenio correia

  • Ali Akbar
    Ali AkbarJan 29, 2025

    سلام

  • Radian al Mahmmud
    Radian al MahmmudJan 31, 2025

    how to download it to a specific drive and not the c drive?

  • Luis Brown
    Luis BrownFeb 1, 2025

    Well done. Simple and straight to the point. Thank you for contributing and helping those of us that really need guidance. I'm running an Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz 1.99 GHz, with 16.0 GB (15.8 GB usable), and I downloaded the deepseek-r1:32b.

    Wish me luck.

  • Farrukh Mustafa
    Farrukh MustafaFeb 2, 2025

    Is there a way to get the API key when running it locally?

  • mcwood
    mcwoodFeb 5, 2025

    I asked who is the current US president and the answers is Joe Biden.
    Maybe that is why it is free.

  • Rushali Bhardwaj
    Rushali BhardwajFeb 25, 2025

    "Maximize your productivity with DeepSeek AI! 🚀
    Here are 100+ use cases to get the most out of AI prompts: [mimicpc.com/learn/deepseek-ai-prom...]

    DeepSeek #AIPrompts #TechGuide #ProductivityHacks #Innovation"

  • Joris W
    Joris WApr 8, 2025

    Could better introduce why the SingleStore account and DeepSeek API key from NVIDIA NIM are needed and why they stand out from any alternatives.

    Likewise each of the steps could use a reason for why they are taken.

Add comment