> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bigdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Narrative miner

# NarrativeMiner

> [!WARNING]
>
> We are sunsetting our SDKs and will no longer add new features, security patches, bug fixes, or technical support for them. To access the latest capabilities and ongoing improvements, we encourage you to migrate to our [RESTful API](https://docs.bigdata.com/api-rest/introduction.md).
>
> SDK support will officially end on **December 31, 2026**. On this date, the underlying endpoints used by the SDKs and related documentation will be decommissioned.
>
> To avoid any disruption to your services, please ensure your migration is complete by that date.
>
> For migration assistance, please contact us at [support@bigdata.com](mailto:support@bigdata.com).

The main entry point for extracting and analyzing narratives from news, filings, and transcripts.

**Parameters**

* `narrative_sentences` (list of str): List of narrative sentences to mine for.
* `sources` (list of str): List of source IDs (e.g., from knowledge graph).
* `document_type` (DocumentType): Type of document to mine (`NEWS`, `FILINGS`, `TRANSCRIPTS`).
* `companies` (list of str): List of company identifiers.
* `start_date` (str): Start date (YYYY-MM-DD).
* `end_date` (str): End date (YYYY-MM-DD).
* `fiscal_year` (int, optional): Fiscal year to filter documents.
* `rerank_threshold` (float, optional): Minimum similarity threshold for reranking results.

**Returns**

* `NarrativeMiner` instance.

**Example**

```python theme={null}
from bigdata_research_tools.miners import NarrativeMiner
from bigdata_client.models.search import DocumentType
# For the example, you also need a bigdata client instance:
from bigdata_research_tools.client import bigdata_connection

bigdata = bigdata_connection()

deglobalization_narratives = [
    "Global supply chains are fragmenting under geopolitical pressure",
    "Companies are rethinking offshoring amid rising geopolitical risks",
    "Trade flows are slowing as nations prioritize domestic resilience",
    "Manufacturing reshoring may increase costs without productivity gains",
    "Investors are underestimating the long-term impact of economic decoupling",
    "Globalization tailwinds have turned into headwinds for corporate margins",
    "Rising tariffs and sanctions are reshaping global investment patterns",
    "Policy shifts toward economic nationalism are disrupting decades of integration",
    "Multinationals face growing regulatory fragmentation across key markets",
    "De-risking from China could strain supply chain efficiency and raise input costs",
    "Emerging markets risk marginalization in a bifurcated global economy",
    "Executives express concern over escalating costs of regionalization strategies",
    "Cross-border capital flows are slowing amid increased scrutiny and controls",
    "De-globalization is accelerating inflationary pressures across industries",
    "Historical assumptions of global labor arbitrage are no longer holding"
]

tech_news_sources = bigdata.knowledge_graph.find_sources("MT Newswires")
tech_news_ids = [source.id for source in tech_news_sources if "MT Newswires" == source.name]

miner = NarrativeMiner(
    narrative_sentences=deglobalization_narratives,
    sources=tech_news_ids,
    document_type=DocumentType.NEWS,
    companies=["AAPL", "MSFT"],
    start_date="2024-01-01",
    end_date="2024-06-30",
    fiscal_year=None,
    rerank_threshold=0.7,
)
```

***

## mine\_narratives

Run the narrative mining process and retrieve results.

**Parameters**

* `document_limit` (int, optional): Maximum number of documents to process per company.
* `freq` (str, optional): Frequency for aggregating results (e.g., `'M'` for monthly).
* `export_path` (str, optional): Path to export results as an Excel file.

**Returns**

* Mining results (typically a DataFrame or list of results).

**Example**

```python theme={null}
results = miner.mine_narratives(
    document_limit=10,
    freq='M',
    export_path='output/mining_results.xlsx'
)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.