<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: RafterKode</title>
    <description>The latest articles on DEV Community by RafterKode (@rafterkode).</description>
    <link>https://dev.to/rafterkode</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4251434%2F3a4c27ca-25fc-4218-abc6-26fe3b3017d4.jpg</url>
      <title>DEV Community: RafterKode</title>
      <link>https://dev.to/rafterkode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafterkode"/>
    <language>en</language>
    <item>
      <title>My first RAG project</title>
      <dc:creator>RafterKode</dc:creator>
      <pubDate>Thu, 03 Dec 2026 08:06:07 +0000</pubDate>
      <link>https://dev.to/rafterkode/my-first-rag-project-51g0</link>
      <guid>https://dev.to/rafterkode/my-first-rag-project-51g0</guid>
      <description>&lt;p&gt;I have been interested in LLMs that can be installed locally, with the goal of controlling the data provided and its propagation outside the private network. ⁠&lt;br&gt;
Here is a presentation of the choices I made and how I implemented them.&lt;/p&gt;
&lt;h2&gt;
  
  
  LLM Installation
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -fsSL https://ollama.com/install.sh &lt;span class="o"&gt;|&lt;/span&gt; sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; Installing ollama to /usr/local
&amp;gt;&amp;gt;&amp;gt; Downloading ollama-linux-amd64.tar.zst
######################################################################## 100,0%
&amp;gt;&amp;gt;&amp;gt; Creating ollama user...
&amp;gt;&amp;gt;&amp;gt; Adding ollama user to render group...
&amp;gt;&amp;gt;&amp;gt; Adding ollama user to video group...
&amp;gt;&amp;gt;&amp;gt; Adding current user to ollama group...
&amp;gt;&amp;gt;&amp;gt; Creating ollama systemd service...
&amp;gt;&amp;gt;&amp;gt; Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
&amp;gt;&amp;gt;&amp;gt; The Ollama API is now available at 127.0.0.1:11434.
&amp;gt;&amp;gt;&amp;gt; Install complete. Run "ollama" from the command line.
WARNING: No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;My PC does not have an active GPU, so my LLM will run exclusively on the CPU.&lt;/p&gt;
&lt;h2&gt;
  
  
  Post-installation Verification
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama --version
systemctl status ollama
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ollama version is 0.40.16

● ollama.service - Ollama Service
     Loaded: loaded (/etc/systemd/system/ollama.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2026-11-18 13:28:54 CET; 3min 58s ago
   Main PID: 4228 (ollama)
      Tasks: 13 (limit: 18737)
     Memory: 11.6M
        CPU: 559ms
     CGroup: /system.slice/ollama.service
             └─4228 /usr/local/bin/ollama serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Downloading the LLM Model for Response Generation
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama pull qwen2.5:1.5b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pulling manifest
pulling 183715c43589: 100% ▕██985 MB/986 MB   78 MB/s  0s
pulling 377ac4d7aeef: 100% ▕██ 487 B
verifying sha256 digest
writing manifest
success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I chose Qwen2.5:1.5b, with a download size of approximately 986 MB. It is a lightweight model, and since I only need French and English, it is more than sufficient for my requirements.&lt;/p&gt;
&lt;h2&gt;
  
  
  RAM Configuration and Service Restart
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo systemctl edit ollama
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Add the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"OLLAMA_MAX_LOADED_MODELS=1"&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"OLLAMA_NUM_PARALLEL=1"&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"OLLAMA_CONTEXT_LENGTH=2048"&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"OLLAMA_KEEP_ALIVE=0"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then reload the systemd configuration and restart the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo systemctl daemon-reload
sudo systemctl restart ollama
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have now optimized our model so that only one model instance can be loaded at a time, with no parallel processing. The model will also be unloaded after use.&lt;/p&gt;

&lt;p&gt;The context length is limited to a maximum of 2,048 tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local-rag/
│
├── documents/
│   ├── document1.pdf
│   └── document2.pdf
│
├── database/
│
├── app/
│   ├── ingest.py
│   └── api.py
│
└── requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing Dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt update
sudo apt install python3 python3-venv python3-pip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating an Isolated Environment
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mkdir local-rag
&lt;span class="nb"&gt;cd&lt;/span&gt; local-rag

python3 -m venv venv
&lt;span class="nb"&gt;source&lt;/span&gt; venv/bin/activate

mkdir documents database app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  requirements.txt Content
&lt;/h3&gt;

&lt;p&gt;We do not pin dependency versions because this is a local environment, not a production environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fastapi
uvicorn
chromadb
pymupdf
requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing Python Dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running Our Python Scripts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  app/ingest.py
&lt;/h3&gt;

&lt;p&gt;This script indexes the PDF files, splits their content into chunks, and stores them locally in a database to avoid having to reload and process them every time the application starts.&lt;/p&gt;

&lt;p&gt;Indexing process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PDF → Text → Chunks → Embeddings → ChromaDB&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  app/api.py
&lt;/h3&gt;

&lt;p&gt;This file contains our API, which allows users to search for the requested information within the indexed documents.&lt;/p&gt;

&lt;p&gt;After placing the PDF file in the &lt;code&gt;documents&lt;/code&gt; directory, simply run the indexing script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python app/ingest.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Starting the API and Making It Available to the User
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uvicorn app.api:app --host 127.0.0.1 --port 8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The associated endpoint will then be available at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://127.0.0.1:8000/ask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing Using a Browser or the Command Line
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -X POST http://127.0.0.1:8000/ask \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{
    "question": "What are the key points of the document?"
  }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will receive a JSON response containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The question.&lt;/li&gt;
&lt;li&gt;The generated answer.&lt;/li&gt;
&lt;li&gt;The source documents.&lt;/li&gt;
&lt;li&gt;The page numbers.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🌐 &lt;a href="https://rafterkode.github.io/" rel="noopener noreferrer"&gt;rafterkode.github.io&lt;/a&gt;   &lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>rag</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
