test_chunking.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import annotations
  2. def test_chunks_are_deterministic_and_trace_back_to_points():
  3. from app.core.knowledge.chunking import build_chunks
  4. from app.core.knowledge.point_builder import build_knowledge_snapshot
  5. snapshot = build_knowledge_snapshot(
  6. "DataFlow",
  7. {
  8. "uid": "01900000-0000-7000-8000-000000000901",
  9. "version": 1,
  10. "name": "sync",
  11. "purpose": "sync customer data",
  12. "owner": "governance",
  13. },
  14. )
  15. first = build_chunks(snapshot)
  16. second = build_chunks(snapshot)
  17. assert first == second
  18. assert len(first) == len(snapshot.points)
  19. assert all(chunk.point_keys == (chunk.primary_point_key,) for chunk in first)
  20. assert {chunk.primary_point_key for chunk in first} == {
  21. point.point_key for point in snapshot.points
  22. }
  23. def test_embedding_input_hash_changes_with_profile_but_not_source_revision():
  24. from app.core.knowledge.chunking import build_chunks, embedding_input_hash
  25. from app.core.knowledge.point_builder import build_knowledge_snapshot
  26. first_snapshot = build_knowledge_snapshot(
  27. "DataFlow",
  28. {
  29. "uid": "01900000-0000-7000-8000-000000000902",
  30. "version": 1,
  31. "purpose": "same purpose",
  32. },
  33. )
  34. second_snapshot = build_knowledge_snapshot(
  35. "DataFlow",
  36. {
  37. "uid": "01900000-0000-7000-8000-000000000902",
  38. "version": 2,
  39. "purpose": "same purpose",
  40. },
  41. )
  42. first_chunk = build_chunks(first_snapshot)[0]
  43. second_chunk = build_chunks(second_snapshot)[0]
  44. assert first_chunk.content_hash == second_chunk.content_hash
  45. assert embedding_input_hash(first_chunk, "qwen:1024:v1") == embedding_input_hash(
  46. second_chunk, "qwen:1024:v1"
  47. )
  48. assert embedding_input_hash(first_chunk, "qwen:1024:v1") != embedding_input_hash(
  49. first_chunk, "qwen:1024:v2"
  50. )