[Question]: GPT and Simple KeywordTableRetriever won't respond to keyword template #8382
Replies: 3 comments
-
Answer generated by a 🤖 AnswerHello, Thank you for your detailed question. It seems like you're having trouble with the KeywordTableGPTRetriever not extracting the keywords you expect, especially when it comes to dates. The KeywordTableGPTRetriever uses a GPT model to predict the response to the query and then extracts keywords from this response. The The response from the GPT model is then passed to the If you're finding that the KeywordTableGPTRetriever is not extracting dates as expected, you might want to modify the Here is an example of how you can modify the from dateutil.parser import parse
import re
def _extract_keywords(self, text: str) -> Set[str]:
"""Extract keywords from text."""
response = self._service_context.llm_predictor.predict(
self.keyword_extract_template,
text=text,
)
keywords = extract_keywords_given_response(response, start_token="KEYWORDS:")
# Custom function to extract dates
def extract_dates(text):
matches = re.findall(r'\b\d{1,2}[/-]\d{1,2}[/-]\d{4}\b', text)
dates = [parse(match) for match in matches]
return dates
dates = extract_dates(response)
keywords.update(dates)
return keywords In this example, the Please note that this is just an example and the actual implementation might need to be adjusted based on the specific requirements of your application. For instance, you might need to adjust the regular expression to match the date format used in your data, or use a different method to extract dates if they are not in a standard format. I hope this helps! Let me know if you have any other questions. SourcesThis response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
-
Could someone please tell me where these keywords are dropping off and how to fix this??
|
Beta Was this translation helpful? Give feedback.
-
Answer generated by a 🤖 AnswerHello, Based on the logs and code snippet you've provided, it seems like all the keywords are being correctly identified and extracted in the This discrepancy could be due to the filtering process that happens in the To resolve this issue, you can ensure that all the necessary keywords are present in your index structure. If a keyword is important but not present in the index structure, you might need to update your index. Additionally, you might want to check the Here's how you can adjust the class CustomKeywordTableGPTRetriever(BaseKeywordTableRetriever):
"""Custom Keyword Table GPT Retriever."""
def __init__(self, index, max_keywords_per_query=20): # Increase this value
super().__init__(index)
self.max_keywords_per_query = max_keywords_per_query Remember to re-index your data if you make changes to the keyword extraction method or the I hope this helps! Let me know if you have any other questions. Sources
This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
-
Question Validation
Question
I am trying to use a KeywordTableRetriever to combine vector and keyword search. My keyword retriever will not extract important keywords, specifically dates, even when I use a keyword prompt template to do so. Is there a way to give more direct guidance to the KeywordTableGPTRetriever? Has anyone also come across this problem?
When I ask a question that does not have a month (or date) in the query, the keywords are months. Seems like the KeywordTableGPTRetriever is interpreting my prompt in a strange way.
When I just say the phrase "February 2023," there are no keywords fetched.
Interestingly, when I ask "What date did we discuss x?" it's able to answer pretty well.
Beta Was this translation helpful? Give feedback.
All reactions