Revert "fix: truncate oversized text in embedding requests" (#9227)

Revert "fix: truncate oversized text in embedding requests (#9196)"

This reverts commit a9c342087e022519c63d62fb76b72aed8859539b.
This commit is contained in:
Kian Jones
2026-01-30 16:35:21 -08:00
committed by Caren Thomas
parent 68eb076135
commit 01cb00ae10
3 changed files with 25 additions and 303 deletions

View File

@@ -203,99 +203,3 @@ async def test_openai_embedding_minimum_chunk_failure(default_user):
with pytest.raises(Exception, match="API error"):
await client.request_embeddings(test_inputs, embedding_config)
def test_split_text_in_half():
"""Test the _split_text_in_half helper function."""
from letta.helpers.tpuf_client import _split_text_in_half
# Test with text that has sentence boundaries
long_text = "This is a test sentence. " * 100
splits = _split_text_in_half(long_text)
assert len(splits) == 2
assert len(splits[0]) > 0
assert len(splits[1]) > 0
# Should split at a sentence boundary
assert splits[0].endswith(".")
# Test with text that has no good break points
no_breaks = "a" * 1000
splits = _split_text_in_half(no_breaks)
assert len(splits) == 2
assert len(splits[0]) + len(splits[1]) == 1000
# Test with empty text
splits = _split_text_in_half("")
assert splits == []
# Test with short text (still splits)
short_text = "hello world"
splits = _split_text_in_half(short_text)
assert len(splits) == 2
def test_chunked_message_query_deduplication():
"""Test that chunked messages are deduplicated by message_id in query results."""
from unittest.mock import MagicMock
from letta.helpers.tpuf_client import TurbopufferClient
# Create a mock result with multiple chunks from the same message
mock_result = MagicMock()
# Simulate 3 rows: 2 chunks from message-1, 1 chunk from message-2
# The chunks are ranked by relevance (row order = rank order)
row1 = MagicMock()
row1.id = "message-1_chunk_1" # Second chunk of message-1, but ranked first
row1.message_id = "message-1"
row1.chunk_index = 1
row1.text = "chunk 1 text"
row1.organization_id = "org-1"
row1.agent_id = "agent-1"
row1.role = "user"
row1.created_at = None
row1.conversation_id = None
row2 = MagicMock()
row2.id = "message-2"
row2.message_id = "message-2"
row2.chunk_index = 0
row2.text = "message 2 text"
row2.organization_id = "org-1"
row2.agent_id = "agent-1"
row2.role = "assistant"
row2.created_at = None
row2.conversation_id = None
row3 = MagicMock()
row3.id = "message-1" # First chunk of message-1, but ranked third
row3.message_id = "message-1"
row3.chunk_index = 0
row3.text = "chunk 0 text"
row3.organization_id = "org-1"
row3.agent_id = "agent-1"
row3.role = "user"
row3.created_at = None
row3.conversation_id = None
mock_result.rows = [row1, row2, row3]
# Process results with deduplication
client = TurbopufferClient.__new__(TurbopufferClient) # Create without __init__
results = client._process_message_query_results(mock_result, deduplicate=True)
# Should have 2 messages (message-1 deduplicated)
assert len(results) == 2
# First result should be message-1 (from the best-ranked chunk)
assert results[0]["id"] == "message-1"
assert results[0]["text"] == "chunk 1 text" # Text from best-ranked chunk
assert results[0]["chunk_index"] == 1
# Second result should be message-2
assert results[1]["id"] == "message-2"
assert results[1]["text"] == "message 2 text"
# Test without deduplication
results_no_dedup = client._process_message_query_results(mock_result, deduplicate=False)
assert len(results_no_dedup) == 3 # All rows returned