<?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: Tim Pap</title>
    <description>The latest articles on DEV Community by Tim Pap (@blackpr).</description>
    <link>https://dev.to/blackpr</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%2F200216%2Fd0fa1f54-f73b-47b3-b9af-614cadf5ea06.jpeg</url>
      <title>DEV Community: Tim Pap</title>
      <link>https://dev.to/blackpr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/blackpr"/>
    <language>en</language>
    <item>
      <title>🚀 🤖 Let's Retrieve Data and Talk: A Full-stack RAG App with Create-Llama and LlamaIndex.TS</title>
      <dc:creator>Tim Pap</dc:creator>
      <pubDate>Mon, 22 Jan 2024 21:13:00 +0000</pubDate>
      <link>https://dev.to/blackpr/lets-retrieve-data-and-talk-a-full-stack-rag-app-with-create-llama-and-llamaindexts-4hck</link>
      <guid>https://dev.to/blackpr/lets-retrieve-data-and-talk-a-full-stack-rag-app-with-create-llama-and-llamaindexts-4hck</guid>
      <description>&lt;p&gt;🦙 LlamaIndex is an open-source data framework that allows developers to build applications powered by large language models like GPT-3 using their own custom data. &lt;/p&gt;

&lt;p&gt;🦾 The &lt;code&gt;create-llama&lt;/code&gt; CLI tool makes it easy to scaffold a full LlamaIndex app with just one command. It sets up a &lt;code&gt;Next.js&lt;/code&gt; frontend, choice of &lt;code&gt;Express, Node or Python&lt;/code&gt; backends, data ingestion and indexing, and LLM integration out of the box so you can start building quickly. With &lt;code&gt;LlamaIndex&lt;/code&gt; and &lt;code&gt;create-llama&lt;/code&gt;, you can take advantage of powerful LLMs while keeping your data private and customizing the models to your specific domain. I'm excited to start experimenting with building conversational apps enhanced by LlamaIndex's data retrieval capabilities!&lt;/p&gt;

&lt;p&gt;In this hands-on tutorial, we’ll use create-llama to scaffold a custom search assistant app. I’ll show you how I set up data ingestion pipelines, indexing, storage all using LlamaIndex’s TypeScript library.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;The easiest way to leverage &lt;code&gt;create-llama&lt;/code&gt; is by invoking its interactive mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;npx&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;llama&lt;/span&gt;&lt;span class="nd"&gt;@latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;create-llama&lt;/code&gt; runs, it will prompt you to name your project and set additional configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ What is your project named? … llamaindex-ts-first-steps
✔ Which template would you like to use? › Chat with streaming
✔ Which framework would you like to use? › NextJS
✔ Which UI would you like to use? › Just HTML
✔ Which model would you like to use? › gpt-3.5-turbo
✔ Which data source would you like to use? › Use an example PDF
✔ Would you like to use a vector database? › No, just store the data in the file system
✔ Please provide your OpenAI API key (leave blank to skip): #### Add your OpenAI key here
✔ Would you like to use ESLint? … No / Yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running the Example App
&lt;/h2&gt;

&lt;p&gt;Navigate into the &lt;code&gt;llamaindex-ts-first-steps&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd llamaindex-ts-first-steps

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, open the project in your editor - for example using VS Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code .

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To provide custom data for LlamaIndex to ingest, first create a text file named &lt;code&gt;my-file.txt&lt;/code&gt; within the &lt;code&gt;data/&lt;/code&gt; directory. Add whatever content you would like &lt;code&gt;LlamaIndex&lt;/code&gt; to have access to - this can be any freeform text.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hey my name is Tim
the secret number is 12

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run generate

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This preprocesses the documents and creates vector embeddings to enable semantic search.&lt;/p&gt;

&lt;p&gt;With data indexed, start the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now ask natural language questions about your documents!&lt;/p&gt;

&lt;p&gt;Note: Re-run &lt;code&gt;generate&lt;/code&gt; whenever new data is added to update the index.&lt;/p&gt;

