Skip to content

Commit b589d9f

Browse files
committed
using set
1 parent b2c6eb8 commit b589d9f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

backend/apps/ai/common/base/chunk_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def process_chunks_batch(self, entities: list[Model]) -> int:
5858
continue
5959

6060
chunk_texts = Chunk.split_text(full_content)
61-
unique_chunk_texts = list(dict.fromkeys(chunk_texts))
61+
unique_chunk_texts = list(set(chunk_texts))
6262

6363
if not unique_chunk_texts:
6464
self.stdout.write(f"No chunks created for {self.entity_name} {entity_key}")

backend/tests/apps/ai/common/base/chunk_command_test.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ def test_process_chunks_batch_success(
221221
result = command.process_chunks_batch([mock_entity])
222222

223223
assert result == 1
224-
mock_create_chunks.assert_called_once_with(
225-
chunk_texts=["chunk1", "chunk2", "chunk3"],
226-
context=mock_context,
227-
openai_client=command.openai_client,
228-
save=False,
229-
)
224+
_, kwargs = mock_create_chunks.call_args
225+
assert set(kwargs["chunk_texts"]) == {"chunk1", "chunk2", "chunk3"}
226+
assert kwargs["context"] == mock_context
227+
assert kwargs["openai_client"] == command.openai_client
228+
assert kwargs["save"] is False
230229
mock_bulk_save.assert_called_once_with(mock_chunks)
231230
mock_write.assert_has_calls(
232231
[
@@ -461,12 +460,11 @@ def test_process_chunks_batch_with_duplicates(
461460

462461
assert result == 1
463462
mock_split_text.assert_called_once()
464-
mock_create_chunks.assert_called_once_with(
465-
chunk_texts=["chunk1", "chunk2", "chunk3"],
466-
context=mock_context,
467-
openai_client=command.openai_client,
468-
save=False,
469-
)
463+
_, kwargs = mock_create_chunks.call_args
464+
assert set(kwargs["chunk_texts"]) == {"chunk1", "chunk2", "chunk3"}
465+
assert kwargs["context"] == mock_context
466+
assert kwargs["openai_client"] == command.openai_client
467+
assert kwargs["save"] is False
470468
mock_bulk_save.assert_called_once_with(mock_chunks)
471469

472470
def test_process_chunks_batch_whitespace_only_content(

0 commit comments

Comments
 (0)