ZunairaHawwar commited on
Commit
1841f05
·
verified ·
1 Parent(s): 6b9c52a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -20,9 +20,9 @@ GROQ_MODEL = "llama3-8b-8192"
20
  # Initialize Groq client
21
  groq_client = Groq(api_key=GROQ_API_KEY)
22
 
 
23
  embedding_function = SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
24
 
25
-
26
  # Initialize ChromaDB Persistent Client
27
  chroma_client = chromadb.PersistentClient(path="./chroma_db", settings=Settings(anonymized_telemetry=False))
28
  collection = chroma_client.get_or_create_collection(
@@ -30,6 +30,13 @@ collection = chroma_client.get_or_create_collection(
30
  embedding_function=embedding_function
31
  )
32
 
 
 
 
 
 
 
 
33
  # --- Ingest JSON Files from /docs/ ---
34
  def ingest_docs_to_chroma():
35
  folder_path = "./docs"
@@ -48,7 +55,7 @@ def ingest_docs_to_chroma():
48
  st.write(f"Total chunks created: {len(chunks)}")
49
 
50
  # Clear existing vectors to avoid duplication
51
- collection.delete(where={})
52
 
53
  # Add Chunks to ChromaDB
54
  for chunk in chunks:
 
20
  # Initialize Groq client
21
  groq_client = Groq(api_key=GROQ_API_KEY)
22
 
23
+ # Initialize Chroma Embedding Function
24
  embedding_function = SentenceTransformerEmbeddingFunction(model_name="all-MiniLM-L6-v2")
25
 
 
26
  # Initialize ChromaDB Persistent Client
27
  chroma_client = chromadb.PersistentClient(path="./chroma_db", settings=Settings(anonymized_telemetry=False))
28
  collection = chroma_client.get_or_create_collection(
 
30
  embedding_function=embedding_function
31
  )
32
 
33
+ # --- Clear Collection ---
34
+ def clear_collection():
35
+ all_items = collection.get(include=["ids"])
36
+ if all_items and "ids" in all_items:
37
+ collection.delete(ids=all_items["ids"])
38
+ st.info(f"Cleared {len(all_items['ids'])} existing documents from ChromaDB.")
39
+
40
  # --- Ingest JSON Files from /docs/ ---
41
  def ingest_docs_to_chroma():
42
  folder_path = "./docs"
 
55
  st.write(f"Total chunks created: {len(chunks)}")
56
 
57
  # Clear existing vectors to avoid duplication
58
+ clear_collection()
59
 
60
  # Add Chunks to ChromaDB
61
  for chunk in chunks: