Skip to content

Commit e30d1f1

Browse files
committed
update example f Question_Answering_Pipeline_with_LangChain_and_Epsilla and EpsillaCloud
Signed-off-by: eric-epsilla <eric@epsilla.com>
1 parent 59c0856 commit e30d1f1

2 files changed

Lines changed: 17 additions & 29 deletions

File tree

examples/Question_Answering_Pipeline_with_LangChain_and_Epsilla.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,22 @@
1616

1717
# Step2. Configure the OpenAI API Key
1818
import os
19-
20-
os.environ["OPENAI_API_KEY"] = "*****"
19+
os.environ["OPENAI_API_KEY"] = "Your-OpenAI-API-Key"
2120

2221

2322
# Step3. Load the documents
2423
from langchain.document_loaders import WebBaseLoader
2524
from langchain.text_splitter import CharacterTextSplitter
2625
from langchain_openai import OpenAIEmbeddings
2726

28-
loader = WebBaseLoader(
29-
"https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt"
30-
)
27+
loader = WebBaseLoader("https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt")
3128
documents = loader.load()
32-
documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(
33-
documents
34-
)
29+
documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(documents)
3530
embeddings = OpenAIEmbeddings()
3631

3732

38-
39-
4033
# Step4. Load the vector store
41-
from langchain.vectorstores import Epsilla
34+
from langchain_community.vectorstores import Epsilla
4235
from pyepsilla import vectordb
4336

4437
db_client = vectordb.Client(protocol="https", host="demo.epsilla.com", port="443")
@@ -56,11 +49,12 @@
5649
)
5750

5851

52+
53+
5954
# Step4. Create the QA for Retrieval
6055
from langchain.chains import RetrievalQA
6156
from langchain_openai import OpenAI
6257

63-
6458
qa = RetrievalQA.from_chain_type(
6559
llm=OpenAI(), chain_type="stuff", retriever=vector_store.as_retriever()
6660
)

examples/Question_Answering_Pipeline_with_LangChain_and_EpsillaCloud.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,35 @@
1010
pip install tiktoken
1111
pip install pyepsilla
1212
pip install -U langchain-openai
13-
pip uninstall -y langchain-community
14-
git clone https://github.com/epsilla-cloud/langchain.git
15-
cd ./langchain/libs/community
16-
pip install .
13+
pip install -U langchain-community
1714
"""
1815

1916

20-
2117
# Step2. Configure the OpenAI API Key
2218
import os
2319

24-
os.environ["OPENAI_API_KEY"] = ""
25-
epsilla_api_key = os.getenv("EPSILLA_API_KEY", "")
26-
project_id = os.getenv("EPSILLA_PROJECT_ID", "")
27-
db_id = os.getenv("EPSILLA_DB_ID", "")
20+
os.environ["OPENAI_API_KEY"] = "Your-OpenAI-API-Key"
21+
epsilla_api_key = os.getenv("EPSILLA_API_KEY", "Your-Epsilla-API-Key")
22+
project_id = os.getenv("EPSILLA_PROJECT_ID", "Your-Project-ID")
23+
db_id = os.getenv("EPSILLA_DB_ID", "Your-DB-ID")
2824
db_sharding_id = os.getenv("EPSILLA_DB_SHARDING_ID", 0)
2925

26+
3027
# Step3. Load the documents
3128
from langchain.document_loaders import WebBaseLoader
3229
from langchain.text_splitter import CharacterTextSplitter
3330
from langchain_openai import OpenAIEmbeddings
3431

35-
loader = WebBaseLoader(
36-
"https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt"
37-
)
32+
loader = WebBaseLoader("https://raw.githubusercontent.com/hwchase17/chat-your-data/master/state_of_the_union.txt")
3833
documents = loader.load()
39-
documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(
40-
documents
41-
)
34+
documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(documents)
4235
embeddings = OpenAIEmbeddings()
4336

4437

4538
# Step4. Load the vector store
46-
from langchain.vectorstores import Epsilla
39+
from langchain_community.vectorstores import Epsilla
4740
from pyepsilla import cloud, vectordb
4841

49-
5042
db_name = f"db_{db_id.replace('-', '_')}"
5143
db_path = f"/data/{project_id}/{db_name}/s{db_sharding_id}"
5244
table_name = "MyCollection"
@@ -69,6 +61,8 @@
6961
collection_name=table_name,
7062
)
7163

64+
65+
7266
# Step4. Create the QA for Retrieval
7367
from langchain.chains import RetrievalQA
7468
from langchain_openai import OpenAI

0 commit comments

Comments
 (0)