Document Processing¶
processing
¶
Assembly: Mappy
Filename: processing.py
Author: Terry D. Eppler
Created: 09-08-2026
Last Modified By: Terry D. Eppler
Last Modified On: 09-10-2026
Classes¶
Functions:¶
throw_if
¶
Validate a required value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Argument name included in validation failures. |
required |
value
|
object
|
Runtime value to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function validates input only. |
Source code in processing.py
initialize_document_state
¶
Initialize shared document-processing state.
Source code in processing.py
initialize_web_state
¶
Initialize shared web-document state.
Source code in processing.py
clear_document_state
¶
Clear loaded documents and all derived document state.
Source code in processing.py
clear_web_state
¶
Clear scraped documents and all derived web-document state.
Source code in processing.py
load_uploaded_document
¶
Load an uploaded file into LangChain documents.
Source code in processing.py
render_processing_inputs
¶
Render Foo-style chunking, embedding, and vector-store controls.
Source code in processing.py
tokenize_documents
¶
Tokenize document chunks into words.
Purpose
Creates word tokens for each chunk while preserving positional correspondence between the chunk, its tokens, and any subsequently generated embedding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
Document chunks requiring tokenization. |
required |
Returns: List[List[str]]: Tokens grouped by document chunk in input order.
Source code in processing.py
chunk_documents
¶
chunk_documents(
documents: List[Document],
chunk_size: int,
chunk_overlap: int,
) -> List[Document]
Split LangChain documents into retrieval chunks.
Source code in processing.py
create_embeddings
¶
create_embeddings(
chunks: List[Document],
provider: str,
model: str,
model_path: str,
) -> tuple[object, List[List[float]]]
Create and validate embeddings for document chunks.
Source code in processing.py
store_documents
¶
store_documents(
chunks: List[Document],
embeddings: List[List[float]],
embedder: object,
vector_backend: str,
vector_target: str,
persist_directory: str,
namespace: str,
) -> object
Persist document chunks to Chroma or Pinecone.
Source code in processing.py
render_retrieval_controls
¶
Render similarity retrieval for a stored vector collection.
Purpose
Makes persisted document vectors usable by accepting a query and displaying scored source context returned by the active Chroma or Pinecone wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_key
|
str
|
Session-state key containing the connected vector-store wrapper. |
required |
key_prefix
|
str
|
Unique Streamlit widget-key prefix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function renders controls and retrieval results. |
Source code in processing.py
render_document_actions
¶
Render Chunk, Embed, and Store actions for one Foo-style loader expander.
Source code in processing.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
render_loader_expander
¶
Render one local Foo-style loader expander.
Source code in processing.py
render_enrichment_expander
¶
Render Mappy's existing Excel/CSV geospatial enrichment workflow.
Source code in processing.py
render_document_tabs
¶
render_document_tabs(
documents_key: str,
chunks_key: str,
tokens_key: str,
embeddings_key: str,
first_label: str,
) -> None
Render loaded/scraped, chunk, and embedding tabs.
Source code in processing.py
render_document_processing
¶
Render Foo-style local document loading in Mappy Data Upload mode.
Source code in processing.py
render_web_document_processing
¶
Render Foo-style web scraping and document processing in Mappy Web Scraper mode.
Source code in processing.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | |
initialize_mode_document_state
¶
Initialize per-mode document state.
Source code in processing.py
clear_mode_document_outputs
¶
Clear source-derived processing outputs for one GIS mode.
Purpose
Removes the source document, chunks, tokens, embeddings, and vector-store connection after the active source is cleared without changing any source or processing input controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Session-state prefix assigned to the GIS mode. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function updates Streamlit session state. |
Source code in processing.py
serialize_mode_result
¶
Serialize a structured API result as document text.
Source code in processing.py
create_result_documents
¶
Convert a GIS provider result into record-oriented documents.
Purpose
Preserves row, feature, observation, and event boundaries so chunking does not destroy the geographic and temporal context required for filtered retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
object
|
Provider result returned by a Mappy source. |
required |
source
|
str
|
Provider or endpoint label. |
required |
mode
|
str
|
Mappy GIS mode containing the source. |
required |
Returns:
| Type | Description |
|---|---|
List[Document]
|
List[Document]: Record-oriented documents with provider and GIS metadata. |
Source code in processing.py
sync_mode_document
¶
Synchronize the latest API result into a LangChain Document.
Source code in processing.py
render_source_processing_controls
¶
render_source_processing_controls(
prefix: str,
result_key: str,
source_key: str,
source_name: str,
key_prefix: str,
) -> None
Render Foo-style processing controls inside one source expander.
Purpose
Keeps each API source, its processing configuration, and its Chunk/Embed/Store actions together in the same expander while maintaining isolated document state per mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Per-mode session-state prefix. |
required |
result_key
|
str
|
Session-state key containing the latest structured API result. |
required |
source_key
|
str
|
Session-state key identifying the latest API source. |
required |
source_name
|
str
|
Source name represented by the containing expander. |
required |
key_prefix
|
str
|
Unique Streamlit widget-key prefix for this source. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function renders controls and updates session state. |
Source code in processing.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
render_mode_processing_controls
¶
render_mode_processing_controls(
prefix: str,
result_key: str,
source_key: str,
key_prefix: str,
) -> None
Render processing controls for the latest result in a GIS mode.
Purpose
Adds ingestion, non-destructive storage, and retrieval to an existing specialized GIS result panel without replacing its maps, images, metrics, tables, or raw response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Per-mode session-state prefix. |
required |
result_key
|
str
|
Session-state key containing the latest provider result. |
required |
source_key
|
str
|
Session-state key containing the latest provider name. |
required |
key_prefix
|
str
|
Unique Streamlit widget-key prefix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function renders processing and retrieval controls. |
Source code in processing.py
render_mode_document_tabs
¶
Render Loaded, Chunks, and Embeddings tabs for one API mode.
Source code in processing.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 | |