Skip to content

Upgrade OpenTelemetry and Azure packages to latest compatible versions #2634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ celerybeat.pid
# Environments
.env
.venv
.venv_*
.evalenv
env/
venv/
Expand Down
12 changes: 10 additions & 2 deletions app/backend/prepdocslib/textsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ def split_pages(self, pages: list[Page]) -> Generator[SplitPage, None, None]:
CJK_SENTENCE_ENDINGS = ["。", "!", "?", "‼", "⁇", "⁈", "⁉"]

# NB: text-embedding-3-XX is the same BPE as text-embedding-ada-002
bpe = tiktoken.encoding_for_model(ENCODING_MODEL)
_bpe = None


def get_encoding():
"""Get the tiktoken encoding, loading it lazily when first needed."""
global _bpe
if _bpe is None:
_bpe = tiktoken.encoding_for_model(ENCODING_MODEL)
return _bpe

DEFAULT_OVERLAP_PERCENT = 10 # See semantic search article for 10% overlap performance
DEFAULT_SECTION_LENGTH = 1000 # Roughly 400-500 tokens for English
Expand All @@ -99,7 +107,7 @@ def split_page_by_max_tokens(self, page_num: int, text: str) -> Generator[SplitP
"""
Recursively splits page by maximum number of tokens to better handle languages with higher token/word ratios.
"""
tokens = bpe.encode(text)
tokens = get_encoding().encode(text)
if len(tokens) <= self.max_tokens_per_section:
# Section is already within max tokens, return
yield SplitPage(page_num=page_num, text=text)
Expand Down
Loading
Loading