PearlIsa commited on
Commit
459f450
1 Parent(s): 02bf538

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -27
app.py CHANGED
@@ -453,33 +453,23 @@ class PearlyBot:
453
  - Professional limits"""
454
  }
455
 
456
- os.makedirs("knowledge_base", exist_ok=True)
457
-
458
- # Create and process documents
459
- documents = []
460
- for filename, content in knowledge_base.items():
461
- with open(f"knowledge_base/{filename}", "w") as f:
462
- f.write(content)
463
- documents.append(content)
464
-
465
- # Setup embeddings and vector store
466
- self.embeddings = HuggingFaceEmbeddings(
467
- model_name="sentence-transformers/all-MiniLM-L6-v2"
468
- )
469
-
470
- text_splitter = RecursiveCharacterTextSplitter(
471
- chunk_size=300,
472
- chunk_overlap=100
473
- )
474
-
475
- texts = text_splitter.split_text("\n\n".join(documents))
476
- self.vector_store = FAISS.from_texts(texts, self.embeddings)
477
- logger.info("RAG system setup complete")
478
-
479
- return knowledge_base
480
- except Exception as e:
481
- logger.error(f"Error setting up RAG: {str(e)}")
482
- raise
483
 
484
  def _validate_rag_setup(self):
485
  """Validate RAG system setup"""
 
453
  - Professional limits"""
454
  }
455
 
456
+ # Create knowledge base directory
457
+ os.makedirs("knowledge_base", exist_ok=True)
458
+
459
+ # Write files and process documents
460
+ documents = []
461
+ for filename, content in knowledge_base.items():
462
+ filepath = os.path.join("knowledge_base", filename)
463
+ with open(filepath, "w", encoding="utf-8") as f:
464
+ f.write(content)
465
+ documents.append(content)
466
+ logger.info(f"Written knowledge base file: {filename}")
467
+
468
+ return knowledge_base
469
+
470
+ except Exception as e:
471
+ logger.error(f"Error loading knowledge base: {str(e)}")
472
+ raise
 
 
 
 
 
 
 
 
 
 
473
 
474
  def _validate_rag_setup(self):
475
  """Validate RAG system setup"""