<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Iraj on Medium]]></title>
        <description><![CDATA[Stories by Iraj on Medium]]></description>
        <link>https://medium.com/@Iraj?source=rss-d50a84f4fb10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WKaM4QI9kApyUR0kxMYhGQ.jpeg</url>
            <title>Stories by Iraj on Medium</title>
            <link>https://medium.com/@Iraj?source=rss-d50a84f4fb10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:06:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Iraj/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Qdrant Combines Query Results (Explaining RRF and DBSF)]]></title>
            <link>https://medium.com/@Iraj/how-qdrant-combines-query-results-explaining-rrf-and-dbsf-cd08cd272a80?source=rss-d50a84f4fb10------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd08cd272a80</guid>
            <category><![CDATA[qdrant]]></category>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[search-engines]]></category>
            <dc:creator><![CDATA[Iraj]]></dc:creator>
            <pubDate>Sat, 29 Mar 2025 17:54:15 GMT</pubDate>
            <atom:updated>2025-03-29T17:54:15.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*l9jrEBtRtyO2_bCSQmcSjg.png" /></figure><p>Ever wondered how search engines or databases rank results and make sure you get the most relevant stuff at the top? It’s not magic — it’s math! And Qdrant, a vector database, uses <a href="https://qdrant.tech/documentation/concepts/hybrid-queries/#hybrid-search">two clever techniques</a> to combine results from multiple queries on named vectors per point: <strong>Reciprocal Rank Fusion (RRF)</strong> and <strong>Distribution-Based Score Fusion (DBSF)</strong>. Let me break these down for you in plain, everyday language.</p><h4>Reciprocal Rank Fusion (RRF): Friends With High Ranks Get Boosted!</h4><p>Imagine you’re running multiple searches, and you notice that some items pop up consistently at the top. For example, let’s say you’re looking for the best pizza places, and “Super Tasty Pizza” is ranked #1 in one query and #3 in another. Clearly, it’s a strong contender!</p><p>RRF focuses on where results show up in each query (their <em>rank</em>). Instead of caring about exact scores, it rewards results that rank higher more often. It works like this:</p><ol><li>For each result, RRF gives it a score based on its position: higher rank = bigger boost.</li><li>If a result keeps showing up near the top across multiple queries, its score adds up, giving it a nice overall push.</li></ol><p>Here’s a simple formula RRF uses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*4ITbQP9IMRLaRwfshz7Png.png" /></figure><ul><li><em>k</em> is just a number (usually 60) to make sure even lower-ranked results don’t completely vanish.</li><li>The <em>rank </em>is where the result sits on the list. For example, rank 1 gives a higher score than rank 5.</li></ul><p>So, “Super Tasty Pizza” might end up as the ultimate winner because it was consistently ranked high across your searches!</p><h4>Distribution-Based Score Fusion (DBSF): Normalizing the Scores Like a Pro</h4><p>Now, what if instead of ranks, you want to deal with the actual scores from each query? DBSF does just that. The challenge here is that scores can be on wildly different scales. For example, one query might give scores out of 10, while another uses percentages. Comparing these directly would be like comparing apples to oranges.</p><p>DBSF solves this problem with a bit of statistical wizardry:</p><ol><li><strong>Step 1:</strong> It looks at the scores for a query and calculates the average (called the <em>mean</em>) and how spread out the scores are (using <em>standard deviation</em>).</li><li><strong>Step 2:</strong> It sets boundaries around the mean — three standard deviations above and below. This creates a nice range to identify and compare scores fairly.</li><li><strong>Step 3:</strong> It adjusts (or “normalizes”) every score into a 0-to-1 range so they all play nicely together.</li></ol><p>The formula looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*_jiDEfGn2kS_MKycZd82-g.png" /></figure><p>Here, <em>σ </em>is the standard deviation.</p><p>After that, it adds up the normalized scores from all queries for the same result. Voilà! You get a final score that combines information from everywhere in a fair and balanced way.</p><h4>So, What’s the Big Deal?</h4><p>These techniques make sure that the search results you get are <strong>consistent and reliable</strong>:</p><ul><li><strong>RRF</strong> boosts results that perform well across multiple queries, focusing on ranks.</li><li><strong>DBSF</strong> balances the actual scores across queries to compare apples to apples (or pizzas to pizzas).</li></ul><p>Whether you’re building a vector search or just curious about how databases handle multiple queries, these methods are smart ways to ensure top-notch relevance.</p><p>What do you think — pretty neat, right? Next time you search for something, and the perfect result is right at the top, remember there’s a whole lot of clever math behind the scenes making it happen! 🍕</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd08cd272a80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serving Downloadable Protected Files by Nginx and Django]]></title>
            <link>https://medium.com/@Iraj/serve-downloadable-protected-files-by-nginx-and-django-9ac4d10252df?source=rss-d50a84f4fb10------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ac4d10252df</guid>
            <category><![CDATA[download]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[protect]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Iraj]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 15:15:01 GMT</pubDate>
            <atom:updated>2019-09-15T10:07:19.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*jp9V1PjPqxQ1ihiWddUL0Q.png" /></figure><p>These other days, I had a challenge with Django and Nginx, so after dealing with the challenge, decided to publish the solution here. the challenge was about serving downloadable protected files by Django. needed a way to allow permitted requests for downloadable protected files in Django. it seems easy writing a View to authorize and serve requests protected files. but serving files by Django on its own, isn’t such a great idea. because Django isn’t asynchronous yet, so by keeping busy views due to long read/write IO actions (reading file chunks and sending them for client — downloading or receiving many chunks and writing them as a file for a long from client — uploading), your backend will be blocked, actually, it’s not good in production at all.</p><p>So I needed a way to handle protected files by Nginx and protect them by Django as Nginx is a reliable asynchronous server to serve static files . fortunately, Nginx and Apache have mechanisms that help you improve performance with reverse proxies, via mechanisms such as <a href="https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/"><strong>Nginx’s X-Accel</strong></a> or <strong>Apache’s X-Sendfile</strong>.</p><p>Indeed <strong>Nginx’s X-Accel </strong>is a mechanism in which you can tell Nginx to redirect internal requests with helping of a response header called <strong><em>X-Accel-Redirect.</em></strong></p><p><em>We’ll use X-Accel-Redirect header in Django view’s response to tell nginx redirecting to a certain URL (in this case, protected files url)</em></p><p>Suppose We have such models in <em>Models.py</em> :</p><pre><em>class</em> File(<em>models</em>.<em>Model</em>):<br>    title = models.CharField(<em>max_length</em>=255, <em>blank</em>=True, <em>null</em>=True)<br>    description = models.TextField(<em>blank</em>=True, <em>null</em>=True)<br>    upload_date = models.DateTimeField(<em>auto_now_add</em>=True)<br>    update_date = models.DateTimeField(<em>auto_now</em>=True)<br>    # file will be saved to MEDIA_ROOT/uploads/2015/01/30<br>    file = models.FileField(<em>upload_to</em>=&#39;uploads/%Y/%m/%d/&#39;)<br>    owner = models.ForeignKey(<br>        settings.AUTH_USER_MODEL,<br>        <em>related_name</em>=&#39;owner_files&#39;,<br>        <em>on_delete</em>=models.CASCADE,<br>    )<br>   <em>def</em> __str__(<em>self</em>):<br>       return self.title or self.description or self.file.url<br></pre><pre><em>class</em> Message(<em>models</em>.<em>Model</em>):<br>    title = models.CharField(<em>max_length</em>=255, <em>blank</em>=True, <em>null</em>=True)<br>    message = models.TextField(<em>blank</em>=True, <em>null</em>=True)<br>    files = models.ManyToManyField(<br>        File,<br>        <em>blank</em>=True,<br>        <em>null</em>=True,<br>        <em>related_name</em>=&#39;messages&#39;)</pre><pre>    is_read = models.BooleanField(<em>default</em>=False)<br>    is_public = models.BooleanField(<em>default</em>=False)<br>    created_date = models.DateTimeField(<em>auto_now_add</em>=True)<br>    read_date = models.DateTimeField(<em>blank</em>=True, <em>null</em>=True)<br>    to_users = models.ManyToManyField(settings.AUTH_USER_MODEL, &#39;inbox&#39;)<br>    created_by = models.ForeignKey(<br>        settings.AUTH_USER_MODEL,<br>        <em>related_name</em>=&#39;sent_inbox_messages&#39;,<br>        <em>on_delete</em>=models.CASCADE,<br>    )</pre><pre>    parent = models.ForeignKey(<br>        &#39;self&#39;,<br>        <em>null</em>=True,<br>        <em>blank</em>=True,<br>        <em>related_name</em>=&#39;replies&#39;,<br>        <em>on_delete</em>=models.CASCADE<br>    )</pre><pre><em>    def</em> __str__(<em>self</em>):<br>        return self.title or self.message</pre><p>And a view like this:</p><pre><em>def</em> download(<em>request</em>, <em>id</em>):<br>    file = get_object_or_404(File, <em>id</em>=id)<br>    messages = file.messages.all()<br>    is_allowed = True if len(<em>list</em>(filter(<br>        <em>lambda</em> <em>message</em>: (<br>            request.user in message.to_users.all()<br>            or<br>            request.user.username == message.created_by.username<br>        ),<br>        messages<br>    ))) else False<br>    response = HttpResponse()<br>    if not request.headers.get(&#39;X-Real-Ip&#39;):<br>        response.status_code = 404<br>        response.content = &#39;The request should be come from Nginx server.&#39;<br>        return response</pre><pre>    if not is_allowed:<br>        response.status_code = 403<br>        response.content = &#39;You are not allowed to access this file.&#39;<br>        return response</pre><pre>    file_name = file.file.name<br>    # Let NGINX handle it<br>    <strong>response[&#39;X-Accel-Redirect&#39;] = <em>f</em>&#39;/{file.file.url}&#39;</strong><br>    response[&#39;Content-Disposition&#39;] = &#39;attachment; filename=&quot;{}&quot;&#39;.format(<br>        file_name<br>    )<br>    return response</pre><p>And in <em>urls.py</em>:</p><pre>urlpatterns = [<br>     path(&#39;download/&lt;int:id&gt;/&#39;, views.download, <em>name</em>=&#39;download&#39;),<br>]</pre><p>Then set following Nginx’s setting and restart Nginx server:</p><pre>server {<br>    listen 80;<br>    location / {<br>        # Django server:<br>        proxy_pass <a href="http://localhost:8000;">http://localhost:8000;</a><br>        proxy_set_header   Host             $host;<br>        proxy_set_header   X-Real-IP        $remote_addr;<br>        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;<br>    }<br>    location /uploads/ {<br>        # Only allow internal redirects<br>        <strong>internal;</strong><br>        # Django upload directory<br>        <strong>alias /path/to/django/upload/directory/;</strong><br>    }<br>}</pre><p>That’s it. now you can serve protected files perfectly :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ac4d10252df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing and Running Postgresql on Manjaro OS]]></title>
            <link>https://medium.com/@Iraj/installing-and-running-postgresql-on-manjaro-os-10210cdefbd6?source=rss-d50a84f4fb10------2</link>
            <guid isPermaLink="false">https://medium.com/p/10210cdefbd6</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[arch]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[manjaro]]></category>
            <category><![CDATA[installation]]></category>
            <dc:creator><![CDATA[Iraj]]></dc:creator>
            <pubDate>Sun, 18 Mar 2018 22:50:41 GMT</pubDate>
            <atom:updated>2019-09-03T22:20:57.401Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*sW4xxcGF8bMf3U_IZ-H4aA.jpeg" /></figure><p>Ima introduce you to installing and running Postgresql server on Manjaro (an ARCH based gnu/linux distribution) OS.<br>Let’s start via installing Postgresql on our system through below command:</p><pre>yaourt -S postgresql-9.5</pre><p>it is worth noting that I know the Postgres 9.5 is out of date but I needed that as a dependency in a project. So you can install a newer version. I used <strong>Yaourt</strong> command to look up an old version however you can use <strong>Pacman</strong> in order to install more recently version.</p><p>Ok. the next steps is to make a directory as the data area on disk ( also called database cluster in PostgreSQL). Of course it is completely up to you where you want to store your data:</p><pre>$ sudo mkdir -p /var/lib/postgres/data</pre><p>and then change owner and group ownership of the database cluster in favor of Postgres:</p><pre><em>$ sudo chown -c -R postgres:postgres /var/lib/postgres</em></pre><p>I am not sure about the following commands, I just noted them in my postgres installation document. So if you were asked to such a path during <strong>server running proccess </strong>you can run them:</p><pre><em>$ sudo mkdir /run/postgresql/; </em><br>$ sudo chown -c -R postgres:postgres /run/postgresql/</pre><p>now it’s time to switch in Postgres shell:</p><pre><em>$ su<br># su postgres</em></pre><p>so I will show commands that will be run in postgres shell via the prefix “<strong><em>[postgres]$</em></strong>”. To initialize the data area (or data directory or database cluster) we can use 2 commands:</p><pre><em>[postgres]$ initdb -D /var/lib/postgres/data</em></pre><p>or</p><pre><em>[postgres]$ pg_ctl -D /var/lib/postgres/data initdb</em></pre><p>both of commands ( <em>initdb</em> &amp; <em>pg_ctl</em>) will be exist along with postgresql installation.</p><p>Yes. Let’s start the postgres database server now:</p><pre><em>[postgres]$ pg_ctl -D /var/lib/postgres/data start</em></pre><p>also we can enable the database server as a service in background using systemctltoo. in this case we don’t need an open terminal any longer like when we typed the commands.</p><pre><em>$ sudo systemctl start postgresql</em></pre><p>so we can use following command to find out that our postgres server works correctly as well:</p><pre><em>[postgres]$ pg_isready <br>/run/postgresql:5432 — accepting connections</em></pre><p><strong>Congratulations !!!</strong> the server is accepting connections and works great ;)</p><p>finally I list some useful commands below:</p><pre><em># to exit from postgres shell:<br>[postgres]$ ^C</em></pre><pre><em># to remove the storage:<br>$ sudo rm -R /var/lib/postgres/*</em></pre><pre><em># to kill the server:<br>kill -INT `head -1 /var/lib/postgres/data/postmaster.pid`</em></pre><p>Hopfully the article helped you to install postgresql server quickly and correctly on your Manjaro.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10210cdefbd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>