Skip to content
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

Refactor Prompt Builder for Efficient DataChunk Processing and Memory Optimization #42

Open
dorbanianas opened this issue Oct 26, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@dorbanianas
Copy link
Member

dorbanianas commented Oct 26, 2024

The current prompt_builder.cpp implementation in src/core/functions requires several optimizations and refactoring steps to improve efficiency and memory usage when processing DataChunks. Below are the main issues identified:

  1. Function Naming and Parameter Handling:

    • Rename GetMaxLengthValues to GetMaxTokenLengthPerAttribute for better clarity.
    • Optimization: Update this function to find max token length directly over the DataChunk vectors, bypassing JSON-related overhead.
  2. Concatenation and String Allocation:

    • In CombineValues, while += concatenation is currently manageable, the approach could be improved by allocating the full string size upfront to prevent reallocation overhead. This is especially relevant as the code is likely to be reused in scenarios with aggregate data handling.
    • Loop Optimization: Remove pop_back usage for trimming the last space after concatenation. Instead, concatenate up to N-1 times and handle the last item separately, reducing unnecessary operations.
  3. DataChunk to JSON Transformation:

    • Avoid mapping entire DataChunks to JSON before chunking. Although JSON is currently used as a temporary solution, the goal is to remove this dependency.
    • For efficient memory handling, calculate and set the maximum number of tuples per LLM request based on token size limits, allocating memory in advance on the stack.
  4. Prompt Rendering and Inja Removal:

    • In the long term, replace Inja for prompt rendering. Implement a custom rendering solution directly with DataChunks to avoid intermediary JSON representations and reduce memory usage.
@dorbanianas dorbanianas added the enhancement New feature or request label Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant