DrishtiSharma commited on
Commit
d47491b
·
verified ·
1 Parent(s): 573b41b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -9,6 +9,7 @@ from llama_index.embeddings.openai import OpenAIEmbedding
9
  from llama_index.vector_stores.faiss import FaissVectorStore
10
  from llama_index.core.ingestion import IngestionPipeline
11
  from langchain_community.vectorstores import FAISS as LangChainFAISS
 
12
  from langchain.chains import create_retrieval_chain
13
  from langchain.chains.combine_documents import create_stuff_documents_chain
14
  from langchain_core.prompts import ChatPromptTemplate
@@ -43,16 +44,17 @@ if uploaded_file:
43
  data.to_csv(temp_file.name, index=False, encoding="utf-8")
44
  temp_file.flush()
45
 
46
- # Verify the temporary file
47
  st.write("Temporary file path:", temp_file_path)
48
  with open(temp_file_path, "r") as f:
49
- st.write("Temporary file content:")
50
- st.text(f.read())
 
51
 
52
  # Tabs for LangChain and LlamaIndex
53
  tab1, tab2 = st.tabs(["LangChain", "LlamaIndex"])
54
 
55
- # LangChain Tab with Custom Loader
56
  with tab1:
57
  st.subheader("LangChain Query")
58
  try:
@@ -68,11 +70,15 @@ if uploaded_file:
68
  if documents:
69
  st.text(documents[0]["page_content"])
70
 
71
- # Create FAISS VectorStore
72
  langchain_index = faiss.IndexFlatL2(EMBED_DIMENSION)
 
 
73
  langchain_vector_store = LangChainFAISS(
74
  embedding_function=OpenAIEmbeddings(),
75
  index=langchain_index,
 
 
76
  )
77
  langchain_vector_store.add_documents(documents)
78
 
 
9
  from llama_index.vector_stores.faiss import FaissVectorStore
10
  from llama_index.core.ingestion import IngestionPipeline
11
  from langchain_community.vectorstores import FAISS as LangChainFAISS
12
+ from langchain_community.docstore.in_memory import InMemoryDocstore
13
  from langchain.chains import create_retrieval_chain
14
  from langchain.chains.combine_documents import create_stuff_documents_chain
15
  from langchain_core.prompts import ChatPromptTemplate
 
44
  data.to_csv(temp_file.name, index=False, encoding="utf-8")
45
  temp_file.flush()
46
 
47
+ # Debugging: Verify the temporary file (Display partially)
48
  st.write("Temporary file path:", temp_file_path)
49
  with open(temp_file_path, "r") as f:
50
+ content = f.read()
51
+ st.write("Partial file content (first 500 characters):")
52
+ st.text(content[:500])
53
 
54
  # Tabs for LangChain and LlamaIndex
55
  tab1, tab2 = st.tabs(["LangChain", "LlamaIndex"])
56
 
57
+ # LangChain Tab with Proper FAISS Initialization
58
  with tab1:
59
  st.subheader("LangChain Query")
60
  try:
 
70
  if documents:
71
  st.text(documents[0]["page_content"])
72
 
73
+ # Create FAISS VectorStore with proper arguments
74
  langchain_index = faiss.IndexFlatL2(EMBED_DIMENSION)
75
+ docstore = InMemoryDocstore() # Create an in-memory docstore
76
+ index_to_docstore_id = {} # Mapping of index to document ID
77
  langchain_vector_store = LangChainFAISS(
78
  embedding_function=OpenAIEmbeddings(),
79
  index=langchain_index,
80
+ docstore=docstore,
81
+ index_to_docstore_id=index_to_docstore_id,
82
  )
83
  langchain_vector_store.add_documents(documents)
84