avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2100

Abstract

</div><p id="43ab">Step 2: Provide your OpenAI key</p><div id="79aa"><pre><span class="hljs-keyword">import</span> <span class="hljs-built_in">os</span> <span class="hljs-built_in">os</span>.environ[<span class="hljs-string">"OPENAI_API_KEY"</span>] = <span class="hljs-string">"YOUR_OPENAI_API_KEY"</span></pre></div><p id="720a">Step 3: Prepare for knowledge and embedding model</p><div id="6f25"><pre>from langchain<span class="hljs-selector-class">.embeddings</span> import OpenAIEmbeddings from langchain<span class="hljs-selector-class">.document_loaders</span> import WebBaseLoader from langchain<span class="hljs-selector-class">.text_splitter</span> import CharacterTextSplitter

loader = <span class="hljs-built_in">WebBaseLoader</span>(<span class="hljs-string">"https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt"</span>) documents = loader<span class="hljs-selector-class">.load</span>()

documents = <span class="hljs-built_in">CharacterTextSplitter</span>(chunk_size=<span class="hljs-number">1000</span>, chunk_overlap=<span class="hljs-number">0</span>)<span class="hljs-selector-class">.split_documents</span>(documents)

embeddings = <span class="hljs-built_in">OpenAIEmbeddings</span>()</pre></div><p id="7d8e">Step 4: Vectorize the knowledge documents</p><div id="e6f9"><pre><span class="hljs-keyword">from</span> langchain.vectorstores import Epsilla <span class="hljs-keyword">from</span> pyepsilla import vectordb <span class="hljs-built_in"> client </span>= vectordb.Client() vector_store = Epsilla.from_documents( documents, embeddings, client, <span class="hljs-attribute">db_path</span>=<span class="hljs-string">"/tmp/mypath"</span>, <span class="hljs-attribute">db_name</span>=<span class="hljs-string">"MyDB"</span>, <span class="hljs-attribute">collection_name</span>=<span class="hljs-string">"MyCollection"</span> )</pre></div><p id="ac15">Step 5: Create a RetrievalQA chain for question answering on the uploaded knowledge</p><div id="a553"><pre><span class="hljs-keyword">from</span> langchain.chains i

Options

mport RetrievalQA <span class="hljs-keyword">from</span> langchain.llms import OpenAI

qa = RetrievalQA.from_chain_type(<span class="hljs-attribute">llm</span>=OpenAI(), <span class="hljs-attribute">chain_type</span>=<span class="hljs-string">"stuff"</span>, <span class="hljs-attribute">retriever</span>=vector_store.as_retriever()) query = <span class="hljs-string">"What did the president say about Ketanji Brown Jackson"</span> qa.<span class="hljs-built_in">run</span>(query)</pre></div><p id="77c9">The response will be:</p><p id="ffdf">“The president said that Ketanji Brown Jackson is one of the nation’s top legal minds, a former top litigator in private practice, a former federal public defender, from a family of public school educators and police officers, a consensus builder, and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.”</p><p id="6f7e">This integration promises richer, more accurate, and context-aware answers, making LangChain and Epsilla powerful tools in the transformation of AI and question-answering systems. For those who wish to explore further, the source code and implementation details with Epsilla are available on Google Colab.</p><div id="89a4" class="link-block"> <a href="https://readmedium.com/langchain-is-langchain-demogpt-the-new-era-for-general-ai-applications-fa5cc5ca2dbd"> <div> <div> <h2>LANGCHAIN — Is Langchain DemoGPT the New Era for General AI Applications?</h2> <div><h3>Real artists ship. — Steve Jobs</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="af63">By following these steps, you can implement a question-answering pipeline with LangChain and Epsilla, leveraging their superior performance and capabilities.</p></article></body>

LANGCHAIN — What Is Espilla-X Langchain Retrieval Augmented Generation (RAG) in LLM-Powered Question Answering Pipelines?

Software and cathedrals are much the same — first we build them, then we pray. — Sam Redwine

Retrieval Augmented Generation (RAG) in LLM-Powered Question-Answering Pipelines is a revolutionary approach that incorporates the strengths of Large Language Models (LLMs) and vector databases, enhancing the precision and relevance of generated responses. Epsilla’s integration with LangChain signifies a leap forward in the domain of question-answering systems.

Here’s a step-by-step guide on implementing a question-answering pipeline with LangChain and Epsilla using Python.

Step 1: Install LangChain and Epsilla

pip install langchain
pip install openai
pip install tiktoken
pip install pyepsilla
docker pull epsilla/vectordb
docker run --pull=always -d -p 8888:8888 epsilla/vectordb

Step 2: Provide your OpenAI key

import os
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"

Step 3: Prepare for knowledge and embedding model

from langchain.embeddings import OpenAIEmbeddings
from langchain.document_loaders import WebBaseLoader
from langchain.text_splitter import CharacterTextSplitter

loader = WebBaseLoader("https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt")
documents = loader.load()

documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(documents)

embeddings = OpenAIEmbeddings()

Step 4: Vectorize the knowledge documents

from langchain.vectorstores import Epsilla
from pyepsilla import vectordb

client = vectordb.Client()
vector_store = Epsilla.from_documents(
    documents,
    embeddings,
    client,
    db_path="/tmp/mypath",
    db_name="MyDB",
    collection_name="MyCollection"
)

Step 5: Create a RetrievalQA chain for question answering on the uploaded knowledge

from langchain.chains import RetrievalQA
from langchain.llms import OpenAI

qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=vector_store.as_retriever())
query = "What did the president say about Ketanji Brown Jackson"
qa.run(query)

The response will be:

“The president said that Ketanji Brown Jackson is one of the nation’s top legal minds, a former top litigator in private practice, a former federal public defender, from a family of public school educators and police officers, a consensus builder, and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.”

This integration promises richer, more accurate, and context-aware answers, making LangChain and Epsilla powerful tools in the transformation of AI and question-answering systems. For those who wish to explore further, the source code and implementation details with Epsilla are available on Google Colab.

By following these steps, you can implement a question-answering pipeline with LangChain and Epsilla, leveraging their superior performance and capabilities.

Question
Generation
Espilla X
Langchain
Augmented
Recommended from ReadMedium