&lt;p&gt;This application utilizes Vercel's AI SDK for the text generation components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Indexing Logic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main indexing logic resides in &lt;code&gt;generate.mjs&lt;/code&gt;. Let's examine how it works&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;loadData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;directoryPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;STORAGE_DIR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromDocuments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;storageContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;serviceContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;SimpleDirectoryReader&lt;/code&gt; provides a straightforward method to ingest local files into LlamaIndex. While more robust Readers from LlamaHub may be better suited for production systems, the &lt;code&gt;SimpleDirectoryReader&lt;/code&gt; offers a simple on-ramp to start loading data and experimenting with LlamaIndex.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;Document&lt;/code&gt; encapsulates a data source such as a PDF, API response, or database query result. Within LlamaIndex, data is divided into discrete &lt;code&gt;Node&lt;/code&gt; objects representing atomic semantic units. For example, a node could contain a paragraph of text or table from a document.&lt;/p&gt;

&lt;p&gt;Nodes maintain metadata linking them to their parent Document and any related Nodes. This connectivity between nodes and back to source documents creates a rich knowledge graph for targeted information retrieval.&lt;/p&gt;

&lt;p&gt;Vector stores play a vital role in retrieval-augmented generation by efficiently indexing vector embeddings. You'll leverage vector stores, whether directly or behind the scenes, in most LlamaIndex applications.&lt;/p&gt;

&lt;p&gt;A vector store ingests Node objects, analyzing the data to construct an optimized search index.&lt;/p&gt;

&lt;p&gt;The most straightforward approach for indexing data utilizes the vector store's &lt;code&gt;fromDocuments&lt;/code&gt; method. Simply pass in your documents and the vector store handles building the index&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Indexes and Embeddings&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After loading data, LlamaIndex facilitates indexing to optimize retrieval. Indexing transforms the raw content into vector embeddings - numeric representations of semantic meaning. These embeddings get stored in a vector database engine specialized for efficient similarity searches.&lt;/p&gt;

&lt;p&gt;The index may also track extra metadata like relationships between nodes. This supplementary information bolsters the relevance of fetched content.&lt;/p&gt;

&lt;p&gt;To locate relevant context for a query, LlamaIndex first converts the search terms into an embedding vector. It then identifies stored nodes with the closest matching embeddings to the query vector. This vector similarity search allows retrieving the most contextually related data points for any natural language query.&lt;/p&gt;

&lt;p&gt;The chat functionality is enabled by &lt;code&gt;createChatEngine&lt;/code&gt; defined in &lt;code&gt;app/api/chat/engine/index.ts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This exports the &lt;code&gt;createChatEngine&lt;/code&gt; factory function which constructs a &lt;code&gt;ChatEngine&lt;/code&gt; instance for conducting conversational flows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createChatEngine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LLM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getDataSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;retriever&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asRetriever&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;retriever&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;similarityTopK&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ContextChatEngine&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;chatModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;retriever&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ContextChatEngine&lt;/code&gt; enables conversational interactions powered by retrievals over indexed data.&lt;/p&gt;

&lt;p&gt;Its chat loop works as follows for each user message:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Retrieve the most relevant text passages from the index based on the message text.&lt;/li&gt;
&lt;li&gt;Incorporate those texts as context when formulating the system prompt.&lt;/li&gt;
&lt;li&gt;Generate a response to the user message using the context-aware prompt.&lt;/li&gt;
&lt;li&gt;Return the reply to the user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This simplicity makes &lt;code&gt;ContextChatEngine&lt;/code&gt; suitable for queries directly related to the knowledge base and basic conversational flows. By basing each response on contextual retrievals, it can directly leverage the indexed data.&lt;/p&gt;

&lt;p&gt;The full source code for this application is available at:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/blackpr/llamaindex-ts-first-steps"&gt;https://github.com/blackpr/llamaindex-ts-first-steps&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Feel free to reference the repository to see the complete working example of initializing LlamaIndex, configuring indexing and retrieval, and enabling conversational interactions.&lt;/p&gt;

