<?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: andrew</title>
    <description>The latest articles on DEV Community by andrew (@halftruths).</description>
    <link>https://dev.to/halftruths</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2348923%2F352f70a2-b829-4318-94ad-07d875eacaf6.jpg</url>
      <title>DEV Community: andrew</title>
      <link>https://dev.to/halftruths</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/halftruths"/>
    <language>en</language>
    <item>
      <title>Relevant arXiv paper RAG</title>
      <dc:creator>andrew</dc:creator>
      <pubDate>Mon, 11 Nov 2024 07:43:01 +0000</pubDate>
      <link>https://dev.to/halftruths/relevant-arxiv-paper-rag-4k2m</link>
      <guid>https://dev.to/halftruths/relevant-arxiv-paper-rag-4k2m</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pgai"&gt;Open Source AI Challenge with pgai and Ollama &lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;Imagine having an assistant that can, based on a given research topic/paper, instantly connect you with papers that are relevant to you - saving hours spent sifting through services like Arxiv!&lt;/p&gt;

&lt;p&gt;This project is a research paper recommendation system leveraging RAG with PostgreSQL, pgVectorScale, and a language model (choose from ChatGpt4o:mini/Claude35/llama32:3b). Using a *&lt;em&gt;single *&lt;/em&gt; arXiv paper ID, the system finds similar research articles using vector embeddings, allowing users to dive deeper into related works, spot trends, and explore different approaches on the topic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Hosted GUI: &lt;br&gt;
&lt;a href="https://tinyurl.com/timescalechallengeanyademo" rel="noopener noreferrer"&gt;https://tinyurl.com/timescalechallengeanyademo&lt;/a&gt;&lt;/strong&gt; &lt;br&gt;
Note: May be unavailable due to Gradio 72hr url limit - &lt;strong&gt;SEE COLAB-HOSTED SELF-RUNNABLE SOURCE CODE BELOW&lt;/strong&gt;, slow due to multiple users, some recent arXiv url/papers don't work)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Top-10 Similar Papers Demo&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figu434n9a47v6fuaoxaj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figu434n9a47v6fuaoxaj.gif" alt="GRadio Top-10 Similar Papers Demo" width="480" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;T10 Similar Paper Summary/Analysis Demo&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5dewf5371qa3s74hqxck.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5dewf5371qa3s74hqxck.gif" alt="GRadio Similar Paper Summary Demo" width="480" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static Preview&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8pirmfsrbto3175edq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8pirmfsrbto3175edq1.png" alt="Static UI Screenshot" width="800" height="1422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Colab Notebook Source Code (Try it: ~10min):&lt;br&gt;
&lt;a href="https://tinyurl.com/timescalechallengeanyanotebook" rel="noopener noreferrer"&gt;https://tinyurl.com/timescalechallengeanyanotebook&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NOTE: Default configuration uses Ollama, but OpenAI Anthropic Claude w/ Cohere Embeddings is preferred due to context length limitations with pgAI and Ollama embeddings (LLM similarity analysis/question: 3 papers instead of 10 papers w/ Ollama, see final thoughts). &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools Used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;pgvector &amp;amp; pgvectorscale: Backbone for storing and searching vector embeddings of arXiv paper texts, which are each converted into vector representation. Use DISKANN (or IVFFLAT) for grouping, indexing embeddings.&lt;/li&gt;
&lt;li&gt;pgai: Used for generating embeddings and answer questions for research documents. pgAI is used as a gateway to OpenAI, Anthropic, Cohere, and Ollama.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Additional unique aspects of this project: 

&lt;ul&gt;
&lt;li&gt;Usage Postgres stored functions to call pgai functions in 'function mode', enabling users without any access to the database or pgai to build a RAG (superior security).&lt;/li&gt;
&lt;li&gt;Integration with OpenAI, Anthropic, and local Ollama APIs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Learnings

&lt;ul&gt;
&lt;li&gt;The learning curve for implementation was of medium level, but I felt like I learned a lot from exploring timescale's github documentation and writing stored function commands (with ChatGPT's help, took my database systems course &amp;gt;1yr ago - a little rusty). Should add further documentation and review for inefficiencies to notebook in future.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Feedback

&lt;ul&gt;
&lt;li&gt;pgvector is limited to an embedding dimension size of 4k (2k if full vector is used), falling short of OpenAI's 4096. I wrote additional code to trim the output, which complicated the implementation.&lt;/li&gt;
&lt;li&gt;pgAI's Ollama may have context length issues (when I use Ollama's interface directly there are no such issues), which limited the later question-answering function to 3 papers. When using Anthropic/Cohere, we could do more.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>devchallenge</category>
      <category>pgaichallenge</category>
      <category>database</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
