Skip to content

added support for MAX_INPUT_TOKENS #61

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions api/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def append_dialog_turn(self, dialog_turn):
logger = logging.getLogger(__name__)

# Maximum token limit for embedding models
MAX_INPUT_TOKENS = 7500 # Safe threshold below 8192 token limit
MAX_INPUT_TOKENS = 3400 # Adjusted for embedding model with 4096 token limit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a comment explaining why the token limit was adjusted to 3400. This will help future developers understand the reasoning behind this specific value.

Style Guide References

Suggested change
MAX_INPUT_TOKENS = 3400 # Adjusted for embedding model with 4096 token limit
MAX_INPUT_TOKENS = 3400 # Adjusted for embedding model with 4096 token limit. Testing indicates best performance at this level.


class Memory(adal.core.component.DataComponent):
"""Simple conversation management with a list of dialog turns."""
Expand Down Expand Up @@ -232,7 +232,10 @@ def __init__(self, use_s3: bool = False, local_ollama: bool = False): # noqa: F
# --- Initialize Embedder ---
self.embedder = adal.Embedder(
model_client=embedder_config["model_client"](),
model_kwargs=embedder_config["model_kwargs"],
model_kwargs={
**embedder_config["model_kwargs"],
"max_input_tokens": MAX_INPUT_TOKENS, # Use the configured token limit
},
Comment on lines +235 to +238

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good that you're passing the MAX_INPUT_TOKENS to the embedder. Consider adding a brief comment explaining why this is important, such as preventing exceeding the model's token limit.

Style Guide References

Suggested change
model_kwargs={
**embedder_config["model_kwargs"],
"max_input_tokens": MAX_INPUT_TOKENS, # Use the configured token limit
},
model_kwargs={
**embedder_config["model_kwargs"],
"max_input_tokens": MAX_INPUT_TOKENS, # Prevents exceeding model's token limit
},

)

# Patch: ensure query embedding is always single string for Ollama
Expand Down