<?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: Vardhanam Daga</title>
    <description>The latest articles on DEV Community by Vardhanam Daga (@vardhanam).</description>
    <link>https://dev.to/vardhanam</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%2F1227320%2F39fa9981-98c9-4757-84e7-de4029a35406.jpg</url>
      <title>DEV Community: Vardhanam Daga</title>
      <link>https://dev.to/vardhanam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vardhanam"/>
    <language>en</language>
    <item>
      <title>Using Qdrant’s Discovery API for Video Search</title>
      <dc:creator>Vardhanam Daga</dc:creator>
      <pubDate>Tue, 16 Jan 2024 13:41:13 +0000</pubDate>
      <link>https://dev.to/vardhanam/using-qdrants-discovery-api-for-video-search-3dpd</link>
      <guid>https://dev.to/vardhanam/using-qdrants-discovery-api-for-video-search-3dpd</guid>
      <description>&lt;h2&gt;
  
  
  How Video Search Works
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xY8WtIMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffj62q5trxdh42mzdw88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xY8WtIMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffj62q5trxdh42mzdw88.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we are going to understand how semantic search works for a video database. It is a technique where the description of a video tells a story so that querying becomes easier than ever before. But, first, let’s understand how most video search works currently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Metadata-Based Search:&lt;/strong&gt; This is one of the most common methods. Videos are tagged with various metadata such as titles, descriptions, tags, and other relevant information. When you search, the system looks for keywords in this metadata to find matching videos. This search is limited to only the keywords contained in the description of the video, and misses the semantic intention behind these descriptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Transcript or Closed Caption Search:&lt;/strong&gt; With the advent of better speech recognition technology, many platforms have started using automated transcripts or closed captions for videos. This allows for text-based searching within the video content. When you search for a phrase, the system checks the transcript for matches and returns videos containing those words.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Thumbnail-Based Search:&lt;/strong&gt; Some search algorithms analyze the thumbnails of videos to determine their content and relevance to a search query. This method, however, is less precise than the others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Content-Based Video Retrieval (CBVR):&lt;/strong&gt; This is a more advanced approach where the search algorithm analyzes the actual content of the video (like objects, scenes, actions, faces, etc.) using image and video processing techniques. This method can be resource-intensive and is not yet widely implemented in most commercial video search platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. User Interaction Data:&lt;/strong&gt; Search algorithms also take into account user interaction data like views, likes, comments, and watch history to determine the relevance and ranking of videos in search results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Contextual and Semantic Analysis:&lt;/strong&gt; Some advanced search systems also perform contextual and semantic analysis of the video description and user query to understand the intent behind a search and the context of the content in the videos.&lt;/p&gt;

&lt;p&gt;In this article, we are going to delve deeper into this last point, i.e., semantic analysis of video descriptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Semantic Analysis?
&lt;/h2&gt;

&lt;p&gt;Semantic analysis involves understanding the themes, narratives, and concepts presented in the video description, beyond just the visible keywords. For example, a video description might have the words ‘a person running’ but, semantically, it could be about ‘fitness’, ‘perseverance’, or even a ‘sports brand advertisement’.&lt;/p&gt;

&lt;p&gt;Let's consider a more nuanced example of semantic video search:&lt;/p&gt;

&lt;p&gt;Suppose our Search Query is: 'Easy dinner for busy weekdays’.&lt;/p&gt;

&lt;p&gt;A Traditional Keyword-Based Search Approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Would focus on keywords like 'dinner,' 'busy,' and 'weekdays.'&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Might return generic dinner recipes or videos titled with these specific keywords.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the other hand, a Semantic Video Search approach would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand the Query Semantics: Recognize that the user is looking for a meal that is quick and easy to prepare, suitable for a busy weekday schedule.The system might also consider semantically related concepts such as 'meal prep ideas,' 'quick healthy dinners,' or 'family-friendly quick recipes,' expanding the search scope to include relevant content that doesn't necessarily match the exact query terms. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the system would search for videos where the description aligns with the concept of 'easy' and 'quick' preparation, even if those exact words aren't used in the video's title or description or content. For example, it might prioritize videos with concepts such as  '30 minutes or less,' 'simple ingredients,' or 'one-pot meals.'&lt;/p&gt;

&lt;h2&gt;
  
  
  Sentence Transformers
&lt;/h2&gt;

&lt;p&gt;To generate embeddings for our video description, we’ll use the &lt;a href="https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2"&gt;‘all-MiniLM-L6-v2’&lt;/a&gt; sentence transformers from hugging face. This model can map sentences of our video description to a vector space of 384 dimensions, and is ideal for tasks like semantic searching. &lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Semantic Video Search Engine with Qdrant
&lt;/h2&gt;

&lt;p&gt;In this article, we’ll use a collection of GIFs (which is, basically, low-resolution short video snippets), and use the sentence-transformers model to generate their embeddings. Then we’ll store these embeddings in &lt;a href="https://qdrant.tech"&gt;Qdrant&lt;/a&gt;, which is a vector database designed for efficient storing, searching and retrieval of vector embeddings.&lt;/p&gt;

&lt;p&gt;An interesting feature of Qdrant is its Discovery API. This API is particularly notable for refining search parameters to achieve greater precision, focusing on the concept of 'context.' This context refers to a collection of positive-negative pairs that define zones within a space, dividing the space into positive or negative segments. The search algorithm then prioritizes points based on their inclusion within positive zones or their avoidance of negative zones.&lt;/p&gt;

&lt;p&gt;The Discovery API offers two main modes of operation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Discovery Search: This utilizes a target point to find the most relevant points in the collection, but only within preferred areas. It's essentially a controlled search operation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mH4o__v9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9huk9ygufuw33ztl280h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mH4o__v9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9huk9ygufuw33ztl280h.png" alt="Image description" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(from Qdrant’s Documentation)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Context Search: Similar to discovery search but without a target point. Instead, it uses 'context' to navigate the Hierarchical Navigable Small World (HNSW) graph towards preferred zones. This mode is expected to yield diverse results, not centered around one point, and is suitable for more exploratory approaches in navigating the vector space.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tqDz5Gds--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kc1ek035em6d4xlusjnn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tqDz5Gds--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kc1ek035em6d4xlusjnn.png" alt="Image description" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(from Qdrant’s Documentation)&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Environment and Code
&lt;/h2&gt;

&lt;p&gt;We’ll use data from the&lt;a href="https://github.com/raingo"&gt; raingo/TGIF-Release&lt;/a&gt; GitHub repository. It’s a tsv file containing 10,000 rows of GIF urls and descriptions. Download it with the following command on your Colab notebooks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;!wget https://github.com/raingo/TGIF-Release/raw/master/data/tgif-v1.0.tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, install all the dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install requests pillow transformers qdrant-client sentence-transformers accelerate tqdm sentence-transformers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, launch a cluster on &lt;a href="https://cloud.qdrant.io/accounts/06de036b-a0d1-4105-9299-a23a9352f236/clusters"&gt;Qdrant Cloud&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VZmVjT-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tx0eohgerr3lwvhjb2pk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VZmVjT-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tx0eohgerr3lwvhjb2pk.png" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Retain the API key of the cluster. In this cluster, we’ll create a collection for storing the vector embeddings (also known as points).&lt;/p&gt;

