Skip to content

Commit

Permalink
YAML versioning (#2209)
Browse files Browse the repository at this point in the history
* Make YAML files get the same version as Haystack and throw warning at load in case of mismatch

* Update version of most YAMLs in the codebase (aesthethic chamge, only to avoid the warning).

* Remove quotes from version in tests

* Fix version in generate_json_schema.py

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ZanSara and github-actions[bot] committed Feb 21, 2022
1 parent 2a674ea commit 2a840ee
Show file tree
Hide file tree
Showing 16 changed files with 2,651 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .github/utils/generate_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Any, Dict, Optional, Set, Tuple

from haystack import __version__
import haystack.document_stores
import haystack.nodes
import pydantic.schema
Expand All @@ -15,8 +16,8 @@
from pydantic.typing import is_callable_type
from pydantic.utils import lenient_issubclass

schema_version = "0.7"
filename = f"haystack-pipeline.{schema_version}.schema.json"
schema_version = __version__
filename = f"haystack-pipeline-{schema_version}.schema.json"
destination_path = Path(__file__).parent.parent.parent / "json-schemas" / filename


Expand Down
11 changes: 9 additions & 2 deletions docs/_src/api/api/pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Here's a sample configuration:

```python
| {
| "version": "0.9",
| "version": "1.0",
| "components": [
| { # define all the building-blocks for Pipeline
| "name": "MyReader", # custom-name for the component; helpful for visualization & debugging
Expand Down Expand Up @@ -110,7 +110,7 @@ be passed.
Here's a sample configuration:

```yaml
| version: '0.9'
| version: '1.0'
|
| components: # define all the building-blocks for Pipeline
| - name: MyReader # custom-name for the component; helpful for visualization & debugging
Expand All @@ -137,6 +137,9 @@ Here's a sample configuration:
| inputs: [MyESRetriever]
```

Note that, in case of a mismatch in version between Haystack and the YAML, a warning will be printed.
If the pipeline loads correctly regardless, save again the pipeline using `Pipeline.save_to_yaml()` to remove the warning.

**Arguments**:

- `path`: path of the YAML file.
Expand Down Expand Up @@ -605,6 +608,10 @@ Here's a sample configuration:
| inputs: [MyESRetriever]
```


Note that, in case of a mismatch in version between Haystack and the YAML, a warning will be printed.
If the pipeline loads correctly regardless, save again the pipeline using `RayPipeline.save_to_yaml()` to remove the warning.

**Arguments**:

- `path`: path of the YAML file.
Expand Down
34 changes: 31 additions & 3 deletions haystack/pipelines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ray = None # type: ignore
serve = None # type: ignore

from haystack import __version__
from haystack.schema import EvaluationResult, MultiLabel, Document
from haystack.nodes.base import BaseComponent
from haystack.document_stores.base import BaseDocumentStore
Expand Down Expand Up @@ -81,7 +82,7 @@ def load_from_config(
```python
| {
| "version": "0.9",
| "version": "1.0",
| "components": [
| { # define all the building-blocks for Pipeline
| "name": "MyReader", # custom-name for the component; helpful for visualization & debugging
Expand Down Expand Up @@ -146,7 +147,7 @@ def load_from_yaml(cls, path: Path, pipeline_name: Optional[str] = None, overwri
Here's a sample configuration:
```yaml
| version: '0.9'
| version: '1.0'
|
| components: # define all the building-blocks for Pipeline
| - name: MyReader # custom-name for the component; helpful for visualization & debugging
Expand All @@ -173,6 +174,9 @@ def load_from_yaml(cls, path: Path, pipeline_name: Optional[str] = None, overwri
| inputs: [MyESRetriever]
```
Note that, in case of a mismatch in version between Haystack and the YAML, a warning will be printed.
If the pipeline loads correctly regardless, save again the pipeline using `Pipeline.save_to_yaml()` to remove the warning.
:param path: path of the YAML file.
:param pipeline_name: if the YAML contains multiple pipelines, the pipeline_name to load must be set.
:param overwrite_with_env_variables: Overwrite the YAML configuration with environment variables. For example,
Expand All @@ -182,6 +186,14 @@ def load_from_yaml(cls, path: Path, pipeline_name: Optional[str] = None, overwri
"""

pipeline_config = cls._read_pipeline_config_from_yaml(path)
if pipeline_config["version"] != __version__:
logger.warning(
f"YAML version ({pipeline_config['version']}) does not match with Haystack version ({__version__}). "
"Issues may occur during loading. "
"To fix this warning, save again this pipeline with the current Haystack version using Pipeline.save_to_yaml(), "
"check out our migration guide at https://haystack.deepset.ai/overview/migration "
f"or downgrade to haystack version {__version__}."
)
return cls.load_from_config(
pipeline_config=pipeline_config,
pipeline_name=pipeline_name,
Expand Down Expand Up @@ -1037,7 +1049,11 @@ def get_config(self, return_defaults: bool = False) -> dict:
# create the Pipeline definition with how the Component are connected
pipelines[pipeline_name]["nodes"].append({"name": node, "inputs": list(self.graph.predecessors(node))})

config = {"components": list(components.values()), "pipelines": list(pipelines.values()), "version": "0.8"}
config = {
"components": list(components.values()),
"pipelines": list(pipelines.values()),
"version": __version__,
}
return config

def _format_document_answer(self, document_or_answer: dict):
Expand Down Expand Up @@ -1290,6 +1306,10 @@ def load_from_yaml(
| inputs: [MyESRetriever]
```
Note that, in case of a mismatch in version between Haystack and the YAML, a warning will be printed.
If the pipeline loads correctly regardless, save again the pipeline using `RayPipeline.save_to_yaml()` to remove the warning.
:param path: path of the YAML file.
:param pipeline_name: if the YAML contains multiple pipelines, the pipeline_name to load must be set.
:param overwrite_with_env_variables: Overwrite the YAML configuration with environment variables. For example,
Expand All @@ -1299,6 +1319,14 @@ def load_from_yaml(
:param address: The IP address for the Ray cluster. If set to None, a local Ray instance is started.
"""
pipeline_config = cls._read_pipeline_config_from_yaml(path)
if pipeline_config["version"] != __version__:
logger.warning(
f"YAML version ({pipeline_config['version']}) does not match with Haystack version ({__version__}). "
"Issues may occur during loading. "
"To fix this warning, save again this pipeline with the current Haystack version using Pipeline.save_to_yaml(), "
"check out our migration guide at https://haystack.deepset.ai/overview/migration "
f"or downgrade to haystack version {__version__}."
)
return RayPipeline.load_from_config(
pipeline_config=pipeline_config,
pipeline_name=pipeline_name,
Expand Down
Loading

0 comments on commit 2a840ee

Please sign in to comment.