mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
More lenient date searching (#481)
* Modify DateFilter to use compiled entry key * Instruct search to include date in query * Minor prompt change * Prompt fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Standard Packages
|
# Standard Packages
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
@@ -70,6 +70,7 @@ def extract_questions(
|
|||||||
bob_age={current_new_year.year - 1984},
|
bob_age={current_new_year.year - 1984},
|
||||||
chat_history=chat_history,
|
chat_history=chat_history,
|
||||||
text=text,
|
text=text,
|
||||||
|
yesterday_date=(today - timedelta(days=1)).strftime("%Y-%m-%d")
|
||||||
)
|
)
|
||||||
messages = [ChatMessage(content=prompt, role="assistant")]
|
messages = [ChatMessage(content=prompt, role="assistant")]
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,12 @@ Q: What is their age difference?
|
|||||||
|
|
||||||
A: Bob is {bob_tom_age_difference} years older than Tom. As Bob is {bob_age} years old and Tom is 30 years old.
|
A: Bob is {bob_tom_age_difference} years older than Tom. As Bob is {bob_age} years old and Tom is 30 years old.
|
||||||
|
|
||||||
|
Q: What does yesterday's note say?
|
||||||
|
|
||||||
|
["Note from {yesterday_date} dt='{yesterday_date}'"]
|
||||||
|
|
||||||
|
A: Yesterday's note contains the following information: ...
|
||||||
|
|
||||||
{chat_history}
|
{chat_history}
|
||||||
Q: {text}
|
Q: {text}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class DateFilter(BaseFilter):
|
|||||||
# - dt:"2 years ago"
|
# - dt:"2 years ago"
|
||||||
date_regex = r"dt([:><=]{1,2})[\"'](.*?)[\"']"
|
date_regex = r"dt([:><=]{1,2})[\"'](.*?)[\"']"
|
||||||
|
|
||||||
def __init__(self, entry_key="raw"):
|
def __init__(self, entry_key="compiled"):
|
||||||
self.entry_key = entry_key
|
self.entry_key = entry_key
|
||||||
self.date_to_entry_ids = defaultdict(set)
|
self.date_to_entry_ids = defaultdict(set)
|
||||||
self.cache = LRU()
|
self.cache = LRU()
|
||||||
|
|||||||
Reference in New Issue
Block a user