<?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: Julia Zhou</title>
    <description>The latest articles on DEV Community by Julia Zhou (@jjuliazhou).</description>
    <link>https://dev.to/jjuliazhou</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%2F1768232%2F1e58f87b-0a12-46be-b502-95b8ed0778d4.jpeg</url>
      <title>DEV Community: Julia Zhou</title>
      <link>https://dev.to/jjuliazhou</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jjuliazhou"/>
    <language>en</language>
    <item>
      <title>How I Learned Generative AI in Two Weeks (and You Can Too): Part 3 - Prompts &amp; Models</title>
      <dc:creator>Julia Zhou</dc:creator>
      <pubDate>Wed, 14 May 2025 12:05:49 +0000</pubDate>
      <link>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-3-prompts-models-dd7</link>
      <guid>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-3-prompts-models-dd7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;It's been a few months since the last iteration in this series, but new year, more LLMWare Fast Start to RAG examples! In the previous articles, we covered creating libraries and transforming this information into embeddings. Now that we have done the heavy lifting, so to speak, we are ready to begin writing prompts and getting responses. This will be the focus of today's article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra resources
&lt;/h2&gt;

&lt;p&gt;A few notes before we start! In case you missed them, I will link the previous articles in this series. This example will build upon &lt;a href="https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-1-libraries-215h"&gt;example 1&lt;/a&gt; and &lt;a href="https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-2-embeddings-2ppc"&gt;example 2&lt;/a&gt; and will assume prior understanding of these topics.  &lt;/p&gt;

&lt;p&gt;For visual learners, here is a video that works through example 3. Feel free to watch the video before following the steps in this article. Also, here is a Python Notebook that breaks down this example's code alongside the output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware/blob/cbed79d0c185ab2626a2c53fe20c262734d4e7f5/examples/Notebooks/fast_start_examples/example_3_prompts_and_models_version_1.ipynb" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;Notebook for example 3: prompts and models&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/swiu4oBVfbA"&gt;
  &lt;/iframe&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;

&lt;p&gt;Now, we are ready to take a look at the example's code! This LLMWare Faststart example can be run in the same way as the previous ones, but instructions can be found in our &lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/README.md" rel="noopener noreferrer"&gt;README file&lt;/a&gt; if needed. Example 3 is directly copy-paste ready!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/rag/example-3-prompts_and_models.py" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;Code for example 3: prompts and models&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1 - What are prompts?
&lt;/h2&gt;

&lt;p&gt;While working through this example, I read a MIT Sloan Teaching &amp;amp; Learning Technologies article titled "Effective Prompts for AI: The Essentials". The entire article is definitely worth a read, but I wanted to share a quote that summarizes what &lt;strong&gt;prompts&lt;/strong&gt; are in the AI world. To read the whole article, check out &lt;a href="https://mitsloanedtech.mit.edu/ai/basics/effective-prompts/" rel="noopener noreferrer"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Prompts are your input into the AI system to obtain specific results. In other words, prompts are conversation starters: what and how you tell something to the AI for it to respond in a way that generates useful responses for you ... It’s like having a conversation with another person, only in this case the conversation is text-based, and your interlocutor is AI.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, the prompt you provide determines how the AI responds. To create the most effective prompts, use specific wording and consider providing context, including in the form of additional text paragraphs. &lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2 - Which model should I use?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;model catalog&lt;/strong&gt; is a list of all the models LLMWare has registered. Like a dictionary, each model in the catalog is automatically linked with configuration data and implementation classes for easy use. The goal of this catalog is exactly this: ease of use. When provided with only the model's name, if it is present in the catalog, it should be able to run without any other information. &lt;/p&gt;

&lt;p&gt;The following lines of code provide lists of models included in the catalog. More information about the capabilities and performances of these models is included as comments in the Python code file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#   all generative models
llm_models = ModelCatalog().list_generative_models()

#   if you only want to see the local models
llm_local_models = ModelCatalog().list_generative_local_models()