&lt;p&gt;It demonstrates an end-to-end pipeline from ingesting custom data through to asking questions via a chat interface powered by vector similarity search.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>typescript</category>
      <category>openai</category>
      <category>llamaindex</category>
    </item>
    <item>
      <title>🤖📚 Take Your First Steps into RAG: Building a LlamaIndex Retrieval Application using OpenAI’s gpt-3.5-turbo</title>
      <dc:creator>Tim Pap</dc:creator>
      <pubDate>Sat, 20 Jan 2024 20:10:00 +0000</pubDate>
      <link>https://dev.to/blackpr/take-your-first-steps-into-rag-building-a-llamaindex-retrieval-application-using-openais-gpt-35-turbo-4ha0</link>
      <guid>https://dev.to/blackpr/take-your-first-steps-into-rag-building-a-llamaindex-retrieval-application-using-openais-gpt-35-turbo-4ha0</guid>
      <description>&lt;p&gt;🔗 Retrieval-Augmented Generation (RAG) combines the knowledge look up and retrieval capacities of search engines with the fluent language generation capabilities of large language models.&lt;/p&gt;

&lt;p&gt;🦙 LlamaIndex is an open-source data framework that enables developers to ingest, structure, and query data for use in large language model (LLM) applications. It facilitates a Retrieval Augmented Generation (RAG) approach, where relevant knowledge is retrieved from data sources before being fed to language models to generate high-quality responses.&lt;/p&gt;

&lt;p&gt;LlamaIndex handles the complexity of connecting to data, building indexes and retrieval pipelines, and integrating LLMs. Whether your data lives in APIs, databases, or documents, LlamaIndex makes it seamless to leverage for AI applications. With intuitive APIs for querying knowledge and conversing with chatbots to customizable search functionality, LlamaIndex lets you focus on creating performant, tailored LLM experiences.&lt;/p&gt;

