bigdata-smart-batching 0.2.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/.gitignore +5 -0
- bigdata_smart_batching-1.0.2/CHANGELOG.md +110 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/Makefile +7 -1
- bigdata_smart_batching-1.0.2/PKG-INFO +340 -0
- bigdata_smart_batching-1.0.2/README.md +324 -0
- bigdata_smart_batching-1.0.2/docs/smart-batching-architecture.md +481 -0
- bigdata_smart_batching-1.0.2/examples/example.py +118 -0
- bigdata_smart_batching-1.0.2/examples/example_overlapping.py +185 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/pyproject.toml +9 -1
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/src/bigdata_smart_batching/__init__.py +24 -4
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/src/bigdata_smart_batching/search_function.py +341 -66
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/src/bigdata_smart_batching/smart_batching.py +712 -716
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/src/bigdata_smart_batching/smart_batching_config.py +16 -12
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/tests/test_config.py +0 -7
- bigdata_smart_batching-1.0.2/tests/test_validation.py +180 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/uv.lock +1 -1
- bigdata_smart_batching-0.2.0/CHANGELOG.md +0 -28
- bigdata_smart_batching-0.2.0/PKG-INFO +0 -254
- bigdata_smart_batching-0.2.0/README.md +0 -238
- bigdata_smart_batching-0.2.0/docs/smart-batching-architecture.md +0 -387
- bigdata_smart_batching-0.2.0/examples/example.py +0 -76
- bigdata_smart_batching-0.2.0/tests/test_validation.py +0 -84
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/LICENSE +0 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/src/bigdata_smart_batching/output_converter.py +0 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/tests/__init__.py +0 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/tests/test_output_converter.py +0 -0
- {bigdata_smart_batching-0.2.0 → bigdata_smart_batching-1.0.2}/tests/test_rate_limiter.py +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.2] - 2026-04-17
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Corrected README file
|
|
13
|
+
|
|
14
|
+
## [1.0.1] - 2026-04-17
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Republish on PyPI after an erroneous publish of v1.0.0; package contents match the intended release.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [1.0.0] - 2026-04-17
|
|
22
|
+
|
|
23
|
+
First stable release. Redesigns the batching pipeline so every API request stays
|
|
24
|
+
within service limits while keeping plans deterministic.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- `create_entity_groups` step: sorts companies by chunks desc and greedy-packs
|
|
29
|
+
under `MAX_CHUNKS_PER_BASKET` and `MAX_ENTITIES_IN_ANY_OF`, honoring
|
|
30
|
+
`min_entities_per_basket`, with tail-group merge when it fits the entity
|
|
31
|
+
limit.
|
|
32
|
+
- Automatic splitting of co-mention volume queries into sub-ranges of up to 365
|
|
33
|
+
days, with per-company chunks summed across sub-ranges in both three-pass and
|
|
34
|
+
iterative modes. Iterative mode now fans out `(batch, sub-range)` work items
|
|
35
|
+
to the thread pool and derives `very_low` from companies never seen in any
|
|
36
|
+
sub-range.
|
|
37
|
+
- Parallel execution of `get_volume_timeseries` via `ThreadPoolExecutor`.
|
|
38
|
+
- `volume_bucket` metadata on every group/basket via `classify_volume_bucket`
|
|
39
|
+
and `majority_volume_bucket` (ties broken by `VOLUME_BUCKET_PRIORITY`).
|
|
40
|
+
- Centralized `VOLUME_BUCKETS` in `smart_batching_config` with explicit
|
|
41
|
+
`[lower, upper)` semantics and new `VOLUME_BUCKET_PRIORITY` constant.
|
|
42
|
+
- INCLUDE/EXCLUDE category filtering for planning and all Bigdata query paths
|
|
43
|
+
(co-mention, volume, search), validated against a fixed set of allowed
|
|
44
|
+
category strings. `CategoryFilter`, `CategoryMode`, and validators/builders
|
|
45
|
+
are exported from the package.
|
|
46
|
+
- Shared payload builders `build_comention_payload`, `build_volume_payload`,
|
|
47
|
+
and `build_search_query`, which `SmartBatchingPlanner` now routes through
|
|
48
|
+
instead of constructing payloads inline.
|
|
49
|
+
- `content_diversification` option in `ranking_params`, exposed on
|
|
50
|
+
`plan_search`.
|
|
51
|
+
- Universe input accepts either a CSV path or an inline list of entity IDs
|
|
52
|
+
(`universe: str | list[str]`). Added `resolve_universe()` and `UniverseInput`,
|
|
53
|
+
both exported from the package.
|
|
54
|
+
- `Makefile` test targets and coverage settings in `pyproject.toml`.
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- **Breaking:** `SmartBatchingPlanner` public API redesigned. `create_baskets`
|
|
59
|
+
is replaced by `create_entity_groups` (new signature:
|
|
60
|
+
`min_entities_per_group` instead of `max_chunks`/`min_entities_per_basket`);
|
|
61
|
+
returned dicts no longer include `basket_id` or `volume_range` and expose
|
|
62
|
+
`volume_bucket` instead.
|
|
63
|
+
- **Breaking:** Removed helpers `group_by_volume`,
|
|
64
|
+
`consolidate_period_groups`, `sub_period_volumes_from_series`, and
|
|
65
|
+
`get_volume_timeseries_per_company`.
|
|
66
|
+
- **Breaking:** `very_low` basket IDs are now
|
|
67
|
+
`basket_{n}_very_low_{start}_{end}` instead of `very_low_basket_{n}`;
|
|
68
|
+
downstream parsers must be updated.
|
|
69
|
+
- **Breaking:** `VOLUME_BUCKETS` ranges are now enforced as `[lower, upper)`.
|
|
70
|
+
- **Breaking:** `plan_search(..., universe_csv_path=)` renamed to
|
|
71
|
+
`universe=` (accepts `str | list[str]`). `SmartBatchingPlanner.load_universe`
|
|
72
|
+
and `plan_all_periods` now take a required `universe` argument and delegate
|
|
73
|
+
to `resolve_universe`; `UNIVERSE_CSV_PATH` and duplicate CSV parsing removed.
|
|
74
|
+
- **Breaking:** `plan_search` / `plan_all_periods` now accept an optional
|
|
75
|
+
`text` parameter and parameter order has been reordered.
|
|
76
|
+
- Entity filters now use `search_in=BODY` for co-mention and volume payloads;
|
|
77
|
+
`ranking_params` dropped from the volume query.
|
|
78
|
+
- Omit `text` from co-mention, volume, and search payloads when topic/text is
|
|
79
|
+
`None`.
|
|
80
|
+
- Planned baskets are sorted by `basket_id` for stable ordering.
|
|
81
|
+
- Architecture documentation updated to reflect the new `plan_search` flow
|
|
82
|
+
(sub-range splitting, entity groups, pre-fetch only for heavy groups, one
|
|
83
|
+
basket per `(group, sub-period)`) and a new high-level flow diagram.
|
|
84
|
+
- `load_universe_from_csv` rejects empty CSV paths.
|
|
85
|
+
|
|
86
|
+
### Removed
|
|
87
|
+
|
|
88
|
+
- Obsolete `VOLUME_BUCKETS` structure test.
|
|
89
|
+
|
|
90
|
+
## [0.2.0] - 2026-04-14
|
|
91
|
+
|
|
92
|
+
### Changed
|
|
93
|
+
|
|
94
|
+
- **Breaking:** `plan_search` now returns `chunk_upper_bound_estimate` instead of `total_expected_chunks`. Callers, saved plans, and any code reading the plan dict must use the new key. `execute_search` reads `chunk_upper_bound_estimate` when deriving sampling from the plan.
|
|
95
|
+
- Terminology and docs describe this value as a chunk upper bound estimate (module docstring, README, architecture diagram, and example output).
|
|
96
|
+
- README installation: document PyPI consumption (`pip install bigdata-smart-batching`, `uv add bigdata-smart-batching`) and keep a separate **Development** section for cloning the repo and `uv sync`.
|
|
97
|
+
|
|
98
|
+
### Fixed
|
|
99
|
+
|
|
100
|
+
- Align `uv.lock` `requires-python` with `pyproject.toml` (`>=3.11,<4.0`).
|
|
101
|
+
|
|
102
|
+
## [0.1.0] - 2026-04-14
|
|
103
|
+
|
|
104
|
+
### Added
|
|
105
|
+
|
|
106
|
+
- Initial release of **bigdata-smart-batching**: high-performance semantic search with intelligent company grouping and parallel execution.
|
|
107
|
+
- Planning API (`plan_search`) to organize searches via smart batching and report expected chunk counts.
|
|
108
|
+
- Execution API (`execute_search`) with rate-limited parallel requests and proportional sampling to preserve result distribution.
|
|
109
|
+
- Utilities: document deduplication, DataFrame conversion, and configurable search/batching behavior via `smart_batching` and related modules.
|
|
110
|
+
- Python 3.11+ support; dependencies include `requests`, `pandas`, `numpy`, `matplotlib`, and `python-dotenv`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.PHONY: lint lint-check format format-check
|
|
1
|
+
.PHONY: lint lint-check format format-check test test-cov
|
|
2
2
|
|
|
3
3
|
lint:
|
|
4
4
|
uvx ruff check --fix src/ tests/
|
|
@@ -11,3 +11,9 @@ format:
|
|
|
11
11
|
|
|
12
12
|
format-check:
|
|
13
13
|
uvx ruff format --check src/ tests/
|
|
14
|
+
|
|
15
|
+
test:
|
|
16
|
+
uv run pytest
|
|
17
|
+
|
|
18
|
+
test-cov:
|
|
19
|
+
uv run pytest --cov --cov-report=term-missing --cov-report=html
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bigdata-smart-batching
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: High-performance semantic search with intelligent company grouping and parallel execution
|
|
5
|
+
Project-URL: homepage, https://bigdata.com/api
|
|
6
|
+
Author-email: "Bigdata.com" <support@ravenpack.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: <4.0,>=3.11
|
|
10
|
+
Requires-Dist: matplotlib>=3.7
|
|
11
|
+
Requires-Dist: numpy>=1.24
|
|
12
|
+
Requires-Dist: pandas>=2.0
|
|
13
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
14
|
+
Requires-Dist: requests>=2.31.0
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Smart Batching Search
|
|
18
|
+
|
|
19
|
+
A high-performance semantic search system that reduces API queries by **67-99%** (varies by topic specificity) through intelligent company grouping and parallel execution.
|
|
20
|
+
|
|
21
|
+
This module provides a two-step pipeline for efficient semantic search:
|
|
22
|
+
|
|
23
|
+
1. **Planning** -- organize the search via smart batching and return a chunk upper bound estimate.
|
|
24
|
+
2. **Execution** -- run the plan with proportional sampling to preserve the result distribution.
|
|
25
|
+
|
|
26
|
+
## Key Benefits
|
|
27
|
+
|
|
28
|
+
- **67-99% query reduction** -- search 4,732 companies with only 17-3,699 queries (varies by topic).
|
|
29
|
+
- **Parallel execution** -- rate-limited concurrent requests with semaphore-controlled concurrency.
|
|
30
|
+
- **Proportional sampling** -- retrieve a percentage of results while preserving the distribution across baskets.
|
|
31
|
+
- **Category filtering** -- restrict searches to specific document categories (news, transcripts, filings, ...).
|
|
32
|
+
- **Deterministic plans** -- every request stays within service limits; plans can be saved and replayed.
|
|
33
|
+
- **Scalable** -- handles universes with 10,000+ companies efficiently.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
Install the package from PyPI (Python 3.11+):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install bigdata-smart-batching
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv add bigdata-smart-batching
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Development
|
|
50
|
+
|
|
51
|
+
To work on this repository locally, from the project root:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uv sync
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Environment Setup
|
|
58
|
+
|
|
59
|
+
Set up environment variables:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
export BIGDATA_API_KEY="your_api_key_here"
|
|
63
|
+
export BIGDATA_API_BASE_URL="https://api.bigdata.com" # Optional, defaults to this
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or create a `.env` file:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
BIGDATA_API_KEY=your_api_key_here
|
|
70
|
+
BIGDATA_API_BASE_URL=https://api.bigdata.com
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Universe (CSV path or entity list)
|
|
74
|
+
|
|
75
|
+
`plan_search()` takes a **`universe`** argument: either a path to a UTF-8 CSV file, or a `list[str]` of entity IDs. IDs must match the identifiers used by the Bigdata API for your dataset.
|
|
76
|
+
|
|
77
|
+
When using a CSV, two layouts are supported:
|
|
78
|
+
|
|
79
|
+
**1. Header row with an `id` column** (optional extra columns such as `name` are ignored):
|
|
80
|
+
|
|
81
|
+
```csv
|
|
82
|
+
id,name
|
|
83
|
+
B8EF97,Example Corp A
|
|
84
|
+
BB07E4,Example Corp B
|
|
85
|
+
3461CF,Example Corp C
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You can also pass a plain list instead of a CSV path:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
plan = plan_search(
|
|
92
|
+
universe=["B8EF97", "BB07E4", "3461CF"],
|
|
93
|
+
start_date="2023-01-01",
|
|
94
|
+
end_date="2023-12-31",
|
|
95
|
+
text="earnings revenue profit",
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Quick Start
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from bigdata_smart_batching import (
|
|
103
|
+
plan_search,
|
|
104
|
+
execute_search,
|
|
105
|
+
deduplicate_documents,
|
|
106
|
+
convert_to_dataframe,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
plan = plan_search(
|
|
110
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
111
|
+
start_date="2023-01-01",
|
|
112
|
+
end_date="2023-12-31",
|
|
113
|
+
text="earnings revenue profit",
|
|
114
|
+
api_key="your_api_key", # or set BIGDATA_API_KEY env var
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
print(f"Chunk upper bound estimate: {plan['chunk_upper_bound_estimate']:,}")
|
|
118
|
+
|
|
119
|
+
results_raw = execute_search(
|
|
120
|
+
search_plan=plan,
|
|
121
|
+
chunk_percentage=0.1,
|
|
122
|
+
requests_per_minute=100,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
results = deduplicate_documents(results_raw)
|
|
126
|
+
print(f"Retrieved {len(results)} documents (deduplicated)")
|
|
127
|
+
|
|
128
|
+
df = convert_to_dataframe(results) # one row per chunk
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Category Filtering
|
|
132
|
+
|
|
133
|
+
Restrict searches to a specific set of document categories using the `category`
|
|
134
|
+
argument. It accepts either a `CategoryFilter` dataclass or a plain dict.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from bigdata_smart_batching import CategoryFilter, CategoryMode, plan_search
|
|
138
|
+
|
|
139
|
+
plan = plan_search(
|
|
140
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
141
|
+
start_date="2023-01-01",
|
|
142
|
+
end_date="2023-12-31",
|
|
143
|
+
text="merger acquisition",
|
|
144
|
+
category=CategoryFilter(
|
|
145
|
+
mode=CategoryMode.INCLUDE,
|
|
146
|
+
values=("news_premium", "transcripts"),
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Equivalent dict form:
|
|
151
|
+
plan = plan_search(
|
|
152
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
153
|
+
start_date="2023-01-01",
|
|
154
|
+
end_date="2023-12-31",
|
|
155
|
+
text="merger acquisition",
|
|
156
|
+
category={"mode": "INCLUDE", "values": ["news_premium", "transcripts"]},
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Valid category values are exposed via `VALID_CATEGORY_VALUES` and include:
|
|
161
|
+
`expert_interviews`, `filings`, `my_files`, `news`, `news_premium`,
|
|
162
|
+
`news_public`, `podcasts`, `research`, `research_academic_journals`,
|
|
163
|
+
`research_investment_research`, `transcripts`.
|
|
164
|
+
|
|
165
|
+
### Save and Load Plans
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from bigdata_smart_batching import plan_search, execute_search, save_plan, load_plan
|
|
169
|
+
|
|
170
|
+
plan = plan_search(
|
|
171
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
172
|
+
start_date="2023-01-01",
|
|
173
|
+
end_date="2023-12-31",
|
|
174
|
+
text="merger acquisition",
|
|
175
|
+
)
|
|
176
|
+
save_plan(plan, "my_search_plan.json")
|
|
177
|
+
|
|
178
|
+
plan = load_plan("my_search_plan.json")
|
|
179
|
+
raw_10 = execute_search(plan, chunk_percentage=0.1)
|
|
180
|
+
raw_50 = execute_search(plan, chunk_percentage=0.5)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## How It Works
|
|
184
|
+
|
|
185
|
+
### Architecture Overview
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
Step 1: PLANNING
|
|
189
|
+
Universe --> Co-mention volumes --> Entity groups (by volume) --> Sub-period split --> Search plan
|
|
190
|
+
|
|
191
|
+
Step 2: EXECUTION
|
|
192
|
+
Proportional sampling --> Parallel search (rate limited) --> Collect & aggregate
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Planning (`plan_search()`)
|
|
196
|
+
|
|
197
|
+
1. Loads the universe of companies from a CSV path or inline list.
|
|
198
|
+
2. Queries the co-mention endpoint to get chunk volumes per company (split into sub-ranges of up to 365 days, summed per company).
|
|
199
|
+
3. Splits date ranges by volume when a company exceeds the chunk limit, honoring `min_period_days`.
|
|
200
|
+
4. Sorts companies by chunk volume and greedy-packs them into entity groups under `MAX_CHUNKS_PER_BASKET` (1000) and `MAX_ENTITIES_IN_ANY_OF` (500).
|
|
201
|
+
5. Classifies each group by `volume_bucket` (`high`, `medium`, `low`, `very_low`).
|
|
202
|
+
6. Returns a plan with the chunk upper bound estimate and per-basket query configurations.
|
|
203
|
+
|
|
204
|
+
### Execution (`execute_search()`)
|
|
205
|
+
|
|
206
|
+
1. Calculates proportional chunks per basket, with a minimum of 1 chunk per basket when `expected_chunks > 0`.
|
|
207
|
+
2. Executes searches in parallel with sliding-window rate limiting and a concurrency semaphore.
|
|
208
|
+
3. Optionally performs a **second pass**, removing already-retrieved entities from each basket and re-querying for the remainder.
|
|
209
|
+
4. Enriches each chunk with `entity_ids` and `primary_entity_id`, and returns the raw documents.
|
|
210
|
+
|
|
211
|
+
## API Reference
|
|
212
|
+
|
|
213
|
+
### `plan_search()`
|
|
214
|
+
|
|
215
|
+
| Parameter | Type | Default | Description |
|
|
216
|
+
|-----------|------|---------|-------------|
|
|
217
|
+
| `universe` | `str \| list[str]` | required | CSV path or list of entity IDs |
|
|
218
|
+
| `start_date` | `str` | required | Start date (YYYY-MM-DD) |
|
|
219
|
+
| `end_date` | `str` | required | End date (YYYY-MM-DD) |
|
|
220
|
+
| `text` | `str \| None` | `None` | Search query text; omitted from all payloads when `None` |
|
|
221
|
+
| `api_key` | `str \| None` | env var | API key |
|
|
222
|
+
| `api_base_url` | `str \| None` | env var | API base URL |
|
|
223
|
+
| `volume_query_mode` | `str` | `"three_pass"` | `"three_pass"` or `"iterative"` |
|
|
224
|
+
| `max_iterations_per_batch` | `int` | `10` | Max iterations per batch in `"iterative"` mode |
|
|
225
|
+
| `apply_volume_splits` | `bool` | `True` | Use volume time series for period splitting |
|
|
226
|
+
| `min_period_days` | `int` | `30` | Minimum days per sub-period |
|
|
227
|
+
| `min_entities_per_basket` | `int` | `1` | Lower bound on entities per basket |
|
|
228
|
+
| `category` | `CategoryFilter \| dict \| None` | `None` | Optional category filter (`mode` + `values`) |
|
|
229
|
+
| `content_diversification` | `bool` | `True` | Enable/disable content diversification in ranking |
|
|
230
|
+
|
|
231
|
+
### `execute_search()`
|
|
232
|
+
|
|
233
|
+
| Parameter | Type | Default | Description |
|
|
234
|
+
|-----------|------|---------|-------------|
|
|
235
|
+
| `search_plan` | `dict` | required | Plan from `plan_search()` |
|
|
236
|
+
| `chunk_percentage` | `float` | required | 0.0 to 1.0 sampling ratio |
|
|
237
|
+
| `requests_per_minute` | `int` | `100` | Rate limit |
|
|
238
|
+
| `api_key` | `str \| None` | env var | API key |
|
|
239
|
+
| `api_base_url` | `str \| None` | env var | API base URL |
|
|
240
|
+
| `max_workers` | `int` | `40` | Parallel workers |
|
|
241
|
+
| `overwrite_chunks_per_basket` | `int \| None` | `None` | Override the proportional chunk allocation |
|
|
242
|
+
| `second_pass` | `bool` | `False` | Re-query each basket for entities not yet retrieved |
|
|
243
|
+
|
|
244
|
+
### Helper Functions
|
|
245
|
+
|
|
246
|
+
- `deduplicate_documents(documents)` -- merge duplicate documents by `id`, combining their chunks.
|
|
247
|
+
- `convert_to_dataframe(raw_results)` -- convert documents to a DataFrame with one row per chunk.
|
|
248
|
+
- `resolve_universe(universe)` -- load entity IDs from a CSV path or validate a `list[str]`.
|
|
249
|
+
- `load_universe_from_csv(csv_path)` -- load entity IDs from a CSV only.
|
|
250
|
+
- `save_plan(plan, path)` / `load_plan(path)` -- persist plans as JSON.
|
|
251
|
+
- `validate_category_filter(category)` -- validate and normalize a category filter to the API dict shape.
|
|
252
|
+
- `build_comention_payload(...)`, `build_volume_payload(...)`, `build_search_query(...)` -- low-level payload builders used by the planner; useful if you need to construct custom requests.
|
|
253
|
+
|
|
254
|
+
### Public Types
|
|
255
|
+
|
|
256
|
+
- `CategoryFilter` -- frozen dataclass with `mode: CategoryMode` and `values: tuple[str, ...]`.
|
|
257
|
+
- `CategoryMode` -- `StrEnum` with `INCLUDE` and `EXCLUDE` values.
|
|
258
|
+
- `CategoryFilterInput` -- type alias: `CategoryFilter | dict[str, str | list[str]]`.
|
|
259
|
+
- `UniverseInput` -- type alias: `str | list[str]`.
|
|
260
|
+
- `VALID_CATEGORY_VALUES` -- `frozenset[str]` of allowed category strings.
|
|
261
|
+
|
|
262
|
+
## Testing
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Run all tests
|
|
266
|
+
uv run pytest
|
|
267
|
+
|
|
268
|
+
# With coverage
|
|
269
|
+
uv run pytest --cov=bigdata_smart_batching --cov-report=term-missing
|
|
270
|
+
|
|
271
|
+
# Specific test file
|
|
272
|
+
uv run pytest tests/test_validation.py -v
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Project Structure
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
bigdata-smart-batching/
|
|
279
|
+
├── pyproject.toml
|
|
280
|
+
├── README.md
|
|
281
|
+
├── CHANGELOG.md
|
|
282
|
+
├── LICENSE
|
|
283
|
+
├── Makefile
|
|
284
|
+
├── .python-version
|
|
285
|
+
├── src/
|
|
286
|
+
│ └── bigdata_smart_batching/
|
|
287
|
+
│ ├── __init__.py
|
|
288
|
+
│ ├── smart_batching.py
|
|
289
|
+
│ ├── smart_batching_config.py
|
|
290
|
+
│ ├── search_function.py
|
|
291
|
+
│ └── output_converter.py
|
|
292
|
+
├── examples/
|
|
293
|
+
│ └── example.py
|
|
294
|
+
└── tests/
|
|
295
|
+
├── __init__.py
|
|
296
|
+
├── test_config.py
|
|
297
|
+
├── test_output_converter.py
|
|
298
|
+
├── test_rate_limiter.py
|
|
299
|
+
└── test_validation.py
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Configuration
|
|
303
|
+
|
|
304
|
+
### Environment Variables
|
|
305
|
+
|
|
306
|
+
- `BIGDATA_API_KEY` -- required; your Bigdata API key.
|
|
307
|
+
- `BIGDATA_API_BASE_URL` -- optional; API base URL (default: `https://api.bigdata.com`).
|
|
308
|
+
|
|
309
|
+
### Default Settings
|
|
310
|
+
|
|
311
|
+
- `requests_per_minute`: 100
|
|
312
|
+
- `max_workers`: 40
|
|
313
|
+
- `MAX_CHUNKS_PER_BASKET`: 1000
|
|
314
|
+
- `MAX_ENTITIES_IN_ANY_OF`: 500
|
|
315
|
+
- `volume_query_mode`: `"three_pass"`
|
|
316
|
+
|
|
317
|
+
### Volume Buckets
|
|
318
|
+
|
|
319
|
+
Companies (and basket groups) are classified by total chunk volume. Ranges use
|
|
320
|
+
`[lower, upper)` semantics:
|
|
321
|
+
|
|
322
|
+
| Bucket | Range |
|
|
323
|
+
|--------|-------|
|
|
324
|
+
| `high` | 500+ chunks |
|
|
325
|
+
| `medium` | 100-499 chunks |
|
|
326
|
+
| `low` | 1-99 chunks |
|
|
327
|
+
| `very_low` | 0 chunks (headlines only) |
|
|
328
|
+
|
|
329
|
+
Ties are resolved using `VOLUME_BUCKET_PRIORITY`: `high > medium > low > very_low`.
|
|
330
|
+
|
|
331
|
+
## Changelog
|
|
332
|
+
|
|
333
|
+
See [CHANGELOG.md](CHANGELOG.md) for release notes. The package is currently at
|
|
334
|
+
version **1.0.1**.
|
|
335
|
+
|
|
336
|
+
## License
|
|
337
|
+
|
|
338
|
+
This project is part of Bigdata.com.
|
|
339
|
+
|
|
340
|
+
**Disclaimer**: This software is provided "as is" without warranty of any kind, express or implied. The authors and contributors assume no responsibility for the accuracy, completeness, or usefulness of any information, results, or processes provided. This software is for educational and research purposes only and is not intended to be used as financial advice.
|