#   to see only the open source models
llm_open_source_models = ModelCatalog().list_open_source_models()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following line of code selections a model by index. To choose a different model, simply replace the index value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model_name = gguf_generative_models[0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, we can choose a specific model by name. For those interested in exploring RAG through &lt;strong&gt;OpenAI&lt;/strong&gt;, all of the LLMWare examples are ready to use. In this particular example, uncomment the following lines and insert the necessary information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#   model_name = "gpt-4"
#   os.environ["USER_MANAGED_OPENAI_API_KEY"] = "&amp;lt;insert-your-openai-key&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, these examples also encourage the use of &lt;strong&gt;open-source&lt;/strong&gt;, models. These are locally deployed models that produce top-notch quality right on your laptop. The developments in regards to open-source over the past few years cannot be overstated. The future of AI is here in these small, specialized models optimized for a specific purpose. &lt;/p&gt;

&lt;p&gt;For example, the LLMWare &lt;strong&gt;Bling 1B&lt;/strong&gt; is a small, fast model fine-tuned to RAG that runs on your local machine. &lt;/p&gt;

&lt;p&gt;To learn more about LLMWare's &lt;strong&gt;Bling&lt;/strong&gt; and &lt;strong&gt;Dragon&lt;/strong&gt; models, consider visiting their &lt;a href="https://huggingface.co/models?other=llmware-rag" rel="noopener noreferrer"&gt;Hugging Face&lt;/a&gt; page!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbjR3NmsxcnR0am1jN3BxNzdoM3hqMGF1ZnU1cTZmOXF5amIxOGU1cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FHzPtbOKyBoBFsK4hyc%2Fgiphy.gif" class="article-body-image-wrapper"&gt;&lt;img width="50%" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbjR3NmsxcnR0am1jN3BxNzdoM3hqMGF1ZnU1cTZmOXF5amIxOGU1cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FHzPtbOKyBoBFsK4hyc%2Fgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 3 - Main example script
&lt;/h2&gt;

&lt;p&gt;Now, we can head to the main example script, &lt;code&gt;fast_start_prompting&lt;/code&gt;. We will follow four general steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pull sample questions&lt;/li&gt;
&lt;li&gt;Load the model&lt;/li&gt;
&lt;li&gt;Prompt the model&lt;/li&gt;
&lt;li&gt;Get results&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The sample questions (each with query, answer, and context) are found at the top of the Python file. They cover a variety of fields with a little extra emphasis on business, financial, and legal applications. However, it is always encouraged to change these questions or add to them to better suit your interests and needs! All of the questions will be pulled in through the &lt;code&gt;test_list&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To use the model, we create a &lt;strong&gt;prompt object&lt;/strong&gt;. Prompts are what we do to a model: we use them when we have a question in context and want to pass it to the model to receive a response. This line of code loads the model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompter = Prompt().load_model(model_name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first time we load the model, it needs to "move" from the LLMWare Hugging Face repository to your local system, which can take a few minutes. However, once that is complete, all the work the model does will happen locally on your computer!&lt;/p&gt;

&lt;p&gt;Now, we loop through our list of questions. The key method &lt;code&gt;.prompt_main&lt;/code&gt; in the prompt class causes inference on the model. The  mandatory parameter for this method is the query. Optionally, &lt;code&gt;context&lt;/code&gt;, &lt;code&gt;prompt_name&lt;/code&gt;, and &lt;code&gt;temperature&lt;/code&gt; can also be passed in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output = prompter.prompt_main(entries["query"],
                                      context=entries["context"],
                                      prompt_name="default_with_context",
                                      temperature=0.30)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;context&lt;/strong&gt; is a passage of information we want the model to read before answering the question. This allows us to explain what we want the model to consider in its answer, and it will answer based on the passage. &lt;/p&gt;

&lt;p&gt;The prompt catalog supports a range of &lt;strong&gt;prompt names&lt;/strong&gt;. The code uses &lt;code&gt;default_with_context&lt;/code&gt;, which tells the model to read the provided context and answer the question. &lt;/p&gt;

&lt;p&gt;Adjusting the temperature will change the results of the query. In general, a lower temperature will yield more factual responses directly relating to the context. Higher temperatures are more appropriate when we require a more creative response from the model. For RAG based applications, we set the temperature comparatively low to yield the the most consistency and quality. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;output&lt;/code&gt; is a dictionary with two keys: &lt;code&gt;llm_response&lt;/code&gt; and &lt;code&gt;usage&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZWZ3cjk3ejJjZnd4Zzc1OGpsYTR2em5za3dyamY3cjluc2gxOHN5YyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F8bE0EERrvXkq5S9BCa%2Fgiphy.gif" class="article-body-image-wrapper"&gt;&lt;img width="50%" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZWZ3cjk3ejJjZnd4Zzc1OGpsYTR2em5za3dyamY3cjluc2gxOHN5YyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F8bE0EERrvXkq5S9BCa%2Fgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 4 - Running the model
&lt;/h2&gt;

&lt;p&gt;Once you run the code, you will see the queries being iterated through and printed out. Each of these print-outs has an &lt;strong&gt;LLM Response&lt;/strong&gt; and a &lt;strong&gt;Gold Answer&lt;/strong&gt;. The &lt;strong&gt;LLM Response&lt;/strong&gt; is the model's response while the &lt;strong&gt;Gold Answer&lt;/strong&gt; is an "answer key" we created that the model does not see. This allows us to quickly compare the two answers and check for the model's accuracy. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;LLM Usage&lt;/strong&gt; line provides additional information about how the model formulated its response. In particular, you can see the "processing_time" for each query, which showcases the model's speed. Of course, the computer you run the models on will also cause speed to vary - the amount of RAM available is especially impactful for efficiency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Query: What is the total amount of the invoice?
LLM Response: 22,500.00
Gold Answer: $22,500.00
LLM Usage: {'input': 209, 'output': 9, 'total': 218, 'metric': 'tokens', 'processing_time': 2.0669240951538086}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above output is a sample response. The LLM correctly responded to the query since its response matches the gold answer. &lt;/p&gt;

&lt;p&gt;We have successfully received answers to our questions! Congrats on reaching the end of this example. Here is a link to the full working code!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware/blob/cbed79d0c185ab2626a2c53fe20c262734d4e7f5/fast_start/rag/example-3-prompts_and_models.py" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;FULL CODE&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 5 - Further exploration
&lt;/h2&gt;

&lt;p&gt;To experiment more with this example, consider changing out the &lt;code&gt;model_name&lt;/code&gt; for other models! How does the LLMWare Bling model compare to the LLMWare Dragon model or OpenAI? Will these models generate the same response when provided the same queries and context? Once you try out these questions, let us know what you think!&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this example about prompts and models! The next example will be about &lt;strong&gt;RAG text query&lt;/strong&gt;, stay tuned for the article. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZHZnd2pleXYzeHYzMTdpeDZtdnoxbWp0c2h2YmVhNm0ycXUzaWU2byZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FAdX5dZF7LjigSMZZMm%2Fgiphy.gif" class="article-body-image-wrapper"&gt;&lt;img width="50%" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZHZnd2pleXYzeHYzMTdpeDZtdnoxbWp0c2h2YmVhNm0ycXUzaWU2byZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FAdX5dZF7LjigSMZZMm%2Fgiphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  To see more ...
&lt;/h2&gt;

&lt;p&gt;Please join our LLMWare community on discord to learn more about RAG / LLMs and share your thoughts! &lt;a href="https://discord.gg/5mx42AGbHm" rel="noopener noreferrer"&gt;https://discord.gg/5mx42AGbHm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;Visit LLMWare's Website&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;Explore LLMWare on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/free-vector/personal-computer-screen-with-old-software-windows_36102472.htm#fromView=image_search_similar&amp;amp;page=1&amp;amp;position=49&amp;amp;uuid=6524a515-1b2e-441e-8993-357233bf186d&amp;amp;query=cute+coding" rel="noopener noreferrer"&gt;Image from Freepik&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ai</category>
      <category>learning</category>
      <category>python</category>
    </item>
    <item>
      <title>How I Learned Generative AI in Two Weeks (and You Can Too): Part 2 - Embeddings</title>
      <dc:creator>Julia Zhou</dc:creator>
      <pubDate>Fri, 11 Oct 2024 11:41:08 +0000</pubDate>
      <link>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-2-embeddings-2ppc</link>
      <guid>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-2-embeddings-2ppc</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A few weeks ago, I shared my experience learning about Generative AI Libraries through LLMWare's Fast Start to RAG example 1. Today, I will continue this series by taking you through example 2. This is personally one of my favorite "lessons" in this LLMWare series, so I hope you will find it thought-provoking as well! This example will focus on &lt;strong&gt;embeddings and vectors&lt;/strong&gt;. Let us start by exploring what exactly these terms mean! &lt;/p&gt;

&lt;h2&gt;
  
  
  How do embedding models work?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Embeddings models&lt;/strong&gt; are trained on large amounts of language tokens to either predict the next token or fill in missing tokens. In either case, these models learn how to represent language! They take in large chunks of text as input and processes it through tokenization (breaking down into smaller pieces), conversion into numbers, and various layers of transformations. These steps build a representation of the input text to help formulate the output: vectors. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vectors&lt;/strong&gt; are created when the input text is translated into the language through which the model sees the world. Geometrically speaking, they are n-dimensional shapes where "n" is the number of embedding dimensions (typically, n is 768). The dimensions are represented by n floats, usually ranging between 0 and 1 or -1 and 1. Converting the text to numbers allows the model to more easily compare the similarity of two texts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/i1xNYj8xdUmR7z3CrH/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/i1xNYj8xdUmR7z3CrH/giphy.gif" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try thinking back to high school geometry! You might remember that two points (or shapes) that are close to each other are considered more similar to one another than two far away points. This process is exactly what the model performs to compare texts and is known as a &lt;strong&gt;semantic search&lt;/strong&gt;. Once a query is converted to a vector, that vector is compared to all the other vectors in the database. The ones that are the most similar are returned. &lt;/p&gt;

&lt;p&gt;Now, we are ready to take a look at the example's code! This LLMWare Faststart example can be run in the same way as example 1, but instructions can be found in our &lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/README.md" rel="noopener noreferrer"&gt;README file&lt;/a&gt; if needed. Example 2 is directly copy-paste ready!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/rag/example-2-build_embeddings.py" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Example 2: Embeddings&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra resources
&lt;/h2&gt;

&lt;p&gt;In case you missed it, I will link my previous article in this series since this example will continue building on the foundation we built in example 1. The same process for creating libraries is utilized in example 2, so I will skip over it here. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-1-libraries-215h" class="ltag_cta ltag_cta--branded"&gt;Article - Example 1: Libraries&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;For visual learners, here is a video that works through example 2. Feel free to watch the video before following the steps in this article. Also, here is a Python Notebook that breaks down this example's code alongside the output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware/blob/main/examples/Notebooks/fast_start_examples/example_2_build_embeddings_version_1.ipynb" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Example 2 Notebook&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2xDefZ4oBOM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1 - Creating embeddings &amp;amp; storing vectors
&lt;/h2&gt;

&lt;p&gt;As mentioned above, we will not cover the library building process in this article and will move directly into embedding models. For this demo, we will use the "mini-lm-sbert" model, which is efficient and is included in the default LLMWare package. Feel free to experiment with different models, including the OpenAI Text Embedding Ada!&lt;/p&gt;

&lt;p&gt;Recall that in example 1, we not only created our library but also added our documents into a database. This database will make it extremely convenient to access test chunks that we can give to the embedding model. &lt;/p&gt;

&lt;p&gt;Once the library has been created, let us focus our attention on the most important line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;library.install_new_embedding(embedding_model_name=embedding_model, vector_db=vector_db,batch_size=100)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line calls the &lt;code&gt;install_new_embedding&lt;/code&gt; function and passes in the embedding model and vector names as parameters. The final parameter &lt;code&gt;batch_size&lt;/code&gt; determines how many text chunks will be processed at a time. Considerations like efficiency, memory, model capability, and database size all factor into choosing the most appropriate batch size. &lt;/p&gt;

&lt;p&gt;We can confirm that our embedding creation and vector storage was a success!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;update = Status().get_embedding_status(library_name, embedding_model)
print("update: Embeddings Complete - Status() check at end of embedding - ", update)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 2 - Queries
&lt;/h2&gt;

&lt;p&gt;Now that we have the vector database, we can begin running queries on it! We will begin by creating a very simple query before passing it into the library and running a &lt;strong&gt;semantic query model&lt;/strong&gt; on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sample_query = "incentive compensation"
query_results = Query(library).semantic_query(sample_query, result_count=20)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use the following portion of code to iterate through the query results to view them, and we will especially look at the &lt;code&gt;distance&lt;/code&gt; parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i, entries in enumerate(query_results):
  text = entries["text"]
  document_source = entries["file_source"]
  page_num = entries["page_num"]
  vector_distance = entries["distance"]

  if len(text) &amp;gt; 125: text = text[0:125] + " ... "

  print("\nupdate: query results - {} - document - {} - page num - {} distance - {} ".format(i, document_source, page_num, vector_distance))

  print("update: text sample - ", text)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us run the example to see the results in action!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/nFLW7PNGgN3lI68rdv/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/nFLW7PNGgN3lI68rdv/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 3 - The results
&lt;/h2&gt;

&lt;p&gt;Through the output, we can see that at first, we have no embeddings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;embedding record - before embedding  [{'embedding_status': 'no', 'embedding_model': 'none', 'embedding_db': 'none', 'embedded_blocks': 0, 'embedding_dims': 0, 'time_stamp': 'NA'}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, there are a series of outputs showing that we are creating embeddings in batches of 100, as expected. By the end, all of the text chunks will be converted to vectors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;update: Embeddings Complete - Status() check at end of embedding -  [{'_id': 2, 'key': 'example2_library_embedding_mini-lm-sbert', 'summary': '2211 of 2211 blocks', 'start_time': '1717690179.087806', 'end_time': '1717690199.5373614', 'total': 2211, 'current': 2211, 'units': 'blocks'}]

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

&lt;/div&gt;



&lt;p&gt;Now, we have arrived back at the query result for-loop mentioned above. Looking at the first result, we can see that one, among many, of the outputted metadata points is distance. This distance value can be considered the distance between the vector for our query ("incentive compensation") and the vector for this sample block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;update: query results - 0 - document - Artemis Poseidon EXECUTIVE EMPLOYMENT AGREEMENT.pdf - page num - 4 distance - 0.24837934970855713 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The query results are sorted from lowest to highest distance - that is, from most to least similar. For comparison, we can see that the tenth query result returned has a higher distance than the first one!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;update: query results - 10 - document - Eileithyia EXECUTIVE EMPLOYMENT AGREEMENT.pdf - page num - 3 distance - 0.27305811643600464 
update: text sample -  in Employer's annual cash incentive   bonus plan (the “Plan”), based on the same terms and conditions as in existence for oth ... 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Part 4 - Further exploration
&lt;/h2&gt;

&lt;p&gt;For this example, we used the "faiss" vector database, but I encourage you to experiment with others as well. &lt;/p&gt;

&lt;p&gt;Similarly, try using different embedding models to see how their  characteristics might be optimized for certain types of inputs! A series of examples involving embeddings can be found on the LLMWare Github page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware%20ai/llmware/tree/main/examples/Embedding" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Embeddings Examples&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this example about embeddings and vectors! The next example will be about &lt;strong&gt;prompts and models&lt;/strong&gt;, stay tuned for the article. &lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;h2&gt;
  
  
  To see more ...
&lt;/h2&gt;

&lt;p&gt;Please join our LLMWare community on discord to learn more about RAG and LLMs! &lt;a href="https://discord.gg/5mx42AGbHm" rel="noopener noreferrer"&gt;https://discord.gg/5mx42AGbHm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Visit LLMWare's Website&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Explore LLMWare on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/free-photo/view-adorable-3d-cat_45138549.htm#fromView=search&amp;amp;page=1&amp;amp;position=1&amp;amp;uuid=c7c3603a-a846-4ddf-8a71-b0346612cef6" rel="noopener noreferrer"&gt;Image from Freepik&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ai</category>
      <category>learning</category>
      <category>python</category>
    </item>
    <item>
      <title>How I Learned Generative AI in Two Weeks (and You Can Too): Part 1 - Libraries</title>
      <dc:creator>Julia Zhou</dc:creator>
      <pubDate>Thu, 12 Sep 2024 21:54:51 +0000</pubDate>
      <link>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-1-libraries-215h</link>
      <guid>https://dev.to/llmware/how-i-learned-generative-ai-in-two-weeks-and-you-can-too-part-1-libraries-215h</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;For reference, prior to this journey, I barely had more knowledge about AI than the average person. Sure, I fired off the occasional ChatGPT request for one task or another, but I was always more focused on coding than AI, having picked up Python and Java during quarantine.  &lt;/p&gt;

&lt;p&gt;Despite my initial skepticism at being able to successfully understand the examples, particularly in a short time frame, I found LLMWare's "Fast Start to RAG" series highly accessible. I will cover example one of the course in this article - hopefully it can help you as well! If you are interested in learning more about LLMWare, feel free to check out our &lt;a href="https://llmware.ai/" rel="noopener noreferrer"&gt;website&lt;/a&gt; as well as another &lt;a href="https://dev.to/llmware/become-a-rag-professional-in-2024-go-from-beginner-to-expert-41mg"&gt;DEV article&lt;/a&gt; outlining the Fast Start to RAG examples. &lt;/p&gt;

&lt;p&gt;To clarify, extensive knowledge of coding, specifically Python 3, is not necessarily a prerequisite for the examples that I used to get my start in AI and RAG. However, basic understanding is certainly helpful in comprehending content and parsing code. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/CuuSHzuc0O166MRfjt/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/CuuSHzuc0O166MRfjt/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;To run these examples, you will need to install the LLMWare package by running &lt;code&gt;pip3 install llmware&lt;/code&gt; in the command line. Further instructions can be found in our &lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/README.md" rel="noopener noreferrer"&gt;README file&lt;/a&gt;. Then, you will be able to run &lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/example-1-create_first_library.py" rel="noopener noreferrer"&gt;example 1&lt;/a&gt;, which is directly copy-paste ready.  &lt;/p&gt;

&lt;p&gt;I will also point out that the AI community tends to use acronyms (like AI itself!) and technical language extending beyond the scope of everyday conversation. The acronym "RAG" stands for Retrieval Augmented Generation, which enhances outputs of LLMs (Large Language Models) using external knowledge. In Example 1, we will be focusing on the first step in RAG - converting a pile of files into an AI ready knowledge base.    &lt;/p&gt;

&lt;h2&gt;
  
  
  Extra resources
&lt;/h2&gt;

&lt;p&gt;For visual learners, here is a video that works through example 1. Feel free to watch the video before following the steps in this article. Also, here is a Python Notebook that breaks down this example's code alongside the output: &lt;a href="https://github.com/llmware-ai/llmware/blob/main/examples/Notebooks/NoteBook_Examples/example_1_create_first_library.ipynb" rel="noopener noreferrer"&gt;Example 1 Notebook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/2xDefZ4oBOM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1 - Execution configuration
&lt;/h2&gt;

&lt;p&gt;By default, the active database being used is called "mongo", but we will select "sqlite" since it does not require a separate installation. &lt;/p&gt;

&lt;p&gt;Additionally, we can use different debug mode options to see more or less information as it is processed. We can set &lt;code&gt;debug_mode&lt;/code&gt; to 2 for more detailed outputs compared to 0, the default. &lt;/p&gt;

&lt;p&gt;For this example, sample data sets are imported through &lt;code&gt;from llmware.setup import Setup&lt;/code&gt; and are stored in &lt;code&gt;sample_folders&lt;/code&gt;. These sets include documents of different subject matters and sizes, but you will be able to replace them with your own data as well. We can choose a name for our library (go ahead and customize!) and select a folder from the samples before running the main script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LLMWareConfig().set_active_db("sqlite")

LLMWareConfig().set_config("debug_mode", 2)

sample_folders = ["Agreements", "Invoices", "UN-Resolutions-500", "SmallLibrary", "FinDocs", "AgreementsLarge"]
library_name = "example1_library"
selected_folder = sample_folders[0]     # e.g., "Agreements"

output = parsing_documents_into_library(library_name, selected_folder)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/ua7vVw9awZKWwLSYpW/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ua7vVw9awZKWwLSYpW/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 2 - Main body
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Now, we can create our library! This line of code will set up the database tables as well as supporting file repositories to store information about the library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;library = Library().create_new_library(library_name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Steps 2 and 3:&lt;/strong&gt; However, our library is still completely empty, so we need to fill it up. To do so, we will load in the LLMWare sample files and save them in &lt;code&gt;sample_files_path&lt;/code&gt;. If you are using your own data sets, you will need to point to a local folder path with your documents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sample_files_path = Setup().load_sample_files(over_write=False)
ingestion_folder_path = os.path.join(sample_files_path, sample_folder)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; While adding files to a library, LLMWare performs parsing, text chunking, and indexing in the sqlite database. It will automatically choose the correct parser based on a file's extension type. This parser will extract information to store in database text chunks. Although this may seem like a lot of steps, it all happens incredibly quickly behind the scenes!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parsing_output = library.add_files(ingestion_folder_path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; To check our progress, we can look at the &lt;code&gt;updated_library_card&lt;/code&gt;, which contains key metadata, counting data, and other important information. This &lt;code&gt;.get_library_card()&lt;/code&gt; method can be called at any time to retrieve information about your library,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;updated_library_card = library.get_library_card()
doc_count = updated_library_card["documents"]
block_count = updated_library_card["blocks"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Steps 6 and 7:&lt;/strong&gt; We can check the library's main folder structure, but the library is ready to start running queries! We will do this by instantiating a Query object and passing it to the library. This &lt;code&gt;test_query&lt;/code&gt; may need to be adjusted to best suit the data set. For this example, we chose the "Agreements" sample set, so we can use "base salary" as a "hello world"-esque query. &lt;/p&gt;

&lt;p&gt;Now, a text query is going to be run to look at every chunk of text to find the ones that contain "base salary" to return. The Query class contains many methods for different Query types. Today, we will use the simplest &lt;code&gt;text_query&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query_results = Query(library).text_query(test_query, result_count=10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can print out our results, giving us a look at the metadata and attributes of the individual text blocks we created!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i, result in enumerate(query_results):
        #   here are a few useful attributes
        text = result["text"]
        file_source = result["file_source"]
        page_number = result["page_num"]
        doc_id = result["doc_ID"]
        block_id = result["block_ID"]
        matches = result["matches"]

        print("query results: ", i, result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/Z3VgQu8hkVeB1bakS9/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Z3VgQu8hkVeB1bakS9/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 3 - The results
&lt;/h2&gt;

&lt;p&gt;The outputted summary will include key information such as &lt;code&gt;total pdf files processed&lt;/code&gt;, &lt;code&gt;total blocks created&lt;/code&gt;, &lt;code&gt;total pages added&lt;/code&gt;, and &lt;code&gt;time elapsed&lt;/code&gt;. Try and see if you can find all of them! &lt;/p&gt;

&lt;p&gt;In particular, the LLMWare package includes "C based parsers" that are able to quickly and efficiently parse files. Once completed, the parsed information will be outputted as a dictionary. You will see the results of your work in the previous steps!&lt;/p&gt;

&lt;p&gt;To summarize, we took our documents and broke them down into thousands of blocks. Then, we extracted text information and put it into the sqlite database. Lastly, we ran a text search against that data to retrieve our results (including details as small as pixel coordinates and character level matches!).&lt;/p&gt;

&lt;p&gt;You just completed your first example, but there is so much more for you to explore! I would suggest rerunning this example with varied data sets to tap into the true potential of this technology, and of course, continue onto example 2 about &lt;a href="https://github.com/llmware-ai/llmware/blob/main/fast_start/example-2-build_embeddings.py" rel="noopener noreferrer"&gt;building embeddings&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 4 - To see more ...
&lt;/h2&gt;

&lt;p&gt;Please join our LLMWare community on discord to learn more about RAG and LLMs! &lt;a href="https://discord.gg/5mx42AGbHm" rel="noopener noreferrer"&gt;https://discord.gg/5mx42AGbHm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Visit LLMWare's Website&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/llmware-ai/llmware" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Explore LLMWare on GitHub&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/free-photo/computer-scientist-updating-ai-systems_237235999.htm#fromView=image_search_similar&amp;amp;page=1&amp;amp;position=3&amp;amp;uuid=0b4ac661-5087-4321-a5cf-0838108d5997" rel="noopener noreferrer"&gt;Image by DC Studio on Freepik&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>ai</category>
      <category>learning</category>
      <category>python</category>
    </item>
  </channel>
</rss>
