Skip to content

Commit 44f8299

Browse files
committed
fix: optimize junk pattern matching and improve quality sentence check
1 parent 62ce981 commit 44f8299

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

vektori/ingestion/filter.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,36 @@
9292
}
9393

9494
JUNK_PATTERNS = [
95-
r"^(ok|okay|sure|yes|no|yeah|yep|nope|hmm|hm|ah|oh|uh|um|lol|haha|thanks|thank you|got it|right|cool|nice|great|fine|alright)\s*[.!?]*$",
96-
r"^(hey|hi|hello|bye|goodbye|cheers|ciao)\s*[.!?]*$",
95+
re.compile(r"^(ok|okay|sure|yes|no|yeah|yep|nope|hmm|hm|ah|oh|uh|um|lol|haha|thanks|thank you|got it|right|cool|nice|great|fine|alright)\s*[.!?]*$", re.IGNORECASE),
96+
re.compile(r"^(hey|hi|hello|bye|goodbye|cheers|ciao)\s*[.!?]*$", re.IGNORECASE),
9797
# web/social media cruft
98-
r"©\s*\d{4}",
99-
r"(terms of service|privacy policy|cookie policy|accessibility|all rights reserved)",
100-
r"^\s*(trending|trending now|what'?s happening)\s*$",
101-
r"^\d[\d,\.]+\s*(views|likes|retweets|replies|reposts|followers|following)\s*$",
102-
r"^(show more|load more|see more|view more|read more)\s*[.!?]*$",
103-
r"(sports\s*·\s*trending|entertainment\s*·\s*trending|news\s*·\s*trending)",
104-
r"^relevant\s+(people|chats|posts)\s*$",
98+
re.compile(r"©\s*\d{4}", re.IGNORECASE),
99+
re.compile(r"(terms of service|privacy policy|cookie policy|accessibility|all rights reserved)", re.IGNORECASE),
100+
re.compile(r"^\s*(trending|trending now|what'?s happening)\s*$", re.IGNORECASE),
101+
re.compile(r"^\d[\d,\.]+\s*(views|likes|retweets|replies|reposts|followers|following)\s*$", re.IGNORECASE),
102+
re.compile(r"^(show more|load more|see more|view more|read more)\s*[.!?]*$", re.IGNORECASE),
103+
re.compile(r"(sports\s*·\s*trending|entertainment\s*·\s*trending|news\s*·\s*trending)", re.IGNORECASE),
104+
re.compile(r"^relevant\s+(people|chats|posts)\s*$", re.IGNORECASE),
105105
# pipe-separated nav lists (e.g. "Terms | Privacy | Cookie")
106-
r"^[^|]{1,40}\|[^|]{1,40}\|",
106+
re.compile(r"^[^|]{1,40}\|[^|]{1,40}\|", re.IGNORECASE),
107107
]
108108

109109
CODE_PATTERNS = [
110-
r"[{}\[\]<>].*[{}\[\]<>]",
111-
r"^(import |from |def |class |const |let |var |function )",
112-
r"[a-zA-Z0-9+/]{40,}",
113-
r"^(/|\\|[A-Z]:\\)",
114-
r"https?://\S{50,}",
110+
re.compile(r"[{}\[\]<>].*[{}\[\]<>]"),
111+
re.compile(r"^(import |from |def |class |const |let |var |function )"),
112+
re.compile(r"[a-zA-Z0-9+/]{40,}"),
113+
re.compile(r"^(/|\\|[A-Z]:\\)"),
114+
re.compile(r"https?://\S{50,}"),
115115
]
116116

117117
META_PATTERNS = [
118-
r"^(just for context|for reference|fyi|note:|update:)",
119-
r":$",
120-
r"^(explain|tell me about|describe|show me|help me with)\s",
118+
re.compile(r"^(just for context|for reference|fyi|note:|update:)", re.IGNORECASE),
119+
re.compile(r":$"),
120+
re.compile(r"^(explain|tell me about|describe|show me|help me with)\s", re.IGNORECASE),
121121
]
122122

123123

124-
def is_quality_sentence(text: str, config: QualityConfig = QualityConfig()) -> bool:
124+
def is_quality_sentence(text: str, config: QualityConfig | None = None) -> bool:
125125
"""
126126
10-layer quality gauntlet. Returns True if sentence should be stored.
127127
@@ -130,6 +130,9 @@ def is_quality_sentence(text: str, config: QualityConfig = QualityConfig()) -> b
130130
131131
Pass config.enabled=False to store everything (some use cases want this).
132132
"""
133+
if config is None:
134+
config = QualityConfig()
135+
133136
if not config.enabled:
134137
return True
135138

@@ -143,17 +146,17 @@ def is_quality_sentence(text: str, config: QualityConfig = QualityConfig()) -> b
143146
# 2. Junk / filler / acknowledgments
144147
text_lower = text_clean.lower().strip(".,!? ")
145148
for pattern in JUNK_PATTERNS:
146-
if re.match(pattern, text_lower, re.IGNORECASE):
149+
if pattern.match(text_lower):
147150
return False
148151

149152
# 3. Code / credentials / file paths
150153
for pattern in CODE_PATTERNS:
151-
if re.search(pattern, text_clean):
154+
if pattern.search(text_clean):
152155
return False
153156

154157
# 4. Meta-text / vague commands
155158
for pattern in META_PATTERNS:
156-
if re.match(pattern, text_lower, re.IGNORECASE):
159+
if pattern.match(text_lower):
157160
return False
158161

159162
# 5. Pronoun-heavy fragments (likely context-free without surrounding text)

vektori/ingestion/pipeline.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ async def ingest(
7373
continue
7474
raw_sents = split_sentences(msg["content"])
7575
for idx, text in enumerate(raw_sents):
76-
if not self.quality_config.enabled or is_quality_sentence(
77-
text, self.quality_config
78-
):
76+
if is_quality_sentence(text, self.quality_config):
7977
all_sentences.append(
8078
{
8179
"text": text,

0 commit comments

Comments
 (0)