diff --git a/README.md b/README.md
index 4cfd563..be58739 100644
--- a/README.md
+++ b/README.md
@@ -9,11 +9,13 @@ The Apify-Haystack integration allows easy interaction between the [Apify](https
Apify is a platform for web scraping, data extraction, and web automation tasks.
It provides serverless applications called Actors for tasks like crawling websites and scraping Facebook, Instagram, and Google results.
-Haystack offers an ecosystem of tools for building, managing, and deploying search engines and LLM applications.
+Haystack is an open-source framework for building LLM applications, RAG pipelines, and agents.
+
+For a step-by-step guide, see the [Haystack integration](https://docs.apify.com/platform/integrations/haystack) page in the Apify documentation.
## Installation
-Apify-haystack is available as the [`apify-haystack`](https://pypi.org/project/apify-haystack/) package on PyPI. It requires Python 3.11 or newer and Haystack 3.
+The integration is available as the [`apify-haystack`](https://pypi.org/project/apify-haystack/) package on PyPI. It requires Python 3.11 or newer and Haystack 3.
```sh
pip install apify-haystack
@@ -27,46 +29,35 @@ pip install apify-haystack
- `ApifyWebSearch` searches the web with the [RAG Web Browser](https://apify.com/apify/rag-web-browser) Actor and returns the content of the top result pages.
- `ApifyActorTool` is a tool for Haystack Agents that runs any Actor and returns its dataset items. It takes its parameters from the Actor's input schema, and it marks the items it hands to the LLM as untrusted external content to guard against prompt injection.
-The dataset components turn dataset items into Haystack `Document` objects with a mapping function. Without one, they use `default_dataset_mapping_function`, which takes the `markdown` or `text` of website and search Actors with the page `url`, `title`, and `description` as `meta`, and the whole item as JSON for other Actors. Every component also has `run_async`, which `Pipeline.run_async` uses to run it without blocking the event loop. When an Actor or task run finishes with any status other than `SUCCEEDED`, the component raises a `RuntimeError` instead of loading a partial dataset.
+The dataset components turn dataset items into Haystack `Document` objects with a mapping function. Without one, they use `default_dataset_mapping_function`. For website and search Actors, it takes the item's `markdown` or `text` as the content and the page `url`, `title`, and `description` as `meta`. For other Actors, the content is the whole item as JSON.
+
+Every component also has `run_async`, which `Pipeline.run_async` uses to run it without blocking the event loop.
+
+When an Actor or task run finishes with any status other than `SUCCEEDED`, the component raises a `RuntimeError`.
The components read your Apify API token from the `APIFY_TOKEN` environment variable, or from `APIFY_API_TOKEN` if `APIFY_TOKEN` isn't set. To pass the token differently, use a Haystack `Secret`, for example `apify_token=Secret.from_env_var('MY_APIFY_TOKEN')`.
## Examples
-### Crawl a website using Apify's Website Content Crawler and convert it to Haystack Documents
+The examples need an Apify account and API token. You can start with a free account at [Apify](https://apify.com/) and get your [API token](https://docs.apify.com/platform/integrations/api), then set it as the `APIFY_TOKEN` environment variable.
-You need an Apify account and API token to run this example.
-You can start with a free account at [Apify](https://apify.com/) and get your [API token](https://docs.apify.com/platform/integrations/api).
+### Crawl a website and load it as Documents
-In the example below, set the `APIFY_TOKEN` environment variable and run the script:
+`ApifyDatasetFromActorCall` runs [Website Content Crawler](https://apify.com/apify/website-content-crawler) and loads the crawled pages as `Document` objects with the default mapping function:
```python
-from haystack import Document
-
from apify_haystack import ApifyDatasetFromActorCall
-actor_id = 'apify/website-content-crawler'
-run_input = {
- 'maxCrawlPages': 3, # limit the number of pages to crawl
- 'startUrls': [{'url': 'https://haystack.deepset.ai/'}],
-}
-
-
-def dataset_mapping_function(dataset_item: dict) -> Document:
- return Document(content=dataset_item.get('text'), meta={'url': dataset_item.get('url')})
-
-
-actor = ApifyDatasetFromActorCall(
- actor_id=actor_id, run_input=run_input, dataset_mapping_function=dataset_mapping_function
+crawler = ApifyDatasetFromActorCall(
+ actor_id='apify/website-content-crawler',
+ run_input={
+ 'maxCrawlPages': 3,
+ 'startUrls': [{'url': 'https://haystack.deepset.ai/'}],
+ },
)
-print(f'Calling the Apify Actor {actor_id}. Crawling will take some time.')
-print('You can monitor the progress at: https://console.apify.com/actors/runs')
-
-dataset = actor.run()['documents']
-print(f'Loaded {len(dataset)} documents from the Apify Actor {actor_id}:')
-for d in dataset:
- print(d)
+for document in crawler.run()['documents']:
+ print(document.meta['url'], document.content[:100])
```
### Search the web
@@ -103,29 +94,34 @@ print(result['last_message'].text)
### Save and load a pipeline
-The components and the tool support Haystack serialization. The token is saved as the name of its environment variable, never as its value. Haystack 3 only loads classes and functions from trusted modules, so allow `apify_haystack` and the module with your mapping function:
+The components and the tool support Haystack serialization. The token is saved as the name of its environment variable, never as its value. Haystack 3 only loads classes and functions from trusted modules, so pass `apify_haystack` in `allowed_modules`, along with the module of your mapping function if you use a custom one:
```python
from haystack import Pipeline
+from apify_haystack import ApifyDatasetLoader
+
+pipeline = Pipeline()
+pipeline.add_component('loader', ApifyDatasetLoader('YOUR-DATASET-ID'))
+
yaml = pipeline.dumps()
-restored = Pipeline.loads(yaml, allowed_modules=['apify_haystack', 'my_project.mapping'])
+restored = Pipeline.loads(yaml, allowed_modules=['apify_haystack'])
```
### More examples
-The [examples directory](https://github.com/apify/apify-haystack/tree/main/examples) has more examples:
+The [examples directory](https://github.com/apify/apify-haystack/tree/main/examples) has complete scripts:
-- Load a dataset from Apify and convert it to a Haystack Document
-- Call [Website Content Crawler](https://apify.com/apify/website-content-crawler) and convert the data into the Haystack Documents
-- Crawl websites, retrieve text content, and store it in the `InMemoryDocumentStore`
-- Retrieval-Augmented Generation (RAG): Extracting text from a website & question answering
-- Analyze your Instagram comments' vibe with Apify and Haystack
+- [Load an existing dataset](https://github.com/apify/apify-haystack/blob/main/examples/apify_dataset_load.py) and convert its items to Documents.
+- [Call Website Content Crawler](https://github.com/apify/apify-haystack/blob/main/examples/apify_actor_call.py) with a custom mapping function.
+- [Crawl a website, store the pages in `InMemoryDocumentStore`, and retrieve them](https://github.com/apify/apify-haystack/blob/main/examples/crawl_and_process_data.py).
+- [Answer questions about a crawled website with RAG](https://github.com/apify/apify-haystack/blob/main/examples/rag_with_crawled_website.py).
+- [Analyze the sentiment of Instagram comments](https://github.com/apify/apify-haystack/blob/main/examples/instagram_comments_analysis.py).
## Support
-If you find any bug or issue, please [submit an issue on GitHub](https://github.com/apify/apify-haystack/issues).
-For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
+If you find a bug, please [submit an issue on GitHub](https://github.com/apify/apify-haystack/issues).
+For questions, ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify) or join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
## Contributing
@@ -135,4 +131,4 @@ For contribution guidelines, see [CONTRIBUTING.md](https://github.com/apify/apif
## License
-This project is licensed under the Apache License 2.0 - see the [LICENSE](https://github.com/apify/apify-haystack/blob/main/LICENSE) file for details.
+This project is licensed under the [Apache License 2.0](https://github.com/apify/apify-haystack/blob/main/LICENSE).