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

14 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-11-06 08:17 +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("source_id", pa.utf8()), 

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

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

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

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

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

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

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

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

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

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

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

45 pa.field("held_out", pa.utf8()), 

46 pa.field("held_hash", pa.utf8()), 

47 pa.field("held_reason", pa.utf8()), 

48 ] 

49 ) 

50 

51 

52def _page_texts_schema() -> pa.Schema: 

53 return pa.schema( 

54 [ 

55 pa.field("source_id", pa.utf8()), 

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

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

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

59 ] 

60 ) 

61 

62 

63def _citations_schema() -> pa.Schema: 

64 return pa.schema( 

65 [ 

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

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

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

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

70 pa.field("source_id", pa.utf8()), 

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

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

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

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

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

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

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

78 ] 

79 ) 

80 

81 

82def _wiki_mentions_schema() -> pa.Schema: 

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

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

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

86 return pa.schema( 

87 [ 

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

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

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

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

92 pa.field("source_id", pa.utf8()), 

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

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

95 ] 

96 )