bigdata-smart-batching 0.1.0__tar.gz → 1.0.1__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-1.0.1/.gitignore +115 -0
- bigdata_smart_batching-1.0.1/CHANGELOG.md +104 -0
- bigdata_smart_batching-1.0.1/LICENSE +5 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/Makefile +7 -1
- bigdata_smart_batching-0.1.0/README.md → bigdata_smart_batching-1.0.1/PKG-INFO +55 -16
- bigdata_smart_batching-0.1.0/PKG-INFO → bigdata_smart_batching-1.0.1/README.md +39 -29
- bigdata_smart_batching-1.0.1/docs/smart-batching-architecture.md +481 -0
- bigdata_smart_batching-1.0.1/examples/example.py +118 -0
- bigdata_smart_batching-1.0.1/examples/example_overlapping.py +185 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/pyproject.toml +14 -2
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/src/bigdata_smart_batching/__init__.py +24 -4
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/src/bigdata_smart_batching/search_function.py +347 -72
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/src/bigdata_smart_batching/smart_batching.py +712 -716
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/src/bigdata_smart_batching/smart_batching_config.py +16 -12
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/tests/test_config.py +0 -7
- bigdata_smart_batching-1.0.1/tests/test_validation.py +180 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/uv.lock +2 -2
- bigdata_smart_batching-0.1.0/.env +0 -1
- bigdata_smart_batching-0.1.0/.python-version +0 -1
- bigdata_smart_batching-0.1.0/.vscode/launch.json +0 -19
- bigdata_smart_batching-0.1.0/docs/smart-batching-architecture.md +0 -387
- bigdata_smart_batching-0.1.0/examples/example.py +0 -76
- bigdata_smart_batching-0.1.0/id_name_mapping_us_top_3000.csv +0 -4732
- bigdata_smart_batching-0.1.0/id_name_mapping_us_top_3000_reduced.csv +0 -100
- bigdata_smart_batching-0.1.0/tests/test_validation.py +0 -84
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/src/bigdata_smart_batching/output_converter.py +0 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/tests/__init__.py +0 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/tests/test_output_converter.py +0 -0
- {bigdata_smart_batching-0.1.0 → bigdata_smart_batching-1.0.1}/tests/test_rate_limiter.py +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
*.manifest
|
|
31
|
+
*.spec
|
|
32
|
+
|
|
33
|
+
# Installer logs
|
|
34
|
+
pip-log.txt
|
|
35
|
+
pip-delete-this-directory.txt
|
|
36
|
+
|
|
37
|
+
# Unit test / coverage reports
|
|
38
|
+
htmlcov/
|
|
39
|
+
.tox/
|
|
40
|
+
.nox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
*.py,cover
|
|
48
|
+
.hypothesis/
|
|
49
|
+
.pytest_cache/
|
|
50
|
+
cover/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Environments
|
|
57
|
+
.env
|
|
58
|
+
.venv
|
|
59
|
+
env/
|
|
60
|
+
venv/
|
|
61
|
+
ENV/
|
|
62
|
+
env.bak/
|
|
63
|
+
venv.bak/
|
|
64
|
+
|
|
65
|
+
# Spyder project settings
|
|
66
|
+
.spyderproject
|
|
67
|
+
.spyproject
|
|
68
|
+
|
|
69
|
+
# Rope project settings
|
|
70
|
+
.ropeproject
|
|
71
|
+
|
|
72
|
+
# mkdocs documentation
|
|
73
|
+
/site
|
|
74
|
+
|
|
75
|
+
# mypy
|
|
76
|
+
.mypy_cache/
|
|
77
|
+
.dmypy.json
|
|
78
|
+
dmypy.json
|
|
79
|
+
|
|
80
|
+
# Pyre type checker
|
|
81
|
+
.pyre/
|
|
82
|
+
|
|
83
|
+
# pytype static type analyzer
|
|
84
|
+
.pytype/
|
|
85
|
+
|
|
86
|
+
# Cython debug symbols
|
|
87
|
+
cython_debug/
|
|
88
|
+
|
|
89
|
+
# Ruff
|
|
90
|
+
.ruff_cache/
|
|
91
|
+
|
|
92
|
+
# IDEs and editors
|
|
93
|
+
.idea/
|
|
94
|
+
.vscode/
|
|
95
|
+
*.swp
|
|
96
|
+
*.swo
|
|
97
|
+
*~
|
|
98
|
+
|
|
99
|
+
# Jupyter Notebook
|
|
100
|
+
.ipynb_checkpoints/
|
|
101
|
+
|
|
102
|
+
# pyenv
|
|
103
|
+
.python-version
|
|
104
|
+
|
|
105
|
+
# Local / OS
|
|
106
|
+
.DS_Store
|
|
107
|
+
Thumbs.db
|
|
108
|
+
|
|
109
|
+
# CSV files
|
|
110
|
+
*.csv
|
|
111
|
+
|
|
112
|
+
benchmark/
|
|
113
|
+
benchmark.py
|
|
114
|
+
scatter_date_relevance.py
|
|
115
|
+
simple.py
|
|
@@ -0,0 +1,104 @@
|
|
|
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.1] - 2026-04-17
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Republish on PyPI after an erroneous publish of v1.0.0; package contents match the intended release.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [1.0.0] - 2026-04-17
|
|
16
|
+
|
|
17
|
+
First stable release. Redesigns the batching pipeline so every API request stays
|
|
18
|
+
within service limits while keeping plans deterministic.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `create_entity_groups` step: sorts companies by chunks desc and greedy-packs
|
|
23
|
+
under `MAX_CHUNKS_PER_BASKET` and `MAX_ENTITIES_IN_ANY_OF`, honoring
|
|
24
|
+
`min_entities_per_basket`, with tail-group merge when it fits the entity
|
|
25
|
+
limit.
|
|
26
|
+
- Automatic splitting of co-mention volume queries into sub-ranges of up to 365
|
|
27
|
+
days, with per-company chunks summed across sub-ranges in both three-pass and
|
|
28
|
+
iterative modes. Iterative mode now fans out `(batch, sub-range)` work items
|
|
29
|
+
to the thread pool and derives `very_low` from companies never seen in any
|
|
30
|
+
sub-range.
|
|
31
|
+
- Parallel execution of `get_volume_timeseries` via `ThreadPoolExecutor`.
|
|
32
|
+
- `volume_bucket` metadata on every group/basket via `classify_volume_bucket`
|
|
33
|
+
and `majority_volume_bucket` (ties broken by `VOLUME_BUCKET_PRIORITY`).
|
|
34
|
+
- Centralized `VOLUME_BUCKETS` in `smart_batching_config` with explicit
|
|
35
|
+
`[lower, upper)` semantics and new `VOLUME_BUCKET_PRIORITY` constant.
|
|
36
|
+
- INCLUDE/EXCLUDE category filtering for planning and all Bigdata query paths
|
|
37
|
+
(co-mention, volume, search), validated against a fixed set of allowed
|
|
38
|
+
category strings. `CategoryFilter`, `CategoryMode`, and validators/builders
|
|
39
|
+
are exported from the package.
|
|
40
|
+
- Shared payload builders `build_comention_payload`, `build_volume_payload`,
|
|
41
|
+
and `build_search_query`, which `SmartBatchingPlanner` now routes through
|
|
42
|
+
instead of constructing payloads inline.
|
|
43
|
+
- `content_diversification` option in `ranking_params`, exposed on
|
|
44
|
+
`plan_search`.
|
|
45
|
+
- Universe input accepts either a CSV path or an inline list of entity IDs
|
|
46
|
+
(`universe: str | list[str]`). Added `resolve_universe()` and `UniverseInput`,
|
|
47
|
+
both exported from the package.
|
|
48
|
+
- `Makefile` test targets and coverage settings in `pyproject.toml`.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- **Breaking:** `SmartBatchingPlanner` public API redesigned. `create_baskets`
|
|
53
|
+
is replaced by `create_entity_groups` (new signature:
|
|
54
|
+
`min_entities_per_group` instead of `max_chunks`/`min_entities_per_basket`);
|
|
55
|
+
returned dicts no longer include `basket_id` or `volume_range` and expose
|
|
56
|
+
`volume_bucket` instead.
|
|
57
|
+
- **Breaking:** Removed helpers `group_by_volume`,
|
|
58
|
+
`consolidate_period_groups`, `sub_period_volumes_from_series`, and
|
|
59
|
+
`get_volume_timeseries_per_company`.
|
|
60
|
+
- **Breaking:** `very_low` basket IDs are now
|
|
61
|
+
`basket_{n}_very_low_{start}_{end}` instead of `very_low_basket_{n}`;
|
|
62
|
+
downstream parsers must be updated.
|
|
63
|
+
- **Breaking:** `VOLUME_BUCKETS` ranges are now enforced as `[lower, upper)`.
|
|
64
|
+
- **Breaking:** `plan_search(..., universe_csv_path=)` renamed to
|
|
65
|
+
`universe=` (accepts `str | list[str]`). `SmartBatchingPlanner.load_universe`
|
|
66
|
+
and `plan_all_periods` now take a required `universe` argument and delegate
|
|
67
|
+
to `resolve_universe`; `UNIVERSE_CSV_PATH` and duplicate CSV parsing removed.
|
|
68
|
+
- **Breaking:** `plan_search` / `plan_all_periods` now accept an optional
|
|
69
|
+
`text` parameter and parameter order has been reordered.
|
|
70
|
+
- Entity filters now use `search_in=BODY` for co-mention and volume payloads;
|
|
71
|
+
`ranking_params` dropped from the volume query.
|
|
72
|
+
- Omit `text` from co-mention, volume, and search payloads when topic/text is
|
|
73
|
+
`None`.
|
|
74
|
+
- Planned baskets are sorted by `basket_id` for stable ordering.
|
|
75
|
+
- Architecture documentation updated to reflect the new `plan_search` flow
|
|
76
|
+
(sub-range splitting, entity groups, pre-fetch only for heavy groups, one
|
|
77
|
+
basket per `(group, sub-period)`) and a new high-level flow diagram.
|
|
78
|
+
- `load_universe_from_csv` rejects empty CSV paths.
|
|
79
|
+
|
|
80
|
+
### Removed
|
|
81
|
+
|
|
82
|
+
- Obsolete `VOLUME_BUCKETS` structure test.
|
|
83
|
+
|
|
84
|
+
## [0.2.0] - 2026-04-14
|
|
85
|
+
|
|
86
|
+
### Changed
|
|
87
|
+
|
|
88
|
+
- **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.
|
|
89
|
+
- Terminology and docs describe this value as a chunk upper bound estimate (module docstring, README, architecture diagram, and example output).
|
|
90
|
+
- 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`.
|
|
91
|
+
|
|
92
|
+
### Fixed
|
|
93
|
+
|
|
94
|
+
- Align `uv.lock` `requires-python` with `pyproject.toml` (`>=3.11,<4.0`).
|
|
95
|
+
|
|
96
|
+
## [0.1.0] - 2026-04-14
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
|
|
100
|
+
- Initial release of **bigdata-smart-batching**: high-performance semantic search with intelligent company grouping and parallel execution.
|
|
101
|
+
- Planning API (`plan_search`) to organize searches via smart batching and report expected chunk counts.
|
|
102
|
+
- Execution API (`execute_search`) with rate-limited parallel requests and proportional sampling to preserve result distribution.
|
|
103
|
+
- Utilities: document deduplication, DataFrame conversion, and configurable search/batching behavior via `smart_batching` and related modules.
|
|
104
|
+
- Python 3.11+ support; dependencies include `requests`, `pandas`, `numpy`, `matplotlib`, and `python-dotenv`.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
This software is licensed for use solely under the terms agreed upon in the applicable Master Agreement and
|
|
2
|
+
Order Schedule between the parties. For trials, the applicable legal documents are the Mutual Non-Disclosure
|
|
3
|
+
Agreement, or if applicable the Trial Agreement. No other rights or licenses are granted by implication,
|
|
4
|
+
estoppel, or otherwise. For further details, please refer to your specific Master Agreement and Order
|
|
5
|
+
Schedule or contact us at legal@ravenpack.com.
|
|
@@ -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
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bigdata-smart-batching
|
|
3
|
+
Version: 1.0.1
|
|
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
|
+
|
|
1
17
|
# Smart Batching Search
|
|
2
18
|
|
|
3
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.
|
|
4
20
|
|
|
5
21
|
This module provides a two-step system for efficient semantic search:
|
|
6
|
-
1. **Planning**: Organize search using smart batching and return
|
|
22
|
+
1. **Planning**: Organize search using smart batching and return Chunk upper bound estimate
|
|
7
23
|
2. **Execution**: Perform search with proportional sampling to preserve distribution
|
|
8
24
|
|
|
9
25
|
## Key Benefits
|
|
@@ -16,17 +32,24 @@ This module provides a two-step system for efficient semantic search:
|
|
|
16
32
|
|
|
17
33
|
## Installation
|
|
18
34
|
|
|
19
|
-
|
|
35
|
+
Install the package from PyPI (Python 3.11+):
|
|
20
36
|
|
|
21
37
|
```bash
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
pip install bigdata-smart-batching
|
|
39
|
+
```
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv add bigdata-smart-batching
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Development
|
|
48
|
+
|
|
49
|
+
To work on this repository locally, from the project root:
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
uv sync
|
|
51
|
+
```bash
|
|
52
|
+
uv sync
|
|
30
53
|
```
|
|
31
54
|
|
|
32
55
|
### Environment Setup
|
|
@@ -45,6 +68,21 @@ BIGDATA_API_KEY=your_api_key_here
|
|
|
45
68
|
BIGDATA_API_BASE_URL=https://api.bigdata.com
|
|
46
69
|
```
|
|
47
70
|
|
|
71
|
+
## Universe (CSV path or entity list)
|
|
72
|
+
|
|
73
|
+
`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.
|
|
74
|
+
|
|
75
|
+
When using a CSV, two layouts are supported:
|
|
76
|
+
|
|
77
|
+
**1. Header row with an `id` column** (optional extra columns such as `name` are ignored):
|
|
78
|
+
|
|
79
|
+
```csv
|
|
80
|
+
id,name
|
|
81
|
+
B8EF97,Example Corp A
|
|
82
|
+
BB07E4,Example Corp B
|
|
83
|
+
3461CF,Example Corp C
|
|
84
|
+
```
|
|
85
|
+
|
|
48
86
|
## Quick Start
|
|
49
87
|
|
|
50
88
|
```python
|
|
@@ -58,13 +96,13 @@ from bigdata_smart_batching import (
|
|
|
58
96
|
# Step 1: Plan the search
|
|
59
97
|
plan = plan_search(
|
|
60
98
|
text="earnings revenue profit",
|
|
61
|
-
|
|
99
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
62
100
|
start_date="2023-01-01",
|
|
63
101
|
end_date="2023-12-31",
|
|
64
102
|
api_key="your_api_key", # or set BIGDATA_API_KEY env var
|
|
65
103
|
)
|
|
66
104
|
|
|
67
|
-
print(f"
|
|
105
|
+
print(f"Chunk upper bound estimate: {plan['chunk_upper_bound_estimate']:,}")
|
|
68
106
|
|
|
69
107
|
# Step 2: Execute search with 10% of total chunks (preserves distribution)
|
|
70
108
|
results_raw = execute_search(
|
|
@@ -88,7 +126,7 @@ from bigdata_smart_batching import plan_search, execute_search, save_plan, load_
|
|
|
88
126
|
# Create and save a plan
|
|
89
127
|
plan = plan_search(
|
|
90
128
|
text="merger acquisition",
|
|
91
|
-
|
|
129
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
92
130
|
start_date="2023-01-01",
|
|
93
131
|
end_date="2023-12-31",
|
|
94
132
|
)
|
|
@@ -114,11 +152,11 @@ Step 2: EXECUTION
|
|
|
114
152
|
|
|
115
153
|
### Planning (`plan_search()`)
|
|
116
154
|
|
|
117
|
-
1. Loads the universe of companies from CSV
|
|
155
|
+
1. Loads the universe of companies from a CSV path or inline list
|
|
118
156
|
2. Queries the comention endpoint to get chunk volumes per company
|
|
119
157
|
3. Splits date ranges by volume when a company exceeds the chunk limit
|
|
120
158
|
4. Creates optimized baskets grouped by volume
|
|
121
|
-
5. Returns a plan with
|
|
159
|
+
5. Returns a plan with Chunk upper bound estimate and basket configurations
|
|
122
160
|
|
|
123
161
|
### Execution (`execute_search()`)
|
|
124
162
|
|
|
@@ -134,7 +172,7 @@ Step 2: EXECUTION
|
|
|
134
172
|
| Parameter | Type | Default | Description |
|
|
135
173
|
|-----------|------|---------|-------------|
|
|
136
174
|
| `text` | `str` | required | Search query text |
|
|
137
|
-
| `
|
|
175
|
+
| `universe` | `str \| list[str]` | required | CSV path or list of entity IDs |
|
|
138
176
|
| `start_date` | `str` | required | Start date (YYYY-MM-DD) |
|
|
139
177
|
| `end_date` | `str` | required | End date (YYYY-MM-DD) |
|
|
140
178
|
| `api_key` | `str` | env var | API key |
|
|
@@ -156,7 +194,8 @@ Step 2: EXECUTION
|
|
|
156
194
|
### Helper Functions
|
|
157
195
|
|
|
158
196
|
- **`deduplicate_documents(documents)`** -- Merges duplicate documents by `id`
|
|
159
|
-
- **`
|
|
197
|
+
- **`resolve_universe(universe)`** -- Loads entity IDs from a CSV path or validates a `list[str]`
|
|
198
|
+
- **`load_universe_from_csv(csv_path)`** -- Loads entity IDs from CSV only
|
|
160
199
|
- **`convert_to_dataframe(raw_results)`** -- Converts documents to DataFrame (one row per chunk)
|
|
161
200
|
- **`save_plan(plan, path)`** / **`load_plan(path)`** -- Persist plans as JSON
|
|
162
201
|
- **`portfolio_backtesting_pipeline(...)`** -- Long-short portfolio backtesting
|
|
@@ -213,6 +252,6 @@ bigdata-smart-batching/
|
|
|
213
252
|
|
|
214
253
|
## License
|
|
215
254
|
|
|
216
|
-
This project is part of
|
|
255
|
+
This project is part of Bigdata.com.
|
|
217
256
|
|
|
218
257
|
**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.
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: bigdata-smart-batching
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: High-performance semantic search with intelligent company grouping and parallel execution
|
|
5
|
-
License: MIT
|
|
6
|
-
Requires-Python: >=3.11
|
|
7
|
-
Requires-Dist: matplotlib>=3.7
|
|
8
|
-
Requires-Dist: numpy>=1.24
|
|
9
|
-
Requires-Dist: pandas>=2.0
|
|
10
|
-
Requires-Dist: python-dotenv>=1.2.2
|
|
11
|
-
Requires-Dist: requests>=2.31.0
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
|
|
14
1
|
# Smart Batching Search
|
|
15
2
|
|
|
16
3
|
A high-performance semantic search system that reduces API queries by **67-99%** (varies by topic specificity) through intelligent company grouping and parallel execution.
|
|
17
4
|
|
|
18
5
|
This module provides a two-step system for efficient semantic search:
|
|
19
|
-
1. **Planning**: Organize search using smart batching and return
|
|
6
|
+
1. **Planning**: Organize search using smart batching and return Chunk upper bound estimate
|
|
20
7
|
2. **Execution**: Perform search with proportional sampling to preserve distribution
|
|
21
8
|
|
|
22
9
|
## Key Benefits
|
|
@@ -29,17 +16,24 @@ This module provides a two-step system for efficient semantic search:
|
|
|
29
16
|
|
|
30
17
|
## Installation
|
|
31
18
|
|
|
32
|
-
|
|
19
|
+
Install the package from PyPI (Python 3.11+):
|
|
33
20
|
|
|
34
21
|
```bash
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
pip install bigdata-smart-batching
|
|
23
|
+
```
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
With [uv](https://docs.astral.sh/uv/):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv add bigdata-smart-batching
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Development
|
|
32
|
+
|
|
33
|
+
To work on this repository locally, from the project root:
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
uv sync
|
|
35
|
+
```bash
|
|
36
|
+
uv sync
|
|
43
37
|
```
|
|
44
38
|
|
|
45
39
|
### Environment Setup
|
|
@@ -58,6 +52,21 @@ BIGDATA_API_KEY=your_api_key_here
|
|
|
58
52
|
BIGDATA_API_BASE_URL=https://api.bigdata.com
|
|
59
53
|
```
|
|
60
54
|
|
|
55
|
+
## Universe (CSV path or entity list)
|
|
56
|
+
|
|
57
|
+
`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.
|
|
58
|
+
|
|
59
|
+
When using a CSV, two layouts are supported:
|
|
60
|
+
|
|
61
|
+
**1. Header row with an `id` column** (optional extra columns such as `name` are ignored):
|
|
62
|
+
|
|
63
|
+
```csv
|
|
64
|
+
id,name
|
|
65
|
+
B8EF97,Example Corp A
|
|
66
|
+
BB07E4,Example Corp B
|
|
67
|
+
3461CF,Example Corp C
|
|
68
|
+
```
|
|
69
|
+
|
|
61
70
|
## Quick Start
|
|
62
71
|
|
|
63
72
|
```python
|
|
@@ -71,13 +80,13 @@ from bigdata_smart_batching import (
|
|
|
71
80
|
# Step 1: Plan the search
|
|
72
81
|
plan = plan_search(
|
|
73
82
|
text="earnings revenue profit",
|
|
74
|
-
|
|
83
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
75
84
|
start_date="2023-01-01",
|
|
76
85
|
end_date="2023-12-31",
|
|
77
86
|
api_key="your_api_key", # or set BIGDATA_API_KEY env var
|
|
78
87
|
)
|
|
79
88
|
|
|
80
|
-
print(f"
|
|
89
|
+
print(f"Chunk upper bound estimate: {plan['chunk_upper_bound_estimate']:,}")
|
|
81
90
|
|
|
82
91
|
# Step 2: Execute search with 10% of total chunks (preserves distribution)
|
|
83
92
|
results_raw = execute_search(
|
|
@@ -101,7 +110,7 @@ from bigdata_smart_batching import plan_search, execute_search, save_plan, load_
|
|
|
101
110
|
# Create and save a plan
|
|
102
111
|
plan = plan_search(
|
|
103
112
|
text="merger acquisition",
|
|
104
|
-
|
|
113
|
+
universe="id_name_mapping_us_top_3000.csv",
|
|
105
114
|
start_date="2023-01-01",
|
|
106
115
|
end_date="2023-12-31",
|
|
107
116
|
)
|
|
@@ -127,11 +136,11 @@ Step 2: EXECUTION
|
|
|
127
136
|
|
|
128
137
|
### Planning (`plan_search()`)
|
|
129
138
|
|
|
130
|
-
1. Loads the universe of companies from CSV
|
|
139
|
+
1. Loads the universe of companies from a CSV path or inline list
|
|
131
140
|
2. Queries the comention endpoint to get chunk volumes per company
|
|
132
141
|
3. Splits date ranges by volume when a company exceeds the chunk limit
|
|
133
142
|
4. Creates optimized baskets grouped by volume
|
|
134
|
-
5. Returns a plan with
|
|
143
|
+
5. Returns a plan with Chunk upper bound estimate and basket configurations
|
|
135
144
|
|
|
136
145
|
### Execution (`execute_search()`)
|
|
137
146
|
|
|
@@ -147,7 +156,7 @@ Step 2: EXECUTION
|
|
|
147
156
|
| Parameter | Type | Default | Description |
|
|
148
157
|
|-----------|------|---------|-------------|
|
|
149
158
|
| `text` | `str` | required | Search query text |
|
|
150
|
-
| `
|
|
159
|
+
| `universe` | `str \| list[str]` | required | CSV path or list of entity IDs |
|
|
151
160
|
| `start_date` | `str` | required | Start date (YYYY-MM-DD) |
|
|
152
161
|
| `end_date` | `str` | required | End date (YYYY-MM-DD) |
|
|
153
162
|
| `api_key` | `str` | env var | API key |
|
|
@@ -169,7 +178,8 @@ Step 2: EXECUTION
|
|
|
169
178
|
### Helper Functions
|
|
170
179
|
|
|
171
180
|
- **`deduplicate_documents(documents)`** -- Merges duplicate documents by `id`
|
|
172
|
-
- **`
|
|
181
|
+
- **`resolve_universe(universe)`** -- Loads entity IDs from a CSV path or validates a `list[str]`
|
|
182
|
+
- **`load_universe_from_csv(csv_path)`** -- Loads entity IDs from CSV only
|
|
173
183
|
- **`convert_to_dataframe(raw_results)`** -- Converts documents to DataFrame (one row per chunk)
|
|
174
184
|
- **`save_plan(plan, path)`** / **`load_plan(path)`** -- Persist plans as JSON
|
|
175
185
|
- **`portfolio_backtesting_pipeline(...)`** -- Long-short portfolio backtesting
|
|
@@ -226,6 +236,6 @@ bigdata-smart-batching/
|
|
|
226
236
|
|
|
227
237
|
## License
|
|
228
238
|
|
|
229
|
-
This project is part of
|
|
239
|
+
This project is part of Bigdata.com.
|
|
230
240
|
|
|
231
241
|
**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.
|