1 view
In the RAG pipeline for GigaChat, a long document is first tokenized and then split into chunks of a fixed length. There are 5 standard chunk sizes available: 1, 3, 6, 10, and 15 tokens. What is the minimum number of chunks into which a document of n tokens can be split? ```python def min_context_chunks(n_tokens: int) -> int: ```
Asked at
AI answer
def min_context_chunks(n_tokens: int) -> int:
if n_tokens < 0:
raise ValueError("n_tokens must be non-negative")
sizes = (1, 3, 6, 10, 15)
# dp[i] — the minimum number of chunks for a document with i tokens.
dp = [0] + [n_tokens + 1] * n_tokens
for i in range(1, n_tokens + 1):
dp[i] = 1 + min(dp[i - size] for size in sizes if size <= i)
return dp[n_tokens]
Dynamic programming checks all allowed chunk sizes. The complexity is O(5n), and the space complexity is O(n). For a document with 0 tokens, the result is 0.
Also asked at СБЕР
- Do you have any questions about the company and the role?
- Tell us about your experience: on which projects you worked at [company] and [company], what technologies you used, and what you were responsible for?
- Tell us about yourself: how did you come into development, what teams and products have you worked on, what functionality did you perform?
- What databases have you had to work with as a developer?
- Tell me about the product/project you worked on and your main tasks.
Similar questions
- Why does RAG search over a contract split into 200-character chunks with no overlap fail to find the relevant penalty clause and instead return the header and details?
- What is the purpose of chunking? How are chunks vectorized?
- How would you create a chunking-agnostic eval benchmark (a benchmark that does not depend on how the text is split into chunks)?
- What algorithm would you use to make fact retrieval across chunks robust when a fact may be split across a chunk boundary?
- Design an architecture for an enterprise GPT (a chat with an LLM and document uploads for RAG) for 5,000 users per week.