Coverage for src/lilbee/data/store/schema.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""PyArrow schemas for the LanceDB tables managed by the store.""" 

2 

3from __future__ import annotations 

4 

5import pyarrow as pa 

6 

7 

8def _meta_schema() -> pa.Schema: 

9 return pa.schema( 

10 [ 

11 pa.field("embedding_model", pa.utf8()), 

12 pa.field("embedding_dim", pa.int32()), 

13 pa.field("schema_version", pa.int32()), 

14 pa.field("updated_at", pa.utf8()), 

15 ] 

16 ) 

17 

18 

19def _entity_schema_state_schema() -> pa.Schema: 

20 return pa.schema( 

21 [ 

22 pa.field("schema_json", pa.utf8()), 

23 pa.field("applied", pa.bool_()), 

24 pa.field("source_count", pa.int32()), 

25 pa.field("updated_at", pa.utf8()), 

26 ] 

27 ) 

28 

29 

30def _sources_schema() -> pa.Schema: 

31 return pa.schema( 

32 [ 

33 pa.field("filename", pa.utf8()), 

34 pa.field("file_hash", pa.utf8()), 

35 pa.field("ingested_at", pa.utf8()), 

36 pa.field("chunk_count", pa.int32()), 

37 pa.field("source_type", pa.utf8()), 

38 pa.field("size_bytes", pa.int64()), 

39 pa.field("mtime_ns", pa.int64()), 

40 pa.field("stat_captured_ns", pa.int64()), 

41 pa.field("title", pa.utf8()), 

42 pa.field("authors", pa.utf8()), 

43 pa.field("created_at", pa.utf8()), 

44 ] 

45 ) 

46 

47 

48def _page_texts_schema() -> pa.Schema: 

49 return pa.schema( 

50 [ 

51 pa.field("source", pa.utf8()), 

52 pa.field("page", pa.int32()), 

53 pa.field("text", pa.utf8()), 

54 pa.field("content_type", pa.utf8()), 

55 ] 

56 ) 

57 

58 

59def _citations_schema() -> pa.Schema: 

60 return pa.schema( 

61 [ 

62 pa.field("wiki_source", pa.utf8()), 

63 pa.field("wiki_chunk_index", pa.int32()), 

64 pa.field("citation_key", pa.utf8()), 

65 pa.field("claim_type", pa.utf8()), 

66 pa.field("source_filename", pa.utf8()), 

67 pa.field("source_hash", pa.utf8()), 

68 pa.field("page_start", pa.int32()), 

69 pa.field("page_end", pa.int32()), 

70 pa.field("line_start", pa.int32()), 

71 pa.field("line_end", pa.int32()), 

72 pa.field("excerpt", pa.utf8()), 

73 pa.field("created_at", pa.utf8()), 

74 ] 

75 ) 

76 

77 

78def _wiki_mentions_schema() -> pa.Schema: 

79 """One row per (subject, source): the subject's mention evidence in that 

80 source. ``slug`` is the make_slug key the wiki stub index uses; the wiki 

81 aggregates these rows across sources to judge the corpus-wide floor.""" 

82 return pa.schema( 

83 [ 

84 pa.field("slug", pa.utf8()), 

85 pa.field("label", pa.utf8()), 

86 pa.field("kind", pa.utf8()), 

87 pa.field("type_hint", pa.utf8()), 

88 pa.field("source", pa.utf8()), 

89 pa.field("mention_count", pa.int32()), 

90 pa.field("chunk_indices", pa.list_(pa.int32())), 

91 ] 

92 )