bharathmunakala commited on
Commit
37fc202
·
verified ·
1 Parent(s): 5d22a24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -126,39 +126,28 @@ def load_vector_index(role: str):
126
  input_type="search_document"
127
  )
128
  Settings.embed_model = embed_model
129
-
130
- # ✅ Use /tmp for Vercel/read-only filesystems
131
- if os.getenv("VERCEL") or os.access(".", os.W_OK) is False:
132
- persist_dir = os.path.join("/tmp", "chroma_db", role)
133
- else:
134
- persist_dir = os.path.join("chroma_db", role)
135
-
136
- os.makedirs(persist_dir, exist_ok=True)
137
-
138
  # Initialize Chroma client
 
139
  chroma_client = chromadb.PersistentClient(path=persist_dir)
140
-
141
- # Get or create collection
142
- try:
143
- chroma_collection = chroma_client.get_collection("documents")
144
- except chromadb.errors.NotFoundError:
145
- chroma_collection = chroma_client.create_collection("documents")
146
-
147
  # Create vector store
148
  vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
149
-
150
  # Create storage context
151
  storage_context = StorageContext.from_defaults(vector_store=vector_store)
152
-
153
  # Load the index
154
  index = VectorStoreIndex.from_vector_store(
155
  vector_store=vector_store,
156
  storage_context=storage_context,
157
  embed_model=embed_model
158
  )
159
-
160
  return index
161
-
162
  except Exception as e:
163
  st.error(f"Error loading vector index: {str(e)}")
164
  st.stop()
@@ -329,4 +318,4 @@ def main():
329
  chat_interface()
330
 
331
  if __name__ == "__main__":
332
- main()
 
126
  input_type="search_document"
127
  )
128
  Settings.embed_model = embed_model
129
+
 
 
 
 
 
 
 
 
130
  # Initialize Chroma client
131
+ persist_dir = f"./chroma_db/{role}"
132
  chroma_client = chromadb.PersistentClient(path=persist_dir)
133
+
134
+ # Get the collection
135
+ chroma_collection = chroma_client.get_collection("documents")
136
+
 
 
 
137
  # Create vector store
138
  vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
139
+
140
  # Create storage context
141
  storage_context = StorageContext.from_defaults(vector_store=vector_store)
142
+
143
  # Load the index
144
  index = VectorStoreIndex.from_vector_store(
145
  vector_store=vector_store,
146
  storage_context=storage_context,
147
  embed_model=embed_model
148
  )
149
+
150
  return index
 
151
  except Exception as e:
152
  st.error(f"Error loading vector index: {str(e)}")
153
  st.stop()
 
318
  chat_interface()
319
 
320
  if __name__ == "__main__":
321
+ main()