hash-map commited on
Commit
f786957
·
verified ·
1 Parent(s): fc40709

Update rag.py

Browse files
Files changed (1) hide show
  1. rag.py +9 -13
rag.py CHANGED
@@ -34,7 +34,7 @@ loader = DirectoryLoader('.', glob="all_dialogues.txt")
34
  docs = loader.load()
35
 
36
  text_splitter = RecursiveCharacterTextSplitter(
37
- chunk_size=1000, chunk_overlap=200
38
  )
39
  texts = text_splitter.split_documents(docs)
40
  embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
@@ -49,7 +49,7 @@ db = FAISS.load_local(
49
 
50
 
51
  # Vector Store Retriever
52
- vector_retriever = db.as_retriever(search_kwargs={"k": 5})
53
 
54
  # Keyword Retriever (BM25)
55
  bm25_retriever = BM25Retriever.from_documents(texts)
@@ -76,24 +76,20 @@ def respond_rag_huggingface(message: str):
76
  context = "\n\n".join(doc.page_content for doc in docs)
77
 
78
  system_message = os.environ.get("SYSTEM_MESSAGE",
79
- "You are a Game of Thrones measter and harry potter's dumbledore"+
80
- ". Answer the given question based on the context understand the context and try to answer based upon the context.do not give faulty answers and if any dialogue or description mention them ")
 
 
81
 
82
  prompt = f"""{system_message}
83
-
84
- Context:
85
- {context}
86
-
87
  Question:
88
  {message}
89
-
90
  Rules:
91
- - If the answer isn't in the context, respond with something you know about them and do not mention about about context
92
- - try to say that i exactly mean different than i do not know
93
  - Keep answers under 5 sentences
94
  - Include book/season references when possible
95
- - vector store contains both game of thrones and harry potter vectors so answer based on relevant context
96
-
97
  """
98
 
99
  response = model.generate_content(prompt)
 
34
  docs = loader.load()
35
 
36
  text_splitter = RecursiveCharacterTextSplitter(
37
+ chunk_size=300, chunk_overlap=100
38
  )
39
  texts = text_splitter.split_documents(docs)
40
  embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
 
49
 
50
 
51
  # Vector Store Retriever
52
+ vector_retriever = db.as_retriever(search_kwargs={"k": 10})
53
 
54
  # Keyword Retriever (BM25)
55
  bm25_retriever = BM25Retriever.from_documents(texts)
 
76
  context = "\n\n".join(doc.page_content for doc in docs)
77
 
78
  system_message = os.environ.get("SYSTEM_MESSAGE",
79
+ "You are a Game of Thrones maester and Harry Potter's Dumbledore. " +
80
+ "Answer the given question based on your knowledge, providing accurate details without mentioning any specific sources or context used. " +
81
+ "State how much you know about the topic, and do not provide faulty answers. " +
82
+ "If the answer is unclear, clarify what you mean rather than saying 'I do not know.'")
83
 
84
  prompt = f"""{system_message}
 
 
 
 
85
  Question:
86
  {message}
 
87
  Rules:
88
+ - Do not mention the context or where the information comes from
89
+ - State how much you know about the topic (e.g., 'I have detailed knowledge,' 'I have some knowledge,' or 'My knowledge is limited')
90
  - Keep answers under 5 sentences
91
  - Include book/season references when possible
92
+ - Answer based on relevant knowledge from Game of Thrones and Harry Potter
 
93
  """
94
 
95
  response = model.generate_content(prompt)