&lt;p&gt;Load the CLIP model and create a Qdrant client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sentence_transformers import SentenceTransformer
from qdrant_client import QdrantClient
from qdrant_client.http import models

print("[INFO] Loading the model...")
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')

client = QdrantClient(url=url="https://xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx.us-east.aws.cloud.qdrant.io:6333",
    api_key="&amp;lt;your-api-key&amp;gt;"
,)
print("[INFO] Client created...")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ll now create embeddings of the description of our video. We’ll also create an index for our vectors. Additionally, we’ll make a dictionary of payloads that will contain the url and the description of our videos.&lt;br&gt;
&lt;/p&gt;

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

# Replace 'your_file.tsv' with the path to your TSV file
file_path = '/content/tgif-v1.0.tsv'

# Lists to store the data
descriptions = []
payload = []


# Reading the TSV file
with open(file_path, 'r', encoding='utf-8') as file:
    tsv_reader = csv.reader(file, delimiter='\t')


    # Iterate through each row in the TSV file
    for row in tsv_reader:
        if len(row) &amp;gt;= 2:  # Checking if the row has at least two elements (URL and description)
            url, description = row[0], row[1]
            descriptions.append(description)
            payload.append({"url": url, "description": description})


idx = list(range(1, len(descriptions) + 1))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create embeddings of the description.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sentence_transformers import SentenceTransformer
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
embeddings = model.encode(descriptions).tolist()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a Qdrant collection with the name gif_collection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("[INFO] Creating qdrant data collection...")
client.create_collection(
    collection_name="gif_collection",
    vectors_config=models.VectorParams(size=384, distance=models.Distance.COSINE),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;/div&gt;



&lt;p&gt;Next, we upload the records to our collection. We’ll only upload the first 2500 records for convenience’s sake.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#uploading the records to client
print("[INFO] Uploading data records to data collection...")
client.upsert(
    collection_name="gif_collection",
    points=models.Batch(
        ids=idx[:2500],
        payloads=payload[:2500],
        vectors=embeddings[:2500],
    ),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have our Vector DB ready, and we can use the Discovery API to query it.&lt;/p&gt;

&lt;p&gt;Let’s set our target to videos of 'tiger', with the positive context as 'animals', but we don’t want any cat videos, so we’ll set the negative context 'cats':&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;target = 'animals'
positive = 'tiger'
negative = 'cats'
emb_target = model.encode(target).tolist()
emb_positive = model.encode(positive).tolist()
emb_negative = model.encode(negative).tolist()

hits = client.discover(
    collection_name="gif_collection",
    target = emb_target,
    context = [{'positive': emb_positive, 'negative': emb_negative}],
    limit=5,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s see what the top 5 results look like:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ScoredPoint(id=53, version=0, score=1.6944957, payload={'description': 'the tiger is running really fast in the garden', 'url': 'https://38.media.tumblr.com/8c14aa571911985d6d774762f8159452/tumblr_n4gk7efcMw1spy7ono1_400.gif'}, vector=None, shard_key=None),
 ScoredPoint(id=1120, version=0, score=1.6891048, payload={'description': 'a giant tiger creature jumps through the air.', 'url': 'https://38.media.tumblr.com/be596acc2860e691e578c2a64d044d94/tumblr_nq0mhrqyAf1u4fhlko1_250.gif'}, vector=None, shard_key=None),
 ScoredPoint(id=1269, version=0, score=1.6566299, payload={'description': 'a young tiger cub nestles down to sleep next to a large teddy bear.', 'url': 'https://38.media.tumblr.com/b9762b528bbd4a61f4b1c6ac5352b92f/tumblr_nqi6joMEOR1uv0y2ro1_250.gif'}, vector=None, shard_key=None),
 ScoredPoint(id=4, version=0, score=1.6384017, payload={'description': 'an animal comes close to another in the jungle', 'url': 'https://38.media.tumblr.com/9f659499c8754e40cf3f7ac21d08dae6/tumblr_nqlr0rn8ox1r2r0koo1_400.gif'}, vector=None, shard_key=None),
 ScoredPoint(id=2333, version=0, score=1.6347136, payload={'description': 'a view from car where a lion is looking in the tries to get in.', 'url': 'https://33.media.tumblr.com/2aeb5012cde835e61f2e35cd49960971/tumblr_nnums3GbD71ssgyoro1_400.gif'}, vector=None, shard_key=None)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We get three video descriptions with the word ‘tiger’ in it, followed by a description which has the word ‘animal’ in it, and then the last video is that of a ‘lion’. This is as expected. Most of our videos are of our target, which is ‘tiger’. We got one ‘animal’ video because that is our positive context. And we did not get a single video of ‘cat’ as that is our negative context. We got one video of ‘lion’ because ‘lion’ is semantically similar to ‘tiger’.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the process of building a semantic video search engine using sentence-transformers and Qdrant demonstrates the capabilities of AI in understanding and categorizing video descriptions. The traditional keyword-based search methods are limited to metadata, transcripts, and thumbnails, which may not capture the full context or semantic meaning of the video. However, with semantic search, the system comprehends the deeper themes and narratives within the videos, making search results more relevant and precise.&lt;/p&gt;

&lt;p&gt;The Discovery API of Qdrant, with its unique ability to refine search parameters through context, further enhances the precision of these search results.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://qdrant.tech/documentation/concepts/explore/"&gt;https://qdrant.tech/documentation/concepts/explore/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Build a Customer Service Chatbot Using Flask, Llama 2, LangChain and Qdrant</title>
      <dc:creator>Vardhanam Daga</dc:creator>
      <pubDate>Tue, 26 Dec 2023 12:34:41 +0000</pubDate>
      <link>https://dev.to/vardhanam/build-a-customer-service-chatbot-using-flask-llama-2-langchain-and-qdrant-659</link>
      <guid>https://dev.to/vardhanam/build-a-customer-service-chatbot-using-flask-llama-2-langchain-and-qdrant-659</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yo_-wtmz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbk51l218wirv2i2z734.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yo_-wtmz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbk51l218wirv2i2z734.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Customer service chatbots play a pivotal role in transforming the customer experience across diverse industries. These intelligent virtual assistants are employed in a myriad of use cases to streamline and enhance customer support. They excel in handling routine tasks, such as automated FAQs, providing instant responses to common queries and offering real-time updates on order status and tracking. Chatbots are instrumental in automating appointment scheduling, making reservations, and even facilitating product recommendations based on user preferences. Additionally, they prove invaluable in resolving technical issues through guided troubleshooting, collecting valuable customer feedback, and easing the onboarding process for new users. Industries ranging from e-commerce to healthcare leverage chatbots for tasks such as billing inquiries, language translation, and lead generation. The versatility of customer service chatbots extends to internal support, where they assist employees with HR-related queries. While providing swift and efficient responses, these chatbots significantly contribute to optimizing operational processes and fostering positive customer interactions.&lt;/p&gt;

&lt;p&gt;In this article, we’ll build a Customer Service Chatbot that is powered by Flask, Qdrant, LangChain, and Llama 2. As an example we’ll supply the chatbot with a document containing Google’s Code of Conduct, but you can use your own company’s documentation as a context for the chatbot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;**Flask: **Flask is an eminent web framework in the Python programming community, renowned for its simplicity and elegance. As a micro-framework, it is minimalistic yet powerful, offering developers a solid foundation for building a variety of web applications without imposing any specific tools or libraries. This flexibility allows Flask to be lightweight and straightforward to learn, making it an excellent choice for both beginners and experienced developers. It leverages the Jinja2 template engine for dynamic content rendering, ensuring a seamless integration of Python code with HTML. Flask's built-in development server and debugger facilitate efficient development and troubleshooting. Moreover, its capacity for easy extension with numerous available plugins supports more complex requirements, like database integration, form validation, and authentication. Flask's robustness and versatility, combined with a strong community and comprehensive documentation, has cemented its status as a go-to framework for web development in Python.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Qdrant:&lt;/strong&gt; Qdrant is an open-source vector search engine designed to facilitate efficient and scalable similarity search in high-dimensional vector spaces. It is particularly tailored for machine learning applications, such as image or natural language processing, where embedding vectors are commonly used to represent complex data. Qdrant stands out for its performance optimization and ease of use, providing a robust system for storing, managing, and querying large volumes of vector data. It supports various distance metrics, enabling precise and relevant search results for different types of data and use cases. Additionally, Qdrant offers features like filtering and full-text search, allowing for more complex and refined queries. Its architecture is designed to be horizontally scalable, making it well-suited for handling big data scenarios. Qdrant's user-friendly API and compatibility with popular programming languages like Python further enhance its accessibility to developers and data scientists. As a result, Qdrant is becoming increasingly popular in the field of AI and data-driven applications, where efficient and accurate vector search is crucial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LangChain&lt;/strong&gt;: LangChain is an innovative open-source library designed to augment the capabilities of large language models (LLMs), in creating applications that require complex, multi-step reasoning or knowledge retrieval. It primarily focuses on enhancing the ability of LLMs to interface with external knowledge sources, such as databases and search engines, thereby extending their problem-solving and informational capabilities beyond their intrinsic knowledge. LangChain's architecture is modular, allowing for the integration of various components and tools to tailor the LLM's performance to specific applications. This modularity also facilitates experimentation with different strategies for knowledge retrieval and reasoning, making it a versatile tool for developers and researchers in the field of AI and natural language processing. By leveraging LangChain, developers can create more sophisticated and intelligent applications that combine the nuanced understanding of human language inherent in LLMs with vast, dynamic external knowledge bases. This combination opens up new possibilities for AI applications in areas such as automated research, complex decision-making, and personalized content generation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Llama 2&lt;/strong&gt;: Llama 2, a powerhouse language model developed by Meta and Microsoft, stands as a giant in the world of AI. Trained on a vast ocean of internet data, it possesses the remarkable ability to converse, generate creative text formats, and answer your questions in an informative way. This open-source behemoth, freely available for research and commercial use, marks a significant leap forward in AI accessibility. With its immense potential and commitment to responsible development, Llama 2 paves the way for a future where AI empowers human creativity and understanding.&lt;/p&gt;

&lt;p&gt;Using the above 4 components we are going to implement a RAG pipeline into our customer service chatbot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Environment
&lt;/h2&gt;

&lt;p&gt;Install the following dependencies by creating a requirements.txt file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flask
Flask-Session
sentence-transformers
langchain
transformers
scipy
trl
bitsandbytes
peft
accelerate
torch
datasets
langchain
qdrant-client
pypdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file called app.py. That will be the file containing backend flask code, and all the logic for creating the RAG pipeline. First, I’ll paste the entire working code, then I’ll describe each section one-by-one in case you want to understand what the code does.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request, session, jsonify
from werkzeug.utils import secure_filename
import os
import os
import uuid
import torch
import transformers
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
BitsAndBytesConfig,
pipeline
)
from langchain.text_splitter import CharacterTextSplitter
from langchain.document_transformers import Html2TextTransformer
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
from langchain.vectorstores import Qdrant
from langchain.document_loaders import PyPDFLoader
from langchain.llms import HuggingFacePipeline
from langchain.chains import LLMChain, RetrievalQA

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads/'
ALLOWED_EXTENSIONS = {'pdf'}

if not os.path.exists(app.config['UPLOAD_FOLDER']):
    os.makedirs(app.config['UPLOAD_FOLDER'])

#Loading the Llama-2 Model
model_name='meta-llama/Llama-2-7b-chat-hf'
model_config = transformers.AutoConfig.from_pretrained(
model_name,
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"

#################################################################
# bitsandbytes parameters
#################################################################

# Activate 4-bit precision base model loading
use_4bit = True
# Compute dtype for 4-bit base models
bnb_4bit_compute_dtype = "float16"
# Quantization type (fp4 or nf4)
bnb_4bit_quant_type = "nf4"
# Activate nested quantization for 4-bit base models (double quantization)
use_nested_quant = False

#################################################################
# Set up quantization config
#################################################################
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)

bnb_config = BitsAndBytesConfig(
load_in_4bit=use_4bit,
bnb_4bit_quant_type=bnb_4bit_quant_type,
bnb_4bit_compute_dtype=compute_dtype,
bnb_4bit_use_double_quant=use_nested_quant,
)
# Check GPU compatibility with bfloat16
if compute_dtype == torch.float16 and use_4bit:
    major, _ = torch.cuda.get_device_capability()
    if major &amp;gt;= 8:
        print("=" * 80)
        print("Your GPU supports bfloat16: accelerate training with bf16=True")
        print("=" * 80)

#################################################################
# Load pre-trained config
#################################################################
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=bnb_config,
)

# Building a LLM QNA chain
text_generation_pipeline = transformers.pipeline(
model=model,
tokenizer=tokenizer,
task="text-generation",
temperature=0.2,
repetition_penalty=1.1,
return_full_text=True,
max_new_tokens=300,
)

llama_llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
file_id = None
retrieval_chain = None

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/upload', methods=['POST'])
def upload_file():
    global file_id
    if 'file' not in request.files:
        return 'No file part', 400
    file = request.files['file']
    if file.filename == '':
        return 'No selected file', 400
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file_id = str(uuid.uuid4())
        filepath = os.path.join(app.config['UPLOAD_FOLDER'], file_id)
        file.save(filepath)

        # Placeholder for your PDF processing logic
        process_pdf(filepath)

        return 'File uploaded &amp;amp; processed successfully. You can begin querying now', 200

def process_pdf(filepath):
    global retrieval_chain
    # Loading the splitting the document #
    filepath = os.path.join(app.config['UPLOAD_FOLDER'], file_id)
    loader = PyPDFLoader(filepath)
    docs = loader.load_and_split()
    # Chunk text
    text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=100)
    chunked_documents = text_splitter.split_documents(docs)

    # Load chunked documents into the Qdrant index
    db = Qdrant.from_documents(chunked_documents,              HuggingFaceEmbeddings(model_name='sentence-transformers/all-mpnet-base-v2'), location= ":memory:")
    retriever = db.as_retriever()
    retrieval_chain = RetrievalQA.from_llm(llm= llama_llm, retriever= retriever)

