Spaces:
Running
Running
Update rag.py
Browse files
rag.py
CHANGED
@@ -31,15 +31,15 @@ GREETINGS = [
|
|
31 |
try:
|
32 |
with open('dataset.json', 'r') as f:
|
33 |
dataset = json.load(f)
|
34 |
-
if not all(isinstance(item, dict) and '
|
35 |
raise ValueError("Invalid dataset structure")
|
36 |
except Exception as e:
|
37 |
print(f"Error loading dataset: {e}")
|
38 |
dataset = []
|
39 |
|
40 |
# Precompute embeddings
|
41 |
-
dataset_questions = [item.get("
|
42 |
-
dataset_answers = [item.get("
|
43 |
dataset_embeddings = similarity_model.encode(dataset_questions, convert_to_tensor=True)
|
44 |
|
45 |
# Save unmatched queries to Hugging Face
|
|
|
31 |
try:
|
32 |
with open('dataset.json', 'r') as f:
|
33 |
dataset = json.load(f)
|
34 |
+
if not all(isinstance(item, dict) and 'input' in item and 'response' in item for item in dataset):
|
35 |
raise ValueError("Invalid dataset structure")
|
36 |
except Exception as e:
|
37 |
print(f"Error loading dataset: {e}")
|
38 |
dataset = []
|
39 |
|
40 |
# Precompute embeddings
|
41 |
+
dataset_questions = [item.get("input", "").lower().strip() for item in dataset]
|
42 |
+
dataset_answers = [item.get("response", "") for item in dataset]
|
43 |
dataset_embeddings = similarity_model.encode(dataset_questions, convert_to_tensor=True)
|
44 |
|
45 |
# Save unmatched queries to Hugging Face
|