Spaces:
Running
Running
Daniel Foley
commited on
Commit
·
d1935d1
1
Parent(s):
3e602d9
removed prompt alignment
Browse files
RAG.py
CHANGED
@@ -122,38 +122,38 @@ def RAG(llm: Any, query: str,vectorstore:PineconeVectorStore, top: int = 10, k:
|
|
122 |
"""Main RAG function with improved error handling and validation."""
|
123 |
start = time.time()
|
124 |
try:
|
125 |
-
# Retrieve initial documents using rephrased query
|
126 |
-
query_template = PromptTemplate.from_template(
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
|
136 |
-
|
137 |
|
138 |
-
|
139 |
|
140 |
-
|
141 |
|
142 |
-
|
143 |
|
144 |
-
|
145 |
|
146 |
-
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
)
|
151 |
-
query_prompt = query_template.invoke({"query":query})
|
152 |
-
query_response = llm.invoke(query_prompt)
|
153 |
-
new_query = parse_xml_and_query(query=query,xml_string=query_response.content)
|
154 |
-
logging.info(f"Old_Query: {query},New_Query: {new_query}")
|
155 |
|
156 |
-
retrieved, _ = retrieve(query=
|
157 |
if not retrieved:
|
158 |
return "No documents found for your query.", []
|
159 |
|
|
|
122 |
"""Main RAG function with improved error handling and validation."""
|
123 |
start = time.time()
|
124 |
try:
|
125 |
+
# Retrieve initial documents using rephrased query -- not working as intended currently, maybe would be better for data with more words.
|
126 |
+
# query_template = PromptTemplate.from_template(
|
127 |
+
# """
|
128 |
+
# Your job is to think about a query and then generate a statement that only includes information from the query that would answer the query.
|
129 |
+
# You will be provided with a query in <QUERY></QUERY> tags.
|
130 |
+
# Then you will think about what kind of information the query is looking for between <REASONING></REASONING> tags.
|
131 |
+
# Then, based on the reasoning, you will generate a sample response to the query that only includes information from the query between <STATEMENT></STATEMENT> tags.
|
132 |
+
# Afterwards, you will determine and reason about whether or not the statement you generated only includes information from the original query and would answer the query between <DETERMINATION></DETERMINATION> tags.
|
133 |
+
# Finally, you will return a YES, or NO response between <VALID></VALID> tags based on whether or not you determined the statment to be valid.
|
134 |
+
# Let me provide you with an exmaple:
|
135 |
|
136 |
+
# <QUERY>I would really like to learn more about Bermudan geography<QUERY>
|
137 |
|
138 |
+
# <REASONING>This query is interested in geograph as it relates to Bermuda. Some things they might be interested in are Bermudan climate, towns, cities, and geography</REASONING>
|
139 |
|
140 |
+
# <STATEMENT>Bermuda's Climate is [blank]. Some of Bermuda's cities and towns are [blank]. Other points of interested about Bermuda's geography are [blank].</STATEMENT>
|
141 |
|
142 |
+
# <DETERMINATION>The query originally only mentions bermuda and geography. The answers do not provide any false information, instead replacing meaningful responses with a placeholder [blank]. If it had hallucinated, it would not be valid. Because the statements do not hallucinate anything, this is a valid statement.</DETERMINATION>
|
143 |
|
144 |
+
# <VALID>YES</VALID>
|
145 |
|
146 |
+
# Now it's your turn! Remember not to hallucinate:
|
147 |
|
148 |
+
# <QUERY>{query}</QUERY>
|
149 |
+
# """
|
150 |
+
# )
|
151 |
+
# query_prompt = query_template.invoke({"query":query})
|
152 |
+
# query_response = llm.invoke(query_prompt)
|
153 |
+
# new_query = parse_xml_and_query(query=query,xml_string=query_response.content)
|
154 |
+
# logging.info(f"Old_Query: {query},New_Query: {new_query}")
|
155 |
|
156 |
+
retrieved, _ = retrieve(query=query, vectorstore=vectorstore, k=k)
|
157 |
if not retrieved:
|
158 |
return "No documents found for your query.", []
|
159 |
|