&lt;p&gt;In this post, I'll provide a step-by-step tutorial for building your first RAG application with LlamaIndex and OpenAI’s gpt-3.5-turbo&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you already have a Python environment configured, you can skip the next section and start building your LlamaIndex application directly.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Alternatively, if you have Docker installed, you can leverage a VS Code development container for a ready-made environment without any additional setup.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Otherwise, the following section will guide you through installing Python and setting up a virtual environment to run LlamaIndex smoothly. The choice depends on your existing tools and preference.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  (optional) setup development environment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;open wsl&lt;/li&gt;
&lt;li&gt;install build essential &lt;code&gt;sudo apt-get install build-essential&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;install deps &lt;code&gt;sudo apt-get install build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;install pyenv &lt;code&gt;curl [https://pyenv.run](https://pyenv.run/) | bash&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;install python &lt;code&gt;pyenv install 3&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;install pipx &lt;code&gt;sudo apt install pipx&lt;/code&gt;, &lt;code&gt;pipx ensurepath&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;install poetry &lt;code&gt;pipx install poetry&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;poetry config virtualenvs.in-project true&lt;/li&gt;
&lt;li&gt;pyenv local 3&lt;/li&gt;
&lt;li&gt;poetry new rag, cd rag&lt;/li&gt;
&lt;li&gt;poetry shell. If you want to deactivate use &lt;code&gt;deactivate&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;LlamaIndex utilizes OpenAI's &lt;code&gt;gpt-3.5-turbo&lt;/code&gt; model for text generation and &lt;code&gt;text-embedding-ada-002&lt;/code&gt; for retrieval operations by default. To leverage these models, you need an OpenAI API key configured as the OPENAI_API_KEY environment variable.&lt;/p&gt;

&lt;p&gt;To obtain an API key:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log into your OpenAI account&lt;/li&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/account/api-keys"&gt;Create a new API key&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This unique key authorizes LlamaIndex to call OpenAI models on your account's behalf.&lt;/p&gt;

&lt;h2&gt;
  
  
  install libraries
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;poetry add llama-index&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;poetry add python-dotenv&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;open app in vs code &lt;code&gt;code .&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;add a &lt;code&gt;.gitignore&lt;/code&gt; file with the following content: &lt;a href="https://www.toptal.com/developers/gitignore/api/python"&gt;https://www.toptal.com/developers/gitignore/api/python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;create a .env file and add:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OPENAI_API_KEY=ADD_YOUR_KEY_HERE

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To provide custom data for LlamaIndex to ingest, first create a text file named &lt;code&gt;my-file.txt&lt;/code&gt; within the &lt;code&gt;rag/data&lt;/code&gt; directory. Add whatever content you would like LlamaIndex to have access to - this can be any freeform text.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hey my name is Tim
the secret number is 12

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now LlamaIndex can ingest this data file and allow querying over the content using natural language&lt;/p&gt;

&lt;h2&gt;
  
  
  Application
&lt;/h2&gt;

&lt;p&gt;To build your LlamaIndex application, first create a Python file called &lt;code&gt;app.py&lt;/code&gt; in the &lt;code&gt;rag/&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;app.py&lt;/code&gt; will hold the code powering your application. Next we'll start adding Python logic to initialize LlamaIndex, load data, define queries, and ultimately enable asking questions over your custom knowledge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./rag/data/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;query_engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_query_engine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;query_engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is the secret number?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;run the app &lt;code&gt;python rag/app.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By calling &lt;code&gt;load_dotenv()&lt;/code&gt;, we populate the environment variables for the current Python process from the &lt;code&gt;.env&lt;/code&gt; file. This allows us to store configuration, credentials, and other sensitive information in &lt;code&gt;.env&lt;/code&gt; rather than hard-coding them in our application code. The &lt;code&gt;.env&lt;/code&gt; file is gitignored by default so it won't be committed into source control.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;documents = SimpleDirectoryReader("./rag/data/").load_data()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;SimpleDirectoryReader&lt;/code&gt; provides a straightforward method to ingest local files into LlamaIndex. While more robust Readers from LlamaHub may be better suited for production systems, the &lt;code&gt;SimpleDirectoryReader&lt;/code&gt; offers a simple on-ramp to start loading data and experimenting with LlamaIndex.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;Document&lt;/code&gt; encapsulates a data source such as a PDF, API response, or database query result. Within LlamaIndex, data is divided into discrete &lt;code&gt;Node&lt;/code&gt; objects representing atomic semantic units. For example, a node could contain a paragraph of text or table from a document.&lt;/p&gt;

&lt;p&gt;Nodes maintain metadata linking them to their parent Document and any related Nodes. This connectivity between nodes and back to source documents creates a rich knowledge graph for targeted information retrieval.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;index = VectorStoreIndex.from_documents(documents)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Vector stores play a vital role in retrieval-augmented generation by efficiently indexing vector embeddings. You'll leverage vector stores, whether directly or behind the scenes, in most LlamaIndex applications.&lt;/p&gt;

&lt;p&gt;A vector store ingests Node objects, analyzing the data to construct an optimized search index.&lt;/p&gt;

&lt;p&gt;The most straightforward approach for indexing data utilizes the vector store's &lt;code&gt;from_documents&lt;/code&gt; method. Simply pass in your documents and the vector store handles building the index&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Indexes and Embeddings&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After loading data, LlamaIndex facilitates indexing to optimize retrieval. Indexing transforms the raw content into vector embeddings - numeric representations of semantic meaning. These embeddings get stored in a vector database engine specialized for efficient similarity searches.&lt;/p&gt;

&lt;p&gt;The index may also track extra metadata like relationships between nodes. This supplementary information bolsters the relevance of fetched content.&lt;/p&gt;

&lt;p&gt;To locate relevant context for a query, LlamaIndex first converts the search terms into an embedding vector. It then identifies stored nodes with the closest matching embeddings to the query vector. This vector similarity search allows retrieving the most contextually related data points for any natural language query.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;query_engine = index.as_query_engine()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A query engine enables querying a knowledge base through natural language. It takes a question expressed in plain text, retrieves the most relevant supporting content from the indexed data, supplies both the question and contextual information to a language model, and returns the model's response. This end-to-end pipeline allows users to extract information from data by simply asking questions in everyday language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple storage for embedings
&lt;/h2&gt;

&lt;p&gt;The vector embeddings representing your indexed data reside in memory by default. You can optimize performance by persisting these embeddings to local storage instead. Add this line to save the index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;storage_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The data will persist to the "storage" directory by default. To customize this, pass the desired location to the &lt;code&gt;persist_dir&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;To leverage a persisted index, check if one exists and load it. If not found, generate a new index before persisting&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os.path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;StorageContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;load_index_from_storage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# check if storage already exists
&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./storage&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# load the documents and create the index
&lt;/span&gt;    &lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# store it for later
&lt;/span&gt;    &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;storage_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;persist_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# load the existing index
&lt;/span&gt;    &lt;span class="n"&gt;storage_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StorageContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_defaults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;persist_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_index_from_storage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;storage_context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Inspecting Activity with Logging&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To understand everything occurring within your LlamaIndex application, configure logging to output internal events and queries. At the start of &lt;code&gt;starter.py&lt;/code&gt;, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basicConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DEBUG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;addHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StreamHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you encounter rate limiting while sending requests to OpenAI, you may be using a free API key instead of a paid plan. Rate limits apply to OpenAI's free tier. Also verify you have configured LlamaIndex with a valid OpenAI API key associated with a paid subscription  &lt;a href="https://platform.openai.com/account/billing/overview"&gt;https://platform.openai.com/account/billing/overview&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final application
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dotenv&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_dotenv&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os.path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;llama_index&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;StorageContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;load_index_from_storage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;load_dotenv&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# check if storage already exists
&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./rag/storage&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# load the documents and create the index
&lt;/span&gt;    &lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./rag/data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# store it for later
&lt;/span&gt;    &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;storage_context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;persist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;persist_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# load the existing index
&lt;/span&gt;    &lt;span class="n"&gt;storage_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StorageContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_defaults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;persist_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;PERSIST_DIR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_index_from_storage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;storage_context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SimpleDirectoryReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./rag/data/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;load_data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;VectorStoreIndex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;query_engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_query_engine&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;query_engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is the secret number?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  application tree
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;README&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;md&lt;/span&gt;
&lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;poetry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lock&lt;/span&gt;
&lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;pyproject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toml&lt;/span&gt;
&lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;rag&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;py&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;py&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;txt&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;   &lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;      &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;default__vector_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;      &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;docstore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;      &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;graph_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;      &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="nx"&gt;image__vector_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;      &lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="nx"&gt;index_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;
&lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="nx"&gt;tests&lt;/span&gt;
    &lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="nx"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full source code for this LlamaIndex example is located at:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/blackpr/llamaindex-rag-first-steps"&gt;https://github.com/blackpr/llamaindex-rag-first-steps&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This repository contains a complete application showcasing core LlamaIndex concepts including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loading custom documents&lt;/li&gt;
&lt;li&gt;Indexing via vector embeddings&lt;/li&gt;
&lt;li&gt;Defining a query engine&lt;/li&gt;
&lt;li&gt;Enabling querying&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>llamaindex</category>
      <category>llm</category>
      <category>rag</category>
      <category>python</category>
    </item>
    <item>
      <title>🐥 Demystifying the AI Jargon: A Beginner's Guide</title>
      <dc:creator>Tim Pap</dc:creator>
      <pubDate>Fri, 19 Jan 2024 23:05:54 +0000</pubDate>
      <link>https://dev.to/blackpr/demystifying-the-ai-jargon-a-beginners-guide-57oh</link>
      <guid>https://dev.to/blackpr/demystifying-the-ai-jargon-a-beginners-guide-57oh</guid>
      <description>&lt;p&gt;As AI technology advances rapidly, the terminology can be confusing. Here's a quick guide to some of the key AI jargon I came across recently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Models&lt;/strong&gt; - Large data sets that are trained on lots of data to understand prompts and questions. They vary in speed, price, size and quality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLMs (Large Language Models)&lt;/strong&gt; - Models specifically focused on understanding and generating natural language text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Providers&lt;/strong&gt; - Services like OpenAI, Anthropic, Replicate, Cohere, Amazon Bedrock that provide easy APIs to test and run AI models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hugging Face&lt;/strong&gt; - A hub for open source machine learning models anyone can use. Has hundreds of models for text, image and speech tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tokens&lt;/strong&gt; - The way models count length of text prompts sent to them. More tokens used = more expensive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embeddings&lt;/strong&gt; - Turning text into mathematical representations models can match for similarity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Temperature&lt;/strong&gt; - Setting that affects how creative/random a text generation model will be.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Top percentile (Top p)&lt;/strong&gt; - Similar setting that tweaks how deterministically the same a model's outputs will be.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine tuning&lt;/strong&gt; - Customizing a model by training it further on your own specialized data set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompts&lt;/strong&gt; - What you send the model to prime it to generate a useful response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;VectorDB&lt;/strong&gt; - Database for searching embeddings to find similar documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streaming&lt;/strong&gt; - Displaying a model's output as it generates, rather than waiting for it to finish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evals&lt;/strong&gt; - Test suites to evaluate model quality over time.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