@app.route('/query', methods=['POST'])
def query():
    global retrieval_chain
    data = request.json
    query = data.get('query')

    return jsonify(retrieval_chain.run(query)), 200

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request, session, jsonify
......
from langchain.chains import LLMChain, RetrievalQA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, here’s a list of all the import statements needed to initialize our project.&lt;/p&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app = Flask(__name__)
....
    os.makedirs(app.config['UPLOAD_FOLDER'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We initialize our flask app and create the necessary directories.&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Loading the Llama-2 Model
model_name='TheBloke/Llama-2-7B-Chat-GGUF'
………
quantization_config=bnb_config,)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;\&lt;br&gt;
In this part of the code we set the quantization parameters of our model so it may work speedily and efficiently.&lt;/p&gt;

&lt;p&gt;4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Building a LLM QNA chain
text_generation_pipeline = transformers.pipeline(
……retrieval_chain = None
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, a LLM chain pipeline is created and some global variables are initialized, which we’ll later use to save data as the flask server is running.&lt;/p&gt;

&lt;p&gt;5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def allowed_file(filename):
    …………
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Helper function to grab the name of our pdf file.&lt;/p&gt;

&lt;p&gt;6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/upload', methods=['POST'])
def upload_file():
…………

        return 'File uploaded &amp;amp; processed successfully. You can begin querying now', 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where we are creating the API endpoint for uploading the pdf file. The upload file is then saved using a unique id. In-between, we are also using the helper function process_pdf to process our document for the vector store.&lt;/p&gt;

&lt;p&gt;7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def process_pdf(filepath):
    ………    retrieval_chain = RetrievalQA.from_llm(llm= llm, retriever= retriever)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;\&lt;br&gt;
&lt;/code&gt;We chunk the document into smaller parts, then use the Hugging Face embeddings to upsert it into our vector store, and then create a retrieval QA chain which is assigned to a global variable so that it can be used later.&lt;/p&gt;

&lt;p&gt;8.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route('/query', methods=['POST'])
def query():
………
    return jsonify(retrieval_chain.run(query)), 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we create the API endpoint for sending queries to our server and then receiving the returned messages from the retrieval_chain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Launching the app and interacting with our server (chatbot)
&lt;/h3&gt;

&lt;p&gt;Save the app.py file and, in the terminal, launch it with the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ULzGw70t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so5pa4ohid1xtv2wam1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ULzGw70t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/so5pa4ohid1xtv2wam1u.png" alt="Image description" width="800" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have a flask server (the chatbot) up and running on port 5000 of the localhost.&lt;/p&gt;

&lt;p&gt;To upload your pdf file, use the following command in a new terminal. For our article we shall upload Google’s Code of Conduct into our chatbot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -F 'file=@/path/to/your/file.pdf' http://localhost:5000/upload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the file is uploaded and processed, you should see the following message:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--05Z3ZwV1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npc3n5eit53edrvsvny7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--05Z3ZwV1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npc3n5eit53edrvsvny7.png" alt="Image description" width="800" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To send queries, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Content-Type: application/json" -d '{"query":"your query text here"}' http://localhost:5000/query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example queries
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Content-Type: application/json" -d '{"query":"Summarize the code of conduct document for me"}' http://localhost:5000/query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--buFnHCXN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75fuvo89bm7mvlahjxx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--buFnHCXN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75fuvo89bm7mvlahjxx3.png" alt="Image description" width="800" height="149"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Content-Type: application/json" -d '{"query":"What is google's stance on gender discrimination?"}' http://localhost:5000/query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6KGxFxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4xkcsp9c0ipshjzr3sa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y6KGxFxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4xkcsp9c0ipshjzr3sa.png" alt="Image description" width="800" height="86"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST -H "Content-Type: application/json" -d '{"query":"What is policy for outside employment?"}' http://localhost:5000/query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C2C_cQ69--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9evh4mj2b8kstt0ztlg7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C2C_cQ69--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9evh4mj2b8kstt0ztlg7.png" alt="Image description" width="800" height="113"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the provided code sets up a Flask server to deploy a chatbot based on the RAG (Retrieval-Augmented Generation) pipeline. The server allows users to upload PDF documents, which are pr## Introduction&lt;/p&gt;

&lt;p&gt;Customer service chatbots play a pivotal role in transforming the customer experience across diverse industries. These intelligent virtual assistants are employed in a myriad of use cases to streamline and enhance customer support. They excel in handling routine tasks, such as automated FAQs, providing instant responses to common queries and offering real-time updates on order status and tracking. Chatbots are instrumental in automating appointment scheduling, making reservations, and even facilitating product recommendations based on user preferences. Additionally, they prove invaluable in resolving technical issues through guided troubleshooting, collecting valuable customer feedback, and easing the onboarding process for new users. Industries ranging from e-commerce to healthcare leverage chatbots for tasks such as billing inquiries, language translation, and lead generation. The versatility of customer service chatbots extends to internal support, where they assist employees with HR-related queries. While providing swift and efficient responses, these chatbots significantly contribute to optimizing operational processes and fostering positive customer interactions.&lt;/p&gt;

&lt;p&gt;In this article, we’ll build a Customer Service Chatbot that is powered by Flask, Qdrant, LangChain, and Llama 2. As an example we’ll supply the chatbot with a document containing Google’s Code of Conduct, but you can use your own company’s documentation as a context for the chatbot.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Querying news articles via a streamlit app using openAI, langchain, and qdrant db</title>
      <dc:creator>Vardhanam Daga</dc:creator>
      <pubDate>Tue, 19 Dec 2023 08:02:15 +0000</pubDate>
      <link>https://dev.to/vardhanam/querying-news-articles-via-a-streamlit-app-using-openai-langchain-and-qdrant-db-4na4</link>
      <guid>https://dev.to/vardhanam/querying-news-articles-via-a-streamlit-app-using-openai-langchain-and-qdrant-db-4na4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Chatbots integrated into news querying serve various crucial purposes. They offer a convenient and conversational approach for users to access news, eliminating the need to navigate websites or apps. Users can simply ask a chatbot for news on a specific topic or event, making information more accessible, especially for those who find traditional methods challenging.&lt;/p&gt;

&lt;p&gt;Personalization is a key feature of chatbots in the news industry. By learning from users' past queries and interactions, chatbots can present more relevant and personalized news articles, enhancing the overall user experience. This tailoring of content ensures that users receive information aligned with their preferences.&lt;/p&gt;

&lt;p&gt;Time efficiency is another significant advantage. Chatbots quickly sift through vast amounts of information, presenting users with the most relevant news articles. This time-saving aspect is particularly beneficial for users who would otherwise have to manually search and filter through numerous sources.&lt;/p&gt;

&lt;p&gt;Moreover, chatbots contribute to interactive news consumption. They engage users in a conversation, answering follow-up questions and providing additional context or related information. This interactive approach adds depth to the news-reading experience, surpassing the passive nature of traditional methods.&lt;/p&gt;

&lt;p&gt;Information overload is a common issue in the digital age, and chatbots help mitigate it by filtering out noise. They deliver news that is most relevant to the user's interests and needs, streamlining the consumption process and enhancing user satisfaction.&lt;/p&gt;

&lt;p&gt;Visually impaired users benefit significantly from chatbots, especially when integrated with voice technology. This combination provides an invaluable audio-based method for accessing news, promoting inclusivity in news consumption.&lt;/p&gt;

&lt;p&gt;Integration into commonly used platforms, such as messaging apps, enhances user convenience. Users can receive news updates in the same environment where they communicate with others, streamlining their digital experience.&lt;/p&gt;

&lt;p&gt;Automated updates and alerts are a proactive feature of chatbots. Programmed to send timely news updates or alerts about breaking news, chatbots ensure that users stay informed in real time, contributing to a more connected and aware user base.&lt;/p&gt;

&lt;p&gt;Language and regional customization further extend the accessibility of news. Chatbots can be designed to deliver news in multiple languages and tailor content to regional or local interests, catering to diverse demographics and preferences.&lt;/p&gt;

&lt;p&gt;In summary, chatbots in the news industry elevate user experience through convenient, personalized, and interactive access to news. They address various challenges in traditional news consumption methods while catering to a diverse range of user needs and preferences.&lt;/p&gt;

&lt;p&gt;In this article, we’ll design an RAG pipeline using OpenAI, Langchain, and Qdrant DB and encase it in an user interface via Streamlit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is RAG
&lt;/h2&gt;

&lt;p&gt;"RAG" stands for "Retrieval-Augmented Generation." It's a technique used in natural language processing and machine learning, particularly in the development of advanced language models like chatbots.In a RAG setup, when a query is input (like a question or a prompt), the retrieval system first searches through its database to find relevant information or documents. This information is then passed on to the generative model, which synthesizes it to create a coherent and contextually appropriate response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bwvRqClf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3i98tw6iy2d1f1y8tnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bwvRqClf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3i98tw6iy2d1f1y8tnl.png" alt="Image description" width="800" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A Brief Note on the Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Langchain:&lt;/strong&gt; LangChain is an open-source framework designed to simplify the creation of applications using large language models (LLMs). LangChain's use-cases largely overlap with those of language models in general, including document analysis and summarization, chatbots, and code analysis. LangChain enables developers to connect LLMs to other data sources, interact with their environment, and build complex applications. It is written in Python and JavaScript and supports a variety of language models, including GPT-3, LLAMA,  Hugging Face Jurassic-1 Jumbo, and more. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Qdrant:&lt;/strong&gt; Qdrant is an open-source vector similarity search engine and vector database written in Rust. It provides a production-ready service with a convenient API to store, search, and manage points—vectors with an additional payload. Qdrant is tailored to extended filtering support, making it useful for various neural network or semantic-based matching, faceted search, and other applications. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Environment &amp;amp; Code
&lt;/h2&gt;

&lt;p&gt;First, in your directory, create a requirements.txt file with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;langchain
streamlit
requests
opeanai
qdrant-client
tiktoken
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the command to install these dependencies:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now create a file name &lt;code&gt;app.py&lt;/code&gt; and paste the following code in it, the comments explain their functionality:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#importing the needed libraries
import streamlit as st
import requests
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Qdrant
from langchain.chat_models import ChatOpenAI
from langchain.chains import RetrievalQA
import os

#function to fetch text data from the links of news websites
def fetch_article_content(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
    }
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        return response.text
    except requests.RequestException as e:
        st.error(f"Error fetching {url}: {e}")
        return ""

#function to collate all the text from the news website into a single string
def process_links(links):
    all_contents = ""
    for link in enumerate(links):
        content = fetch_article_content(link.strip())
        all_contents += content + "\n\n"
    return all_contents

#function to chunk the articles beofore creating vector embeddings
def get_text_chunks_langchain(text):
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
    texts = text_splitter.split_text(text)
    return texts

#creating the streamlit app

def main():
    st.title('News Article Fetcher')

    # Initialize state variables
    if 'articles_fetched' not in st.session_state:
        st.session_state.articles_fetched = False
    if 'chat_history' not in st.session_state:
        st.session_state.chat_history = ""

    # Model selection
    model_choice = st.radio("Choose your model", ["GPT 3.5", "GPT 4"], key= "model_choice")
    model = "gpt-3.5-turbo-1106" if st.session_state.model_choice == "GPT 3.5" else "gpt-4-1106-preview"

    #API_KEY
    API_KEY = st.text_input("Enter your OpenAI API key", type="password", key= "API_KEY")

    # Ensure API_KEY is set before proceeding
    if not API_KEY:
        st.warning("Please enter your OpenAI API key.")
        st.stop()

    #asking user to upload a text file with links to news articles (1 link per line)
    uploaded_file = st.file_uploader("Upload a file with links", type="txt")

    # Read the file into a list of links
    if uploaded_file:
        stringio = uploaded_file.getvalue().decode("utf-8")
        links = stringio.splitlines()

    # Fetch the articles' content
    if st.button("Fetch Articles") and uploaded_file:
        progress_bar = st.progress(0)
        with st.spinner('Fetching articles...'):
            article_contents = process_links(links)
            progress_bar.progress(0.25)  # Update progress to 25%

            #Process the article contents
            texts = get_text_chunks_langchain(article_contents)
            progress_bar.progress(0.5)  # Update progress to 50%

            #storing the chunked articles as embeddings in Qdrant
            os.environ["OPENAI_API_KEY"] =  st.session_state.API_KEY
            embeddings = OpenAIEmbeddings()
            vector_store = Qdrant.from_texts(texts, embeddings, location=":memory:",)
            retriever = vector_store.as_retriever()
            progress_bar.progress(0.75)  # Update progress to 75%

            #Creating a QA chain against the vectorstore
            llm = ChatOpenAI(model_name= model)
            if 'qa' not in st.session_state:
                st.session_state.qa = RetrievalQA.from_llm(llm= llm, retriever= retriever)
            progress_bar.progress(1)

            st.success('Articles fetched successfully!')
            st.session_state.articles_fetched = True

    #once articles are fetched, take input for user query

    if 'articles_fetched' in st.session_state and st.session_state.articles_fetched:

        query = st.text_input("Enter your query here:", key="query")

        if query:
            # Process the query using your QA model (assuming it's already set up)
            with st.spinner('Analyzing query...'):
                qa = st.session_state.qa
                response = qa.run(st.session_state.query)  
            # Update chat history
            st.session_state.chat_history += f"&amp;gt; {st.session_state.query}\n{response}\n\n"

        # Display conversation history
        st.text_area("Conversation:", st.session_state.chat_history, height=1000, key="conversation_area")
        # JavaScript to scroll to the bottom of the text area
        st.markdown(
            f"&amp;lt;script&amp;gt;document.getElementById('conversation_area').scrollTop = document.getElementById('conversation_area').scrollHeight;&amp;lt;/script&amp;gt;",
            unsafe_allow_html=True
        )

if __name__ == "__main__":
    main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then save the app.py and run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This launches your application at localhost with port number 8051.&lt;/p&gt;

&lt;p&gt;Here’s how the UI of the news article fetcher application looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n7kt39AT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65n7ps48m42w73xoiymk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n7kt39AT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65n7ps48m42w73xoiymk.png" alt="Image description" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the integration of chatbots into news querying not only addresses the challenges of traditional news consumption but also significantly enhances user experience by providing a convenient, personalized, and interactive access to information. The discussed RAG pipeline, incorporating OpenAI, Langchain, and Qdrant DB, coupled with a Streamlit-based user interface, exemplifies the cutting-edge technological advancements in natural language processing and machine learning. This comprehensive solution not only streamlines the process of fetching and analyzing news articles but also showcases the potential of AI-driven systems in delivering tailored content, mitigating information overload, and ensuring inclusivity for visually impaired users. The outlined code implementation serves as a practical guide for developers interested in building advanced chatbot applications for news retrieval, demonstrating the fusion of language models, vector similarity search engines, and efficient UI design. Ultimately, this innovative approach represents a paradigm shift in news consumption, offering a glimpse into the future of user-centric and technology-driven information access.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://api.python.langchain.com/en/latest/api_reference.html"&gt;https://api.python.langchain.com/en/latest/api_reference.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://python.langchain.com/docs/integrations/vectorstores/qdrant"&gt;https://python.langchain.com/docs/integrations/vectorstores/qdrant&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building a Multidocument Chatbot using Mistral 7B, Qdrant, and Langchain</title>
      <dc:creator>Vardhanam Daga</dc:creator>
      <pubDate>Wed, 06 Dec 2023 09:28:10 +0000</pubDate>
      <link>https://dev.to/vardhanam/building-a-multidocument-chatbot-using-mistral-7b-qdrant-and-langchain-523n</link>
      <guid>https://dev.to/vardhanam/building-a-multidocument-chatbot-using-mistral-7b-qdrant-and-langchain-523n</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;A Multi-document chatbot is basically a robot friend that can read lots of different stories or articles and then chat with you about them, giving you the scoop on all they’ve learned. This robot doesn’t get tired, even if it has to go through a whole pile of papers to find the information. They’re like your personal homework helper who does all the reading for you and then tells you what you need to know in a nice and easy way. In this blog post, we’ll elucidate the process of creating a multidocument chatbot using advanced technologies such as Mistral 7B, Qdrant, and Langchain.&lt;/p&gt;

&lt;p&gt;Understanding Mistral 7B&lt;/p&gt;

&lt;p&gt;Mistral 7B is a cutting-edge language model crafted by the startup Mistral, which has impressively raised $113 million in seed funding to focus on building and openly sharing advanced AI models. It boasts sophisticated features such as deep language comprehension, impressive text generation, and the ability to adapt to specialized tasks. For those interested in creating chatbots that can process information from multiple documents, delving into Mistral 7B’s functionalities would be crucial.&lt;/p&gt;

&lt;p&gt;Vector Database&lt;/p&gt;

&lt;p&gt;A vector database is a specialized type of database that is designed to store and manage vector data, which are arrays of numbers that represent various features of high-dimensional data points. In the context of machine learning and artificial intelligence, these vectors often come from the embeddings of more complex data types, such as images, text, or audio.&lt;/p&gt;

&lt;p&gt;The vectors are a way to translate this complex data into a language that a computer can more easily work with for tasks such as similarity search. For instance, in a vector database, you could ask it to find images similar to a given image, and the database would search through its stored vectors — numerical representations of images — to find those that are closest to your input vector in terms of distance in the multi-dimensional space they exist in.&lt;/p&gt;

&lt;p&gt;The “closeness” or “similarity” is determined by distance metrics like Euclidean distance, cosine similarity, or others, depending on the database and the specific application. Vector databases are optimized to perform these types of high-speed similarity searches and are crucial for supporting various AI-driven applications, including recommendation systems, search engines, and data analysis tools.&lt;/p&gt;

&lt;p&gt;Qdrant: An Introduction&lt;/p&gt;

&lt;p&gt;Qdrant is a vector database that specializes in storing and searching through high-dimensional vectors — the kind of data that represents complex items like images, text, or user preferences in a form that AI can understand. It provides an API service that developers use to add search functionality to their applications, allowing them to quickly find the most relevant pieces of information based on their similarity. This is particularly useful for building smarter search engines, recommendation systems, and other applications that need to sift through large amounts of data to find patterns or connections.&lt;/p&gt;

&lt;p&gt;Implementing Langchain for Language Workflows&lt;/p&gt;

&lt;p&gt;Using Langchain with Language Models: When you’re working with language models, sometimes you need specific information that the model wasn’t trained on. Retrieval Augmented Generation (RAG) is one way to solve this problem. It involves finding outside information and then giving it to the language model to help it answer questions. Langchain has many tools to help with this, from easy to advanced. In this part of the guide, we’ll talk about how to get the information you need, including finding documents, preparing them, and then using that information to help the language model.&lt;/p&gt;

&lt;p&gt;Getting Documents: Langchain can find documents from lots of different places for you. It works with more than 100 types of document finders and connects with other big services like AirByte and Unstructured. Whether you’re working with web pages, PDFs, or code, and whether your documents are stored privately (like in S3 buckets) or publicly, Langchain can help you load them up.&lt;br&gt;
Preparing Documents: It’s important to only fetch the parts of documents you really need. Langchain has tools to make this easier by breaking down big documents into smaller pieces that are easier to handle. It has different ways to do this, and some are even tailored for specific kinds of documents, like code or markdown files.&lt;br&gt;
Understanding Text: To make sure we can find documents that are similar to each other, we need to turn them into embeddings, which are like numerical fingerprints of text. Langchain lets you use more than 25 different services to create these embeddings. You can pick from free options or paid services, depending on what you need. Plus, Langchain makes it simple to switch from one service to another.&lt;br&gt;
Storing Embeddings: As embeddings become more common, we need special databases that can store and find them quickly. Langchain has options for this, too, with over 50 different databases you can use, from free local ones to paid cloud services. No matter which one you choose, Langchain keeps the way you interact with them consistent, so it’s easy to change databases if you need to.&lt;br&gt;
Retrievers&lt;/p&gt;

&lt;p&gt;When managing data within your database for a multidocument chatbot, the effectiveness of retrieving the right information is crucial. Langchain steps up to this challenge with a suite of retrieval tools. These include:&lt;/p&gt;

&lt;p&gt;The Parent Document Retriever, which allows for the generation of multiple data ‘fingerprints’ for a larger document. This method enables the chatbot to search through smaller sections of text while still understanding the context of the entire document.&lt;br&gt;
The Self Query Retriever, which is designed to tackle queries that aren’t just about semantic meaning but also include specific user details or conditions. It separates the meaningful content of a user’s question from other non-semantic information to ensure the response is as relevant as possible.&lt;br&gt;
The Ensemble Retriever, which is especially useful when your chatbot needs to pull information from a variety of databases or when you want to blend different retrieval methods for a more robust search.&lt;br&gt;
Integrating these sophisticated retrieval capabilities with Langchain can significantly enhance your chatbot’s ability to access and utilize multiple documents, delivering precise and contextually rich interactions.&lt;/p&gt;

&lt;p&gt;Building the Multidocument Chatbot&lt;/p&gt;

&lt;p&gt;Now that we understand Mistral 7B, Qdrant, and Langchain, we now begin building the multidocument chatbot. This entails data preprocessing, model fine-tuning, and deployment strategies to ensure that your chatbot can provide accurate and informative responses.&lt;/p&gt;

&lt;p&gt;Running LangChain and RAG for Text Generation and Retrieval&lt;br&gt;
In this section, we’ll go through the steps to use LangChain and the Retrieval-Augmented Generation (RAG) model to perform text generation and information retrieval tasks.&lt;/p&gt;

&lt;p&gt;Running With LangChain&lt;br&gt;
Setting Up the Environment&lt;br&gt;
&lt;code&gt;&lt;br&gt;
!pip install -q -U bitsandbytes&lt;br&gt;
!pip install -q -U git+https://github.com/huggingface/transformers.git&lt;br&gt;
!pip install -q -U git+https://github.com/huggingface/peft.git&lt;br&gt;
!pip install -q -U git+https://github.com/huggingface/accelerate.git&lt;br&gt;
!pip install -q -U einops&lt;br&gt;
!pip install -q -U safetensors&lt;br&gt;
!pip install -q -U torch&lt;br&gt;
!pip install -q -U xformers&lt;br&gt;
!pip install -q -U langchain&lt;br&gt;
!pip install -q -U ctransformers[cuda]&lt;br&gt;
!pip install qdrant_client&lt;br&gt;
!pip install sentence-transformers&lt;/code&gt;&lt;br&gt;
Authenticate with Hugging Face&lt;br&gt;
To authenticate with Hugging Face, you’ll need an access token. Here’s how to get it:&lt;/p&gt;

&lt;p&gt;Go to your Hugging Face account.&lt;br&gt;
Navigate to ‘Settings’ and click on ‘Access Tokens’.&lt;br&gt;
Create a new token or copy an existing one.&lt;br&gt;
(Link to Huggingface)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!pip install huggingface_hub&lt;br&gt;
from huggingface_hub import notebook_login&lt;br&gt;
notebook_login()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We begin by defining the model we want to use. In this case, it’s “mistralai/Mistral-7B-Instruct-v0.1.”&lt;br&gt;
We create an instance of the model for text generation and set various parameters for its behavior.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import torch&lt;br&gt;
from transformers import BitsAndBytesConfig&lt;br&gt;
quantization_config = BitsAndBytesConfig(&lt;br&gt;
    load_in_4bit=True,&lt;br&gt;
    bnb_4bit_compute_dtype=torch.float16,&lt;br&gt;
    bnb_4bit_quant_type="nf4",&lt;br&gt;
    bnb_4bit_use_double_quant=True,&lt;br&gt;
)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;LangChain Setup&lt;br&gt;
First we import LangChain components.&lt;br&gt;
Then we create a LangChain pipeline using the model for text generation.&lt;/p&gt;

&lt;p&gt;`model_id = "mistralai/Mistral-7B-Instruct-v0.1"&lt;/p&gt;

&lt;p&gt;from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline&lt;br&gt;
model_4bit = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto",quantization_config=quantization_config, )&lt;br&gt;
tokenizer = AutoTokenizer.from_pretrained(model_id)&lt;br&gt;
pipeline = pipeline(&lt;br&gt;
        "text-generation",&lt;br&gt;
        model=model_4bit,&lt;br&gt;
        tokenizer=tokenizer,&lt;br&gt;
        use_cache=True,&lt;br&gt;
        device_map="auto",&lt;br&gt;
        max_length=500,&lt;br&gt;
        do_sample=True,&lt;br&gt;
        top_k=5,&lt;br&gt;
        num_return_sequences=1,&lt;br&gt;
        eos_token_id=tokenizer.eos_token_id,&lt;br&gt;
        pad_token_id=tokenizer.eos_token_id,&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;from langchain import HuggingFacePipeline&lt;br&gt;
from langchain import PromptTemplate, LLMChain&lt;br&gt;
llm = HuggingFacePipeline(pipeline=pipeline)`&lt;/p&gt;

&lt;p&gt;Generating Text&lt;br&gt;
We define a template for generating responses that includes context and a question.&lt;br&gt;
We provide a specific question and context for the model to generate a response.&lt;br&gt;
The response variable now contains the generated response.&lt;/p&gt;

&lt;p&gt;`template = """[INST] You are a helpful, respectful and honest assistant. Answer exactly in few words from the context&lt;br&gt;
Answer the question below from context below :&lt;br&gt;
{context}&lt;br&gt;
{question} [/INST] &lt;br&gt;
"""&lt;br&gt;
question_p = """Which companies announced their mergers"""&lt;br&gt;
context_p = """ In a landmark fusion of tech titans, Cybervine and QuantumNet announced their merger today, promising to redefine the digital frontier with their combined innovation powerhouse, now known as CyberQuantum."""&lt;br&gt;
prompt = PromptTemplate(template=template, input_variables=["question","context"])&lt;br&gt;
llm_chain = LLMChain(prompt=prompt, llm=llm)&lt;br&gt;
response = llm_chain.run({"question":question_p,"context":context_p})&lt;br&gt;
response&lt;/p&gt;

&lt;p&gt;template = """[INST] You are a helpful, respectful and honest assistant. Answer exactly in few words from the context&lt;br&gt;
Answer the question below from context below :&lt;br&gt;
{context}&lt;br&gt;
{question} [/INST] &lt;br&gt;
"""&lt;br&gt;
question_p = """How many stocks did the investor buy? """&lt;br&gt;
context_p = """ Amidst a flurry of market activity, investor Jordan McHale made headlines by confidently scooping up 50,000 shares of the burgeoning tech firm Solarity Innovations, signaling a bullish stance on the company's green energy prospects."""&lt;br&gt;
prompt = PromptTemplate(template=template, input_variables=["question","context"])&lt;br&gt;
llm_chain = LLMChain(prompt=prompt, llm=llm)&lt;br&gt;
response = llm_chain.run({"question":question_p,"context":context_p})&lt;br&gt;
response`&lt;/p&gt;

&lt;p&gt;Retrieval Augmented Generation (RAG)&lt;br&gt;
Setting Up RAG&lt;br&gt;
We start by importing the necessary modules for RAG setup.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from qdrant_client import QdrantClient&lt;br&gt;
from langchain.llms import HuggingFacePipeline&lt;br&gt;
from langchain.document_loaders import TextLoader&lt;br&gt;
from langchain.text_splitter import RecursiveCharacterTextSplitter&lt;br&gt;
from langchain.embeddings import HuggingFaceEmbeddings&lt;br&gt;
from langchain.chains import RetrievalQA&lt;br&gt;
from langchain.vectorstores import Qdrant&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Providing Document Context&lt;br&gt;
We provide a sample document context, which is a news article in this case.&lt;/p&gt;

&lt;p&gt;`mna_news = &lt;br&gt;
"""Vectora, a forward-thinking player in the tech startup ecosystem, has ushered in a new chapter by naming Priyanka Desai as its Chief Executive Officer. Desai, a renowned figure in the tech community for her groundbreaking work at Nexus Energy Solutions, takes the reins at Vectora to propel the company into a leader in sustainable technology. With an expansive vision and a stellar record, Desai emerged as the chosen leader after an extensive international search, reflecting the board's confidence in her innovative approach and strategic acumen.&lt;br&gt;
This strategic appointment coincides with Vectora's most recent milestone--securing a transformative $200 million in funding aimed at accelerating its growth. Desai's illustrious career, highlighted by her success in scaling Nexus Energy Solutions to an industry vanguard, speaks to her exceptional leadership. "Priyanka is the embodiment of leadership with purpose, and her alignment with our core values is what makes this appointment a perfect match," expressed Anil Mehta, Vectora's co-founder. Desai's plans for Vectora not only encompass financial growth but also reinforce the company's pledge to environmental innovation.&lt;br&gt;
Addressing the company after her appointment, Desai unveiled an ambitious roadmap to expand Vectora's R&amp;amp;D efforts and introduce groundbreaking products to reduce industrial carbon emissions. "I am energized to lead a company that is as committed to sustainability as it is to technological innovation," Desai shared, underscoring her commitment to combating the urgent challenges posed by climate change.&lt;br&gt;
Desai's leadership style, characterized by her emphasis on inclusive growth and collaborative innovation, has been met with resounding approval from within Vectora's ranks and across the tech sector. Her drive for fostering a workplace where diverse ideas flourish has drawn particular admiration. "Priyanka brings a dynamic perspective to Vectora that will undoubtedly spark creativity and drive," commented Anjali Vaidya, a prominent technology sector analyst. "Her track record of empowering her teams speaks volumes about her potential impact on Vectora's trajectory."&lt;br&gt;
As Desai takes charge, industry observers are keenly awaiting the rollout of Vectora's most ambitious endeavor yet--an AI-driven toolset designed to optimize energy management for a global clientele. With Desai at the wheel, Vectora stands on the precipice of not just market success, but also contributing a significant handprint to the global sustainability effort. The tech world is abuzz as Desai is set to officially step into her new role next week, marking a potentially transformative era for Vectora and the industry at large.&lt;/p&gt;

&lt;p&gt;"""`&lt;/p&gt;

&lt;p&gt;Setting Up RAG Components&lt;br&gt;
Let’s configure various components, such as text splitting and embeddings.&lt;br&gt;
Then create a vector store using the provided documents and embeddings.&lt;br&gt;
We’ll also configure the retrieval component, retriever, and setup the RetrievalQA.&lt;/p&gt;

&lt;p&gt;`from langchain.schema.document import Document&lt;br&gt;
documents = [Document(page_content=mna_news, metadata={"source": "local"})]&lt;/p&gt;

&lt;p&gt;text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=20)&lt;br&gt;
all_splits = text_splitter.split_documents(documents)&lt;br&gt;
model_name = "sentence-transformers/all-mpnet-base-v2"&lt;br&gt;
model_kwargs = {"device": "cuda"}&lt;br&gt;
embeddings = HuggingFaceEmbeddings(model_name=model_name, model_kwargs=model_kwargs)&lt;/p&gt;

&lt;p&gt;vectordb = Qdrant.from_documents(documents=all_splits, embedding=embeddings, location=":memory:",&lt;br&gt;
    prefer_grpc=True,&lt;br&gt;
    collection_name="my_documents",&lt;br&gt;
) # Local mode with in-memory storage only&lt;/p&gt;

&lt;p&gt;retriever = vectordb.as_retriever()&lt;/p&gt;

&lt;p&gt;qa = RetrievalQA.from_chain_type(&lt;br&gt;
    llm=llm,&lt;br&gt;
    chain_type="stuff",&lt;br&gt;
    retriever=retriever,&lt;br&gt;
    verbose=True&lt;br&gt;
)&lt;br&gt;
def run_my_rag(qa, query):&lt;br&gt;
    print(f"Query: {query}\n")&lt;br&gt;
    result = qa.run(query)&lt;br&gt;
    print("\nResult: ", result)&lt;br&gt;
Running a Query&lt;/p&gt;

&lt;p&gt;query =""" What company is buyer and seller here """&lt;br&gt;
run_my_rag(qa, query)&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Real-World Applications&lt;/p&gt;

&lt;p&gt;Chatbots that can read and understand information from many documents can be really helpful for different jobs. They can talk to customers to help solve their problems, help people find information they need for research, and pick out the best content for different topics.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;The development of multidocument chatbots is an exciting frontier in the field of AI-powered conversational agents. By combining Mistral 7B’s language understanding, Qdrant’s vectordb, and Langchain’s language processing, developers can create chatbots that provide comprehensive, context-aware responses to user queries. This article serves as a starting point for anyone interested in building chatbots using these advanced technologies, opening up new possibilities for human-machine interaction. With the right tools and techniques, you can create chatbots that are more informative and engaging than ever before.&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;p&gt;Qdrant: &lt;a href="https://qdrant.tech/documentation/overview/"&gt;https://qdrant.tech/documentation/overview/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Langchain documentation: &lt;a href="https://python.langchain.com/docs/modules/data_connection/"&gt;https://python.langchain.com/docs/modules/data_connection/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mistral 7B Research Paper: &lt;a href="https://arxiv.org/pdf/2310.06825.pdf"&gt;https://arxiv.org/pdf/2310.06825.pdf&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vectordatabase</category>
      <category>qdrant</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
