Python: Bug: split_plaintext_paragraph / split_markdown_paragraph can return a chunk larger than max_tokens
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 75/100
Línea de trabajo
Lee python/semantic_kernel/text/text_chunker.py, especialmente _split_text_paragraph cerca de las líneas enlazadas, e inspecciona tests/unit/text/test_text_chunker.py. Ejecuta primero las pruebas del text chunker; actualiza el comportamiento de combinación y los resultados esperados afectados para que el último chunk solo se combine cuando token_counter confirme que cabe. Se considera terminado cuando ningún chunk devuelto supera max_tokens y pasan las pruebas pertinentes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
split_plaintext_paragraph and split_markdown_paragraph can return a paragraph whose token count is above max_tokens.
At the end of _split_text_paragraph, a short last paragraph is merged into the previous one. The merge check counts words (len(paragraph.split(" "))) instead of calling token_counter:
A word is usually more than one token, so the merged paragraph can go over the limit even though the word count is under it. This matters when max_tokens is the embedding model's input limit.
To Reproduce
With the default token counter, using the input of the existing test_split_text_paragraph_evenly test:
from semantic_kernel.text import split_plaintext_paragraph
text = [
"This is a test of the emergency broadcast system. This is only a test.",
"We repeat, this is only a test. A unit test.",
"A small note. And another. And once again. Seriously, this is the end. We're finished. All set. Bye.",
"Done.",
]
chunks = split_plaintext_paragraph(text, 15)
print([len(c) // 4 for c in chunks]) # [12, 5, 11, 10, 16] -> last chunk is 16 tokens, limit is 15
With a real tokenizer (tiktoken, cl100k_base) passed as token_counter, on generated multi-line English text and limits from 64 to 512, 955 of 8000 runs (about 12%) returned an over-limit chunk. The worst one was 314 tokens for max_tokens=256.
Expected behavior
No returned paragraph is above max_tokens. The last paragraph should only be merged into the previous one if the merged text fits, measured with token_counter.
Platform
- Language: Python
- Source:
mainat cc8a15fa3 - OS: Windows 11, Python 3.12
Additional context
Eight existing unit tests in tests/unit/text/test_text_chunker.py expect an over-limit last chunk (for example 16 tokens with max_token_per_line = 15). A fix would change their expected output, so I wanted to raise it here first. I have a small fix with tests ready and I'm happy to open the PR.
- Lenguaje dominante
- C#
- Estrellas
- 28.7k
- Forks
- 4.8k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 22
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/semantic-kernel
-
Python: Bug: Anthropic, Bedrock, Google AI and Vertex AI tool formatters ignore include_in_function_choices=FalsePosiblemente ocupada @wasim-builds la tomó hace 2 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
microsoft/semantic-kernel#14615 ·
Los mantenedores suelen responder en 3 días
-
Python: Bug: AnnotationContent and StreamingAnnotationContent to_element writes CitationType.X, so annotations in a rendered chat history fail to parsePosiblemente ocupada @CRYPTONIKAV la tomó hace 6 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/semantic-kernel#14590 ·
Los mantenedores suelen responder en 3 días
-
Python: Bug: TimePlugin timeZoneOffset and timeZoneName always return an empty stringPosiblemente ocupada @jeevan1098 la tomó hace 4 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
microsoft/semantic-kernel#14583 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
.Net: gpt-image-1 is the default image model in the .NET OpenAI connector, and OpenAI shuts it down on October 23Posiblemente ocupada @nightcityblade la tomó hace 17 días. Abierto.NET triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
microsoft/semantic-kernel#14526 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
Python: VolatileMemoryStore.get_batch and get_nearest_matches ignore with_embeddings=False (deepcopy result is discarded)Posiblemente ocupada @VANDRANKI la tomó hace 18 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/semantic-kernel#14522 ·
Los mantenedores suelen responder en 3 días
Todos los issues de microsoft/semantic-kernel
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
gavin-wolfe/wolfden#104 ·
Los mantenedores suelen responder en 1 día
-
[BUG] Still libmicrohttpd dependency is not removed properly from External-Dependency-Info.txt fileAbiertotype/bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[辞書] かんそうりつ->乾燥率Abierto辞書
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
thomhurst/TUnit#7201 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
ArduPilot/MissionPlanner#3826 ·
Los mantenedores suelen responder en 1 día