From bfa8d3a100eb2cc3c50280cbf5c4cb692526c6fe Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 28 Aug 2023 15:54:19 -0600 Subject: [PATCH 01/17] Service Context to/from dict (#7395) --- llama_index/embeddings/base.py | 7 +- llama_index/embeddings/google.py | 5 + llama_index/embeddings/langchain.py | 5 + llama_index/embeddings/loading.py | 35 ++++++ llama_index/embeddings/openai.py | 5 + llama_index/indices/prompt_helper.py | 12 ++- llama_index/indices/service_context.py | 100 ++++++++++++++++++ llama_index/llm_predictor/base.py | 16 ++- llama_index/llm_predictor/loading.py | 25 +++++ llama_index/llm_predictor/mock.py | 5 + llama_index/llm_predictor/structured.py | 5 + llama_index/llm_predictor/vellum/predictor.py | 5 + llama_index/llms/anthropic.py | 5 + llama_index/llms/azure_openai.py | 5 + llama_index/llms/base.py | 3 +- llama_index/llms/custom.py | 5 + llama_index/llms/huggingface.py | 5 + llama_index/llms/langchain.py | 5 + llama_index/llms/llama_api.py | 5 + llama_index/llms/llama_cpp.py | 5 + llama_index/llms/loading.py | 38 +++++++ llama_index/llms/mock.py | 5 + llama_index/llms/monsterapi.py | 5 + llama_index/llms/openai.py | 7 ++ llama_index/llms/palm.py | 5 + llama_index/llms/predibase.py | 5 + llama_index/llms/replicate.py | 5 + llama_index/llms/xinference.py | 5 + llama_index/node_parser/extractors/loading.py | 39 +++++++ .../extractors/metadata_extractors.py | 56 +++++++++- llama_index/node_parser/hierarchical.py | 5 + llama_index/node_parser/interface.py | 11 +- llama_index/node_parser/loading.py | 30 ++++++ llama_index/node_parser/sentence_window.py | 10 ++ llama_index/node_parser/simple.py | 5 + .../query_engine/sub_question_query_engine.py | 4 +- llama_index/response_synthesizers/refine.py | 7 +- llama_index/schema.py | 77 +++++++++++++- llama_index/text_splitter/code_splitter.py | 5 + llama_index/text_splitter/loading.py | 22 ++++ .../text_splitter/sentence_splitter.py | 13 ++- llama_index/text_splitter/token_splitter.py | 13 ++- llama_index/text_splitter/types.py | 7 +- llama_index/token_counter/mock_embed_model.py | 9 +- tests/indices/knowledge_graph/test_base.py | 5 + tests/indices/query/test_compose_vector.py | 5 + tests/indices/query/test_query_bundle.py | 5 + tests/indices/test_service_context.py | 65 ++++++++++++ tests/indices/vector_store/mock_services.py | 5 + tests/playground/test_base.py | 5 + tests/response_synthesizers/test_refine.py | 7 +- 51 files changed, 700 insertions(+), 48 deletions(-) create mode 100644 llama_index/embeddings/loading.py create mode 100644 llama_index/llm_predictor/loading.py create mode 100644 llama_index/llms/loading.py create mode 100644 llama_index/node_parser/extractors/loading.py create mode 100644 llama_index/node_parser/loading.py create mode 100644 llama_index/text_splitter/loading.py create mode 100644 tests/indices/test_service_context.py diff --git a/llama_index/embeddings/base.py b/llama_index/embeddings/base.py index 83fe12896c808..05cae7ac335ee 100644 --- a/llama_index/embeddings/base.py +++ b/llama_index/embeddings/base.py @@ -8,12 +8,13 @@ import numpy as np try: - from pydantic.v1 import BaseModel, Field, PrivateAttr, validator + from pydantic.v1 import Field, validator, PrivateAttr except ImportError: - from pydantic import BaseModel, Field, PrivateAttr, validator + from pydantic import Field, validator, PrivateAttr from llama_index.callbacks.base import CallbackManager from llama_index.callbacks.schema import CBEventType, EventPayload +from llama_index.schema import BaseComponent from llama_index.utils import get_tqdm_iterable # TODO: change to numpy array @@ -53,7 +54,7 @@ def similarity( return product / norm -class BaseEmbedding(BaseModel): +class BaseEmbedding(BaseComponent): """Base class for embeddings.""" model_name: str = Field( diff --git a/llama_index/embeddings/google.py b/llama_index/embeddings/google.py index 12be5d0f36eb0..c492a9f5954e4 100644 --- a/llama_index/embeddings/google.py +++ b/llama_index/embeddings/google.py @@ -41,6 +41,11 @@ def __init__( model_name=handle, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "GoogleUnivSentEncoderEmbedding" + def _get_query_embedding(self, query: str) -> List[float]: """Get query embedding.""" return self._get_embedding(query) diff --git a/llama_index/embeddings/langchain.py b/llama_index/embeddings/langchain.py index 69b6e40121cc9..6194bf9295184 100644 --- a/llama_index/embeddings/langchain.py +++ b/llama_index/embeddings/langchain.py @@ -46,6 +46,11 @@ def __init__( model_name=model_name, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "LangchainEmbedding" + def _get_query_embedding(self, query: str) -> List[float]: """Get query embedding.""" return self._langchain_embedding.embed_query(query) diff --git a/llama_index/embeddings/loading.py b/llama_index/embeddings/loading.py new file mode 100644 index 0000000000000..1f1659f3c36a9 --- /dev/null +++ b/llama_index/embeddings/loading.py @@ -0,0 +1,35 @@ +from typing import Dict, Type + +from llama_index.embeddings.base import BaseEmbedding +from llama_index.embeddings.google import GoogleUnivSentEncoderEmbedding +from llama_index.embeddings.openai import OpenAIEmbedding +from llama_index.embeddings.langchain import LangchainEmbedding +from llama_index.embeddings.utils import resolve_embed_model +from llama_index.token_counter.mock_embed_model import MockEmbedding + +RECOGNIZED_EMBEDDINGS: Dict[str, Type[BaseEmbedding]] = { + GoogleUnivSentEncoderEmbedding.class_name(): GoogleUnivSentEncoderEmbedding, + OpenAIEmbedding.class_name(): OpenAIEmbedding, + LangchainEmbedding.class_name(): LangchainEmbedding, + MockEmbedding.class_name(): MockEmbedding, +} + + +def load_embed_model(data: dict) -> BaseEmbedding: + """Load Embedding by name.""" + name = data.get("class_name", None) + if name is None: + raise ValueError("Embedding loading requires a class_name") + if name not in RECOGNIZED_EMBEDDINGS: + raise ValueError(f"Invalid Embedding name: {name}") + + # special handling for LangchainEmbedding + # it can be any local model technially + if name == LangchainEmbedding.class_name(): + local_name = data.get("model_name", None) + if local_name is not None: + return resolve_embed_model("local:" + local_name) + else: + raise ValueError("LangchainEmbedding requires a model_name") + + return RECOGNIZED_EMBEDDINGS[name].from_dict(data) diff --git a/llama_index/embeddings/openai.py b/llama_index/embeddings/openai.py index cc639c360fcd6..35fb1f9f37829 100644 --- a/llama_index/embeddings/openai.py +++ b/llama_index/embeddings/openai.py @@ -272,6 +272,11 @@ def __init__( openai_kwargs=kwargs, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "OpenAIEmbedding" + def _get_query_embedding(self, query: str) -> List[float]: """Get query embedding.""" return get_embedding( diff --git a/llama_index/indices/prompt_helper.py b/llama_index/indices/prompt_helper.py index ef90c09eca635..71e07ec49a822 100644 --- a/llama_index/indices/prompt_helper.py +++ b/llama_index/indices/prompt_helper.py @@ -12,9 +12,9 @@ from typing import Callable, List, Optional, Sequence try: - from pydantic.v1 import BaseModel, Field, PrivateAttr + from pydantic.v1 import Field, PrivateAttr except ImportError: - from pydantic import BaseModel, Field, PrivateAttr + from pydantic import Field, PrivateAttr from llama_index.constants import DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS @@ -24,6 +24,7 @@ from llama_index.prompts.prompt_utils import get_empty_prompt_txt from llama_index.text_splitter import TokenTextSplitter from llama_index.text_splitter.utils import truncate_text +from llama_index.schema import BaseComponent from llama_index.utils import globals_helper DEFAULT_PADDING = 5 @@ -32,7 +33,7 @@ logger = logging.getLogger(__name__) -class PromptHelper(BaseModel): +class PromptHelper(BaseComponent): """Prompt helper. General prompt helper that can help deal with LLM context window token limitations. @@ -132,6 +133,11 @@ def from_llm_metadata( separator=separator, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "PromptHelper" + def _get_available_context_size(self, prompt: BasePromptTemplate) -> int: """Get available context size. diff --git a/llama_index/indices/service_context.py b/llama_index/indices/service_context.py index 6ae333bf241c0..72a7cccdc40b0 100644 --- a/llama_index/indices/service_context.py +++ b/llama_index/indices/service_context.py @@ -2,6 +2,11 @@ from dataclasses import dataclass from typing import Optional +try: + from pydantic.v1 import BaseModel +except ImportError: + from pydantic import BaseModel + import llama_index from llama_index.callbacks.base import CallbackManager from llama_index.embeddings.base import BaseEmbedding @@ -13,6 +18,7 @@ from llama_index.llms.utils import LLMType, resolve_llm from llama_index.logger import LlamaLogger from llama_index.node_parser.interface import NodeParser +from llama_index.node_parser.sentence_window import SentenceWindowNodeParser from llama_index.node_parser.simple import SimpleNodeParser from llama_index.prompts.base import BasePromptTemplate @@ -45,6 +51,17 @@ def _get_default_prompt_helper( return PromptHelper.from_llm_metadata(llm_metadata=llm_metadata) +class ServiceContextData(BaseModel): + llm: dict + llm_predictor: dict + prompt_helper: dict + embed_model: dict + node_parser: dict + text_splitter: Optional[dict] + metadata_extractor: Optional[dict] + extractors: Optional[list] + + @dataclass class ServiceContext: """Service Context container. @@ -255,6 +272,89 @@ def llm(self) -> LLM: raise ValueError("llm_predictor must be an instance of LLMPredictor") return self.llm_predictor.llm + def to_dict(self) -> dict: + """Convert service context to dict.""" + llm_dict = self.llm_predictor.llm.to_dict() + llm_predictor_dict = self.llm_predictor.to_dict() + + embed_model_dict = self.embed_model.to_dict() + + prompt_helper_dict = self.prompt_helper.to_dict() + + node_parser_dict = self.node_parser.to_dict() + + metadata_extractor_dict = None + extractor_dicts = None + text_splitter_dict = None + if isinstance(self.node_parser, SimpleNodeParser): + text_splitter_dict = self.node_parser.text_splitter.to_dict() + + if isinstance(self.node_parser, (SimpleNodeParser, SentenceWindowNodeParser)): + if self.node_parser.metadata_extractor: + metadata_extractor_dict = self.node_parser.metadata_extractor.to_dict() + extractor_dicts = [] + for extractor in self.node_parser.metadata_extractor.extractors: + extractor_dicts.append(extractor.to_dict()) + + return ServiceContextData( + llm=llm_dict, + llm_predictor=llm_predictor_dict, + prompt_helper=prompt_helper_dict, + embed_model=embed_model_dict, + node_parser=node_parser_dict, + text_splitter=text_splitter_dict, + metadata_extractor=metadata_extractor_dict, + extractors=extractor_dicts, + ).dict() + + @classmethod + def from_dict(cls, data: dict) -> "ServiceContext": + from llama_index.embeddings.loading import load_embed_model + from llama_index.llm_predictor.loading import load_predictor + from llama_index.llms.loading import load_llm + from llama_index.node_parser.loading import load_parser + from llama_index.node_parser.extractors.loading import load_extractor + from llama_index.text_splitter.loading import load_text_splitter + + service_context_data = ServiceContextData.parse_obj(data) + + llm = load_llm(service_context_data.llm) + llm_predictor = load_predictor(service_context_data.llm_predictor, llm=llm) + + embed_model = load_embed_model(service_context_data.embed_model) + + prompt_helper = PromptHelper.from_dict(service_context_data.prompt_helper) + + extractors = None + if service_context_data.extractors: + extractors = [] + for extractor_dict in service_context_data.extractors: + extractors.append(load_extractor(extractor_dict, llm=llm)) + + metadata_extractor = None + if service_context_data.metadata_extractor: + metadata_extractor = load_extractor( + service_context_data.metadata_extractor, + extractors=extractors, + ) + + text_splitter = None + if service_context_data.text_splitter: + text_splitter = load_text_splitter(service_context_data.text_splitter) + + node_parser = load_parser( + service_context_data.node_parser, + text_splitter=text_splitter, + metadata_extractor=metadata_extractor, + ) + + return cls.from_defaults( + llm_predictor=llm_predictor, + prompt_helper=prompt_helper, + embed_model=embed_model, + node_parser=node_parser, + ) + def set_global_service_context(service_context: Optional[ServiceContext]) -> None: """Helper function to set the global service context.""" diff --git a/llama_index/llm_predictor/base.py b/llama_index/llm_predictor/base.py index 09253dfc02b3d..6fb1d8a227bde 100644 --- a/llama_index/llm_predictor/base.py +++ b/llama_index/llm_predictor/base.py @@ -1,13 +1,13 @@ """Wrapper functions around an LLM chain.""" import logging -from abc import ABC, abstractmethod +from abc import abstractmethod, ABC from typing import Any, List, Optional try: - from pydantic.v1 import BaseModel, PrivateAttr + from pydantic.v1 import PrivateAttr except ImportError: - from pydantic import BaseModel, PrivateAttr + from pydantic import PrivateAttr from llama_index.callbacks.base import CallbackManager from llama_index.llm_predictor.utils import ( @@ -25,12 +25,13 @@ PromptTemplate, SelectorPromptTemplate, ) +from llama_index.schema import BaseComponent from llama_index.types import TokenAsyncGen, TokenGen logger = logging.getLogger(__name__) -class BaseLLMPredictor(BaseModel, ABC): +class BaseLLMPredictor(BaseComponent, ABC): """Base LLM Predictor.""" @property @@ -82,7 +83,7 @@ class Config: def __init__( self, - llm: Optional[LLMType] = None, + llm: Optional[LLMType] = "default", callback_manager: Optional[CallbackManager] = None, system_prompt: Optional[str] = None, query_wrapper_prompt: Optional[BasePromptTemplate] = None, @@ -97,6 +98,11 @@ def __init__( system_prompt=system_prompt, query_wrapper_prompt=query_wrapper_prompt ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "LLMPredictor" + @property def llm(self) -> LLM: """Get LLM.""" diff --git a/llama_index/llm_predictor/loading.py b/llama_index/llm_predictor/loading.py new file mode 100644 index 0000000000000..3c883973dff8d --- /dev/null +++ b/llama_index/llm_predictor/loading.py @@ -0,0 +1,25 @@ +from typing import Optional + +from llama_index.llm_predictor.base import BaseLLMPredictor, LLMPredictor +from llama_index.llm_predictor.structured import StructuredLLMPredictor +from llama_index.llm_predictor.mock import MockLLMPredictor +from llama_index.llm_predictor.vellum.predictor import VellumPredictor +from llama_index.llms.base import LLM + + +def load_predictor(data: dict, llm: Optional[LLM] = None) -> BaseLLMPredictor: + """Load predictor by class name.""" + predictor_name = data.get("class_name", None) + if predictor_name is None: + raise ValueError("Predictor loading requires a class_name") + + if predictor_name == LLMPredictor.class_name(): + return LLMPredictor.from_dict(data, llm=llm) + elif predictor_name == StructuredLLMPredictor.class_name(): + return StructuredLLMPredictor.from_dict(data, llm=llm) + elif predictor_name == MockLLMPredictor.class_name(): + return MockLLMPredictor.from_dict(data) + elif predictor_name == VellumPredictor.class_name(): + return VellumPredictor.from_dict(data) + else: + raise ValueError(f"Invalid predictor name: {predictor_name}") diff --git a/llama_index/llm_predictor/mock.py b/llama_index/llm_predictor/mock.py index caab2a0ee3673..de0e4bf67487c 100644 --- a/llama_index/llm_predictor/mock.py +++ b/llama_index/llm_predictor/mock.py @@ -93,6 +93,11 @@ class MockLLMPredictor(BaseLLMPredictor): default=DEFAULT_NUM_OUTPUTS, description="Number of tokens to mock generate." ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockLLMPredictor" + @property def metadata(self) -> LLMMetadata: return LLMMetadata() diff --git a/llama_index/llm_predictor/structured.py b/llama_index/llm_predictor/structured.py index 9dfcdb2e3618a..f358cf8292637 100644 --- a/llama_index/llm_predictor/structured.py +++ b/llama_index/llm_predictor/structured.py @@ -19,6 +19,11 @@ class StructuredLLMPredictor(LLMPredictor): """ + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "StructuredLLMPredictor" + def predict(self, prompt: BasePromptTemplate, **prompt_args: Any) -> str: """Predict the answer to a query. diff --git a/llama_index/llm_predictor/vellum/predictor.py b/llama_index/llm_predictor/vellum/predictor.py index efa253f21ea00..e9d7e39eaf35b 100644 --- a/llama_index/llm_predictor/vellum/predictor.py +++ b/llama_index/llm_predictor/vellum/predictor.py @@ -54,6 +54,11 @@ def __init__( super().__init__(callback_manager=callback_manager) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "VellumPredictor" + @property def metadata(self) -> LLMMetadata: """Get LLM metadata.""" diff --git a/llama_index/llms/anthropic.py b/llama_index/llms/anthropic.py index a015ae3f1d9f3..6fb837da73f60 100644 --- a/llama_index/llms/anthropic.py +++ b/llama_index/llms/anthropic.py @@ -92,6 +92,11 @@ def __init__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "Anthropic_LLM" + @property def metadata(self) -> LLMMetadata: return LLMMetadata( diff --git a/llama_index/llms/azure_openai.py b/llama_index/llms/azure_openai.py index cde92467d1b3b..652943f8c9500 100644 --- a/llama_index/llms/azure_openai.py +++ b/llama_index/llms/azure_openai.py @@ -91,3 +91,8 @@ def _model_kwargs(self) -> Dict[str, Any]: model_kwargs.pop("model") model_kwargs["engine"] = self.engine return model_kwargs + + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "azure_openai_llm" diff --git a/llama_index/llms/base.py b/llama_index/llms/base.py index b0551b295c75b..7d80045fa8717 100644 --- a/llama_index/llms/base.py +++ b/llama_index/llms/base.py @@ -11,6 +11,7 @@ from llama_index.callbacks import CallbackManager, CBEventType, EventPayload from llama_index.constants import DEFAULT_CONTEXT_WINDOW, DEFAULT_NUM_OUTPUTS +from llama_index.schema import BaseComponent class MessageRole(str, Enum): @@ -312,7 +313,7 @@ def dummy_wrapper(_self: Any, *args: Any, **kwargs: Any) -> Any: return wrap -class LLM(BaseModel): +class LLM(BaseComponent): """LLM interface.""" callback_manager: Optional[CallbackManager] = Field( diff --git a/llama_index/llms/custom.py b/llama_index/llms/custom.py index 5652a3c8b5f64..aa1c9dcdc99c4 100644 --- a/llama_index/llms/custom.py +++ b/llama_index/llms/custom.py @@ -71,3 +71,8 @@ async def gen() -> CompletionResponseAsyncGen: # NOTE: convert generator to async generator return gen() + + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "custom_llm" diff --git a/llama_index/llms/huggingface.py b/llama_index/llms/huggingface.py index d8a1b3399004b..ab842a0b31966 100644 --- a/llama_index/llms/huggingface.py +++ b/llama_index/llms/huggingface.py @@ -167,6 +167,11 @@ def __call__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "HuggingFace_LLM" + @property def metadata(self) -> LLMMetadata: """LLM metadata.""" diff --git a/llama_index/llms/langchain.py b/llama_index/llms/langchain.py index 96f6dbf4353eb..4691955c5aea6 100644 --- a/llama_index/llms/langchain.py +++ b/llama_index/llms/langchain.py @@ -41,6 +41,11 @@ def __init__( self._llm = llm super().__init__(callback_manager=callback_manager) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "LangChainLLM" + @property def llm(self) -> BaseLanguageModel: return self._llm diff --git a/llama_index/llms/llama_api.py b/llama_index/llms/llama_api.py index 5654cf3764ed6..cee254933b0a8 100644 --- a/llama_index/llms/llama_api.py +++ b/llama_index/llms/llama_api.py @@ -62,6 +62,11 @@ def __init__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "llama_api_llm" + @property def _model_kwargs(self) -> Dict[str, Any]: base_kwargs = { diff --git a/llama_index/llms/llama_cpp.py b/llama_index/llms/llama_cpp.py index 85ee7bcad51bc..c3fae8d49f52a 100644 --- a/llama_index/llms/llama_cpp.py +++ b/llama_index/llms/llama_cpp.py @@ -132,6 +132,11 @@ def __init__( verbose=verbose, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "LlamaCPP_llm" + @property def metadata(self) -> LLMMetadata: """LLM metadata.""" diff --git a/llama_index/llms/loading.py b/llama_index/llms/loading.py new file mode 100644 index 0000000000000..b43ee60e088fb --- /dev/null +++ b/llama_index/llms/loading.py @@ -0,0 +1,38 @@ +from typing import Dict, Type + +from llama_index.llms.base import LLM +from llama_index.llms.custom import CustomLLM +from llama_index.llms.huggingface import HuggingFaceLLM +from llama_index.llms.langchain import LangChainLLM +from llama_index.llms.llama_cpp import LlamaCPP +from llama_index.llms.mock import MockLLM +from llama_index.llms.openai import OpenAI +from llama_index.llms.palm import PaLM +from llama_index.llms.predibase import PredibaseLLM +from llama_index.llms.replicate import Replicate +from llama_index.llms.xinference import Xinference + + +RECOGNIZED_LLMS: Dict[str, Type[LLM]] = { + MockLLM.class_name(): MockLLM, + Replicate.class_name(): Replicate, + HuggingFaceLLM.class_name(): HuggingFaceLLM, + OpenAI.class_name(): OpenAI, + Xinference.class_name(): Xinference, + LlamaCPP.class_name(): LlamaCPP, + LangChainLLM.class_name(): LangChainLLM, + PaLM.class_name(): PaLM, + PredibaseLLM.class_name(): PredibaseLLM, + CustomLLM.class_name(): CustomLLM, +} + + +def load_llm(data: dict) -> LLM: + """Load LLM by name.""" + llm_name = data.get("class_name", None) + if llm_name is None: + raise ValueError("LLM loading requires a class_name") + if llm_name not in RECOGNIZED_LLMS: + raise ValueError(f"Invalid LLM name: {llm_name}") + + return RECOGNIZED_LLMS[llm_name].from_dict(data) diff --git a/llama_index/llms/mock.py b/llama_index/llms/mock.py index ccd12a8a694e8..cad5fd35c491b 100644 --- a/llama_index/llms/mock.py +++ b/llama_index/llms/mock.py @@ -20,6 +20,11 @@ def __init__( ) -> None: super().__init__(max_tokens=max_tokens, callback_manager=callback_manager) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockLLM" + @property def metadata(self) -> LLMMetadata: return LLMMetadata(num_output=self.max_tokens or -1) diff --git a/llama_index/llms/monsterapi.py b/llama_index/llms/monsterapi.py index 8e513bad23ef6..c65e6715ff51f 100644 --- a/llama_index/llms/monsterapi.py +++ b/llama_index/llms/monsterapi.py @@ -92,6 +92,11 @@ def initialize_client(self, monster_api_key: Optional[str]) -> Any: return MonsterClient(monster_api_key), llm_models_enabled + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MonsterLLM" + @property def metadata(self) -> LLMMetadata: """Get LLM metadata.""" diff --git a/llama_index/llms/openai.py b/llama_index/llms/openai.py index b5752eeec9829..7c35764c49235 100644 --- a/llama_index/llms/openai.py +++ b/llama_index/llms/openai.py @@ -42,6 +42,8 @@ class OpenAI(LLM): + class_type = "openai" + model: str = Field(description="The OpenAI model to use.") temperature: float = Field(description="The tempature to use during generation.") max_tokens: Optional[int] = Field( @@ -91,6 +93,11 @@ def _get_model_name(self) -> str: return model_name + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "openai_llm" + @property def metadata(self) -> LLMMetadata: return LLMMetadata( diff --git a/llama_index/llms/palm.py b/llama_index/llms/palm.py index fed7ac6db085b..43f99efd2e1fc 100644 --- a/llama_index/llms/palm.py +++ b/llama_index/llms/palm.py @@ -68,6 +68,11 @@ def __init__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "PaLM_llm" + @property def metadata(self) -> LLMMetadata: """Get LLM metadata.""" diff --git a/llama_index/llms/predibase.py b/llama_index/llms/predibase.py index ab2a541cd9dcf..ca51bac4f43ea 100644 --- a/llama_index/llms/predibase.py +++ b/llama_index/llms/predibase.py @@ -71,6 +71,11 @@ def initialize_client(self, predibase_api_key: str) -> Any: except ValueError as e: raise ValueError("Your API key is not correct. Please try again") from e + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "PredibaseLLM" + @property def metadata(self) -> LLMMetadata: """Get LLM metadata.""" diff --git a/llama_index/llms/replicate.py b/llama_index/llms/replicate.py index 46b049a204940..89fcbe24404a5 100644 --- a/llama_index/llms/replicate.py +++ b/llama_index/llms/replicate.py @@ -62,6 +62,11 @@ def __init__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "Replicate_llm" + @property def metadata(self) -> LLMMetadata: """LLM metadata.""" diff --git a/llama_index/llms/xinference.py b/llama_index/llms/xinference.py index 6a086c9bb23c6..ffb3b790c55c7 100644 --- a/llama_index/llms/xinference.py +++ b/llama_index/llms/xinference.py @@ -118,6 +118,11 @@ def load_model(self, model_uid: str, endpoint: str) -> Tuple[Any, int, dict]: return generator, context_window, model_description + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "Xinference_llm" + @property def metadata(self) -> LLMMetadata: """LLM metadata.""" diff --git a/llama_index/node_parser/extractors/loading.py b/llama_index/node_parser/extractors/loading.py new file mode 100644 index 0000000000000..43502cde1a9dd --- /dev/null +++ b/llama_index/node_parser/extractors/loading.py @@ -0,0 +1,39 @@ +from typing import List, Optional + +from llama_index.llms.base import LLM +from llama_index.node_parser.extractors.metadata_extractors import ( + MetadataExtractor, + SummaryExtractor, + QuestionsAnsweredExtractor, + EntityExtractor, + TitleExtractor, + KeywordExtractor, +) + + +def load_extractor( + data: dict, + extractors: Optional[List[MetadataExtractor]] = None, + llm: Optional[LLM] = None, +) -> MetadataExtractor: + extractor_name = data.get("class_name", None) + if extractor_name is None: + raise ValueError("Extractor loading requires a class_name") + + # remove unused key + data.pop("is_text_node_only", None) + + if extractor_name == MetadataExtractor.class_name(): + return MetadataExtractor.from_dict(data, extractors=extractors) + elif extractor_name == SummaryExtractor.class_name(): + return SummaryExtractor.from_dict(data, llm=llm) + elif extractor_name == QuestionsAnsweredExtractor.class_name(): + return QuestionsAnsweredExtractor.from_dict(data, llm=llm) + elif extractor_name == EntityExtractor.class_name(): + return EntityExtractor.from_dict(data) + elif extractor_name == TitleExtractor.class_name(): + return TitleExtractor.from_dict(data, llm=llm) + elif extractor_name == KeywordExtractor.class_name(): + return KeywordExtractor.from_dict(data, llm=llm) + else: + raise ValueError(f"Unknown extractor name: {extractor_name}") diff --git a/llama_index/node_parser/extractors/metadata_extractors.py b/llama_index/node_parser/extractors/metadata_extractors.py index 0c69b9a062e6f..babc9b31a59c6 100644 --- a/llama_index/node_parser/extractors/metadata_extractors.py +++ b/llama_index/node_parser/extractors/metadata_extractors.py @@ -77,6 +77,11 @@ class MetadataExtractor(BaseExtractor): default=True, description="Whether to process nodes in place." ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MetadataExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: """Extract metadata from a document. @@ -179,7 +184,11 @@ def __init__( """Init params.""" if nodes < 1: raise ValueError("num_nodes must be >= 1") - llm_predictor = llm_predictor or LLMPredictor(llm=llm) + + if llm is not None: + llm_predictor = LLMPredictor(llm=llm) + elif llm_predictor is None and llm is None: + llm_predictor = LLMPredictor() super().__init__( llm_predictor=llm_predictor, @@ -189,6 +198,11 @@ def __init__( **kwargs, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "TitleExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: nodes_to_extract_title: List[BaseNode] = [] for node in nodes: @@ -251,9 +265,19 @@ def __init__( """Init params.""" if keywords < 1: raise ValueError("num_keywords must be >= 1") - llm_predictor = llm_predictor or LLMPredictor(llm=llm) + + if llm is not None: + llm_predictor = LLMPredictor(llm=llm) + elif llm_predictor is None and llm is None: + llm_predictor = LLMPredictor() + super().__init__(llm_predictor=llm_predictor, keywords=keywords, **kwargs) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "KeywordExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: metadata_list: List[Dict] = [] for node in nodes: @@ -328,7 +352,12 @@ def __init__( """Init params.""" if questions < 1: raise ValueError("questions must be >= 1") - llm_predictor = llm_predictor or LLMPredictor(llm=llm) + + if llm is not None: + llm_predictor = LLMPredictor(llm=llm) + elif llm_predictor is None and llm is None: + llm_predictor = LLMPredictor() + super().__init__( llm_predictor=llm_predictor, questions=questions, @@ -337,6 +366,11 @@ def __init__( **kwargs, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "QuestionsAnsweredExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: metadata_list: List[Dict] = [] nodes_queue = get_tqdm_iterable( @@ -404,7 +438,11 @@ def __init__( prompt_template: str = DEFAULT_SUMMARY_EXTRACT_TEMPLATE, **kwargs: Any, ): - llm_predictor = llm_predictor or LLMPredictor(llm=llm) + if llm is not None: + llm_predictor = LLMPredictor(llm=llm) + elif llm_predictor is None and llm is None: + llm_predictor = LLMPredictor() + # validation if not all([s in ["self", "prev", "next"] for s in summaries]): raise ValueError("summaries must be one of ['self', 'prev', 'next']") @@ -419,6 +457,11 @@ def __init__( **kwargs, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "SummaryExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: if not all([isinstance(node, TextNode) for node in nodes]): raise ValueError("Only `TextNode` is allowed for `Summary` extractor") @@ -567,6 +610,11 @@ def __init__( **kwargs, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "EntityExtractor" + def extract(self, nodes: Sequence[BaseNode]) -> List[Dict]: # Extract node-level entity metadata metadata_list: List[Dict] = [{} for _ in nodes] diff --git a/llama_index/node_parser/hierarchical.py b/llama_index/node_parser/hierarchical.py index 8a542c9f24d2a..2f01bbf31de14 100644 --- a/llama_index/node_parser/hierarchical.py +++ b/llama_index/node_parser/hierarchical.py @@ -133,6 +133,11 @@ def from_defaults( metadata_extractor=metadata_extractor, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "HierarchicalNodeParser" + def _recursively_get_nodes_from_nodes( self, nodes: List[BaseNode], diff --git a/llama_index/node_parser/interface.py b/llama_index/node_parser/interface.py index c71bfcc831b89..63198cb708a57 100644 --- a/llama_index/node_parser/interface.py +++ b/llama_index/node_parser/interface.py @@ -2,15 +2,10 @@ from abc import ABC, abstractmethod from typing import Dict, List, Sequence -try: - from pydantic.v1 import BaseModel -except ImportError: - from pydantic import BaseModel +from llama_index.schema import BaseComponent, BaseNode, Document -from llama_index.schema import BaseNode, Document - -class NodeParser(BaseModel, ABC): +class NodeParser(BaseComponent, ABC): """Base interface for node parser.""" class Config: @@ -30,7 +25,7 @@ def get_nodes_from_documents( """ -class BaseExtractor(BaseModel, ABC): +class BaseExtractor(BaseComponent, ABC): """Base interface for feature extractor.""" class Config: diff --git a/llama_index/node_parser/loading.py b/llama_index/node_parser/loading.py new file mode 100644 index 0000000000000..52e93b3c31781 --- /dev/null +++ b/llama_index/node_parser/loading.py @@ -0,0 +1,30 @@ +from typing import Optional + +from llama_index.node_parser.interface import NodeParser +from llama_index.node_parser.simple import SimpleNodeParser +from llama_index.node_parser.sentence_window import SentenceWindowNodeParser +from llama_index.node_parser.extractors.metadata_extractors import MetadataExtractor +from llama_index.text_splitter.sentence_splitter import SentenceSplitter +from llama_index.text_splitter.types import TextSplitter + + +def load_parser( + data: dict, + text_splitter: Optional[TextSplitter] = None, + metadata_extractor: Optional[MetadataExtractor] = None, +) -> NodeParser: + parser_name = data.get("class_name", None) + if parser_name is None: + raise ValueError("Parser loading requires a class_name") + + if parser_name == SimpleNodeParser.class_name(): + return SimpleNodeParser.from_dict( + data, text_splitter=text_splitter, metadata_extractor=metadata_extractor + ) + elif parser_name == SentenceWindowNodeParser.class_name(): + assert isinstance(text_splitter, (type(None), SentenceSplitter)) + return SentenceWindowNodeParser.from_dict( + data, sentence_splitter=text_splitter, metadata_extractor=metadata_extractor + ) + else: + raise ValueError(f"Unknown parser name: {parser_name}") diff --git a/llama_index/node_parser/sentence_window.py b/llama_index/node_parser/sentence_window.py index c1a7c6a9275fb..02ced2656d928 100644 --- a/llama_index/node_parser/sentence_window.py +++ b/llama_index/node_parser/sentence_window.py @@ -87,6 +87,16 @@ def __init__( metadata_extractor=metadata_extractor, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "SentenceWindowNodeParser" + + @property + def text_splitter(self) -> Callable[[str], List[str]]: + """Get text splitter.""" + return self.sentence_splitter + @classmethod def from_defaults( cls, diff --git a/llama_index/node_parser/simple.py b/llama_index/node_parser/simple.py index cc78781d3b264..7f1653afde342 100644 --- a/llama_index/node_parser/simple.py +++ b/llama_index/node_parser/simple.py @@ -70,6 +70,11 @@ def from_defaults( metadata_extractor=metadata_extractor, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "SimpleNodeParser" + def get_nodes_from_documents( self, documents: Sequence[Document], diff --git a/llama_index/query_engine/sub_question_query_engine.py b/llama_index/query_engine/sub_question_query_engine.py index e1ee426175056..dd8e7c8ef7208 100644 --- a/llama_index/query_engine/sub_question_query_engine.py +++ b/llama_index/query_engine/sub_question_query_engine.py @@ -31,8 +31,8 @@ class SubQuestionAnswerPair(BaseModel): """ sub_q: SubQuestion - answer: Optional[str] - sources: Optional[List[NodeWithScore]] + answer: Optional[str] = None + sources: Optional[List[NodeWithScore]] = None class SubQuestionQueryEngine(BaseQueryEngine): diff --git a/llama_index/response_synthesizers/refine.py b/llama_index/response_synthesizers/refine.py index 58eb5f66c7fbe..b9509f32f7010 100644 --- a/llama_index/response_synthesizers/refine.py +++ b/llama_index/response_synthesizers/refine.py @@ -1,6 +1,11 @@ import logging from typing import Any, Generator, Optional, Sequence, cast, Type, Callable -from pydantic import BaseModel, Field + +try: + from pydantic.v1 import BaseModel, Field +except ImportError: + from pydantic import BaseModel, Field + from llama_index.indices.service_context import ServiceContext from llama_index.prompts.base import BasePromptTemplate, PromptTemplate from llama_index.llm_predictor.base import BaseLLMPredictor diff --git a/llama_index/schema.py b/llama_index/schema.py index 5b256899b0a44..eb6492dea6963 100644 --- a/llama_index/schema.py +++ b/llama_index/schema.py @@ -1,9 +1,11 @@ """Base schema for data structures.""" +import json import uuid from abc import abstractmethod from enum import Enum, auto from hashlib import sha256 from typing import Any, Dict, List, Optional, Union +from typing_extensions import Self try: from pydantic.v1 import BaseModel, Field, root_validator @@ -17,6 +19,38 @@ DEFAULT_METADATA_TMPL = "{key}: {value}" +class BaseComponent(BaseModel): + """Base component object to caputure class names.""" + + @classmethod + @abstractmethod + def class_name(cls) -> str: + """Get class name.""" + + def to_dict(self, **kwargs: Any) -> Dict[str, Any]: + data = self.dict(**kwargs) + data["class_name"] = self.class_name() + return data + + def to_json(self, **kwargs: Any) -> str: + data = self.to_dict(**kwargs) + return json.dumps(data) + + # TODO: return type here not supported by current mypy version + @classmethod + def from_dict(cls, data: Dict[str, Any], **kwargs: Any) -> Self: # type: ignore + if isinstance(kwargs, dict): + data.update(kwargs) + + data.pop("class_name", None) + return cls(**data) + + @classmethod + def from_json(cls, data_str: str, **kwargs: Any) -> Self: # type: ignore + data = json.loads(data_str) + return cls.from_dict(data, **kwargs) + + class NodeRelationship(str, Enum): """Node relationships used in `BaseNode` class. @@ -50,20 +84,23 @@ class MetadataMode(str, Enum): NONE = auto() -class RelatedNodeInfo(BaseModel): +class RelatedNodeInfo(BaseComponent): node_id: str node_type: Optional[ObjectType] = None metadata: Dict[str, Any] = Field(default_factory=dict) hash: Optional[str] = None + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "RelatedNodeInfo" + RelatedNodeType = Union[RelatedNodeInfo, List[RelatedNodeInfo]] # Node classes for indexes - - -class BaseNode(BaseModel): +class BaseNode(BaseComponent): """Base node Object. Generic abstract interface for retrievable nodes @@ -243,6 +280,11 @@ class TextNode(BaseNode): description="Seperator between metadata fields when converting to string.", ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "TextNode" + @root_validator def _check_hash(cls, values: dict) -> dict: """Generate a hash to represent the node.""" @@ -324,6 +366,11 @@ class ImageNode(TextNode): def get_type(cls) -> str: return ObjectType.IMAGE + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "ImageNode" + class IndexNode(TextNode): """Node with reference to an index.""" @@ -334,8 +381,13 @@ class IndexNode(TextNode): def get_type(cls) -> str: return ObjectType.INDEX + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "IndexNode" + -class NodeWithScore(BaseModel): +class NodeWithScore(BaseComponent): node: BaseNode score: Optional[float] = None @@ -349,6 +401,11 @@ def get_score(self, raise_error: bool = False) -> float: else: return self.score + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "NodeWithScore" + # Document Classes for Readers @@ -406,9 +463,19 @@ def example(cls) -> "Document": ) return document + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "Document" + class ImageDocument(Document): """Data document containing an image.""" # base64 encoded image str image: Optional[str] = None + + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "ImageDocument" diff --git a/llama_index/text_splitter/code_splitter.py b/llama_index/text_splitter/code_splitter.py index e530d1f0b5e65..63f10ef7416f8 100644 --- a/llama_index/text_splitter/code_splitter.py +++ b/llama_index/text_splitter/code_splitter.py @@ -57,6 +57,11 @@ def __init__( callback_manager=callback_manager, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "CodeSplitter" + def _chunk_node(self, node: Any, text: str, last_end: int = 0) -> List[str]: new_chunks = [] current_chunk = "" diff --git a/llama_index/text_splitter/loading.py b/llama_index/text_splitter/loading.py new file mode 100644 index 0000000000000..a792a4424c0db --- /dev/null +++ b/llama_index/text_splitter/loading.py @@ -0,0 +1,22 @@ +from typing import Dict, Type + +from llama_index.text_splitter.code_splitter import CodeSplitter +from llama_index.text_splitter.sentence_splitter import SentenceSplitter +from llama_index.text_splitter.token_splitter import TokenTextSplitter +from llama_index.text_splitter.types import TextSplitter + +RECOGNIZED_TEXT_SPLITTERS: Dict[str, Type[TextSplitter]] = { + SentenceSplitter.class_name(): SentenceSplitter, + TokenTextSplitter.class_name(): TokenTextSplitter, + CodeSplitter.class_name(): CodeSplitter, +} + + +def load_text_splitter(data: dict) -> TextSplitter: + text_splitter_name = data.get("class_name", None) + if text_splitter_name is None: + raise ValueError("TextSplitter loading requires a class_name") + if text_splitter_name not in RECOGNIZED_TEXT_SPLITTERS: + raise ValueError(f"Invalid TextSplitter name: {text_splitter_name}") + + return RECOGNIZED_TEXT_SPLITTERS[text_splitter_name].from_dict(data) diff --git a/llama_index/text_splitter/sentence_splitter.py b/llama_index/text_splitter/sentence_splitter.py index 542a305e88fb2..5ce70babc2afb 100644 --- a/llama_index/text_splitter/sentence_splitter.py +++ b/llama_index/text_splitter/sentence_splitter.py @@ -45,11 +45,11 @@ class SentenceSplitter(MetadataAwareTextSplitter): default=SENTENCE_CHUNK_OVERLAP, description="The token overlap of each chunk when splitting.", ) - seperator: str = Field( - default=" ", description="Default seperator for splitting into words" + separator: str = Field( + default=" ", description="Default separator for splitting into words" ) - paragraph_seperator: List = Field( - default=DEFUALT_PARAGRAPH_SEP, description="Seperator between paragraphs." + paragraph_separator: str = Field( + default=DEFUALT_PARAGRAPH_SEP, description="Separator between paragraphs." ) secondary_chunking_regex: str = Field( default=CHUNKING_REGEX, description="Backup regex for splitting into sentences." @@ -117,6 +117,11 @@ def __init__( tokenizer=tokenizer, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "SentenceSplitter" + def split_text_metadata_aware(self, text: str, metadata_str: str) -> List[str]: metadata_len = len(self.tokenizer(metadata_str)) effective_chunk_size = self.chunk_size - metadata_len diff --git a/llama_index/text_splitter/token_splitter.py b/llama_index/text_splitter/token_splitter.py index 0c91341886a4c..26fa41afd4b81 100644 --- a/llama_index/text_splitter/token_splitter.py +++ b/llama_index/text_splitter/token_splitter.py @@ -30,11 +30,11 @@ class TokenTextSplitter(MetadataAwareTextSplitter): default=DEFAULT_CHUNK_OVERLAP, description="The token overlap of each chunk when splitting.", ) - seperator: str = Field( - default=" ", description="Default seperator for splitting into words" + separator: str = Field( + default=" ", description="Default separator for splitting into words" ) - backup_seperators: List = Field( - default_factory=list, description="Additional seperators for splitting." + backup_separators: List = Field( + default_factory=list, description="Additional separators for splitting." ) callback_manager: CallbackManager = Field( default_factory=CallbackManager, exclude=True @@ -77,6 +77,11 @@ def __init__( tokenizer=tokenizer, ) + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "TokenTextSplitter" + def split_text_metadata_aware(self, text: str, metadata_str: str) -> List[str]: """Split text into chunks, reserving space required for metadata str.""" metadata_len = len(self.tokenizer(metadata_str)) + DEFAULT_METADATA_FORMAT_LEN diff --git a/llama_index/text_splitter/types.py b/llama_index/text_splitter/types.py index bf3c38c8fad54..5e9d42a490899 100644 --- a/llama_index/text_splitter/types.py +++ b/llama_index/text_splitter/types.py @@ -2,13 +2,10 @@ from abc import ABC, abstractmethod from typing import List -try: - from pydantic.v1 import BaseModel -except ImportError: - from pydantic import BaseModel +from llama_index.schema import BaseComponent -class TextSplitter(ABC, BaseModel): +class TextSplitter(ABC, BaseComponent): class Config: arbitrary_types_allowed = True diff --git a/llama_index/token_counter/mock_embed_model.py b/llama_index/token_counter/mock_embed_model.py index 40e1f3cb498bc..00b3a38745970 100644 --- a/llama_index/token_counter/mock_embed_model.py +++ b/llama_index/token_counter/mock_embed_model.py @@ -17,9 +17,14 @@ class MockEmbedding(BaseEmbedding): embed_dim: int - def __init__(self, embed_dim: int, *args: Any, **kwargs: Any) -> None: + def __init__(self, embed_dim: int, **kwargs: Any) -> None: """Init params.""" - super().__init__(embed_dim=embed_dim, *args, *kwargs) + super().__init__(embed_dim=embed_dim, **kwargs) + + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" def _get_vector(self) -> List[float]: return [0.5] * self.embed_dim diff --git a/tests/indices/knowledge_graph/test_base.py b/tests/indices/knowledge_graph/test_base.py index f7e373f91ae50..127fc761902b4 100644 --- a/tests/indices/knowledge_graph/test_base.py +++ b/tests/indices/knowledge_graph/test_base.py @@ -17,6 +17,11 @@ class MockEmbedding(BaseEmbedding): + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" + async def _aget_query_embedding(self, query: str) -> List[float]: del query return [0, 0, 1, 0, 0] diff --git a/tests/indices/query/test_compose_vector.py b/tests/indices/query/test_compose_vector.py index f652efa260eca..b85b19a5e8ba0 100644 --- a/tests/indices/query/test_compose_vector.py +++ b/tests/indices/query/test_compose_vector.py @@ -17,6 +17,11 @@ class MockEmbedding(BaseEmbedding): + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" + async def _aget_query_embedding(self, query: str) -> List[float]: if query == "Foo?": return [0, 0, 1, 0, 0] diff --git a/tests/indices/query/test_query_bundle.py b/tests/indices/query/test_query_bundle.py index ea2901a45300f..ac1cd2174af0a 100644 --- a/tests/indices/query/test_query_bundle.py +++ b/tests/indices/query/test_query_bundle.py @@ -26,6 +26,11 @@ def documents() -> List[Document]: class MockEmbedding(BaseEmbedding): + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" + async def _aget_query_embedding(self, query: str) -> List[float]: text_embed_map: Dict[str, List[float]] = { "It is what it is.": [1.0, 0.0, 0.0, 0.0, 0.0], diff --git a/tests/indices/test_service_context.py b/tests/indices/test_service_context.py new file mode 100644 index 0000000000000..195485c9b4d5f --- /dev/null +++ b/tests/indices/test_service_context.py @@ -0,0 +1,65 @@ +from llama_index.indices.prompt_helper import PromptHelper +from llama_index.indices.service_context import ServiceContext +from llama_index.text_splitter import TokenTextSplitter +from llama_index.node_parser import SimpleNodeParser +from llama_index.node_parser.extractors import ( + MetadataExtractor, + SummaryExtractor, + QuestionsAnsweredExtractor, + TitleExtractor, +) +from llama_index.llms import MockLLM +from llama_index.token_counter.mock_embed_model import MockEmbedding + + +def test_service_context_serialize() -> None: + text_splitter = TokenTextSplitter(chunk_size=1, chunk_overlap=0) + + metadata_extractor = MetadataExtractor( + extractors=[ + SummaryExtractor(), + QuestionsAnsweredExtractor(), + TitleExtractor(), + ] + ) + + node_parser = SimpleNodeParser.from_defaults( + text_splitter=text_splitter, metadata_extractor=metadata_extractor + ) + + llm = MockLLM(max_tokens=1) + embed_model = MockEmbedding(embed_dim=1) + + prompt_helper = PromptHelper(context_window=1) + + service_context = ServiceContext.from_defaults( + llm=llm, + embed_model=embed_model, + node_parser=node_parser, + prompt_helper=prompt_helper, + ) + + service_context_dict = service_context.to_dict() + + assert service_context_dict["llm"]["max_tokens"] == 1 + assert service_context_dict["embed_model"]["embed_dim"] == 1 + assert service_context_dict["text_splitter"]["chunk_size"] == 1 + assert len(service_context_dict["extractors"]) == 3 + assert service_context_dict["prompt_helper"]["context_window"] == 1 + + loaded_service_context = ServiceContext.from_dict(service_context_dict) + + assert isinstance(loaded_service_context.llm, MockLLM) + assert isinstance(loaded_service_context.embed_model, MockEmbedding) + assert isinstance(loaded_service_context.node_parser, SimpleNodeParser) + assert isinstance(loaded_service_context.prompt_helper, PromptHelper) + assert isinstance( + loaded_service_context.node_parser.text_splitter, TokenTextSplitter + ) + + assert loaded_service_context.node_parser.metadata_extractor is not None + assert len(loaded_service_context.node_parser.metadata_extractor.extractors) == 3 + assert loaded_service_context.node_parser.text_splitter.chunk_size == 1 + assert loaded_service_context.prompt_helper.context_window == 1 + assert loaded_service_context.llm.max_tokens == 1 + assert loaded_service_context.embed_model.embed_dim == 1 diff --git a/tests/indices/vector_store/mock_services.py b/tests/indices/vector_store/mock_services.py index dd570d0d5c3fc..b3bb5208c038a 100644 --- a/tests/indices/vector_store/mock_services.py +++ b/tests/indices/vector_store/mock_services.py @@ -4,6 +4,11 @@ class MockEmbedding(BaseEmbedding): + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" + async def _aget_query_embedding(self, query: str) -> List[float]: del query return [0, 0, 1, 0, 0] diff --git a/tests/playground/test_base.py b/tests/playground/test_base.py index b16355f1b23cb..30821ce9915b5 100644 --- a/tests/playground/test_base.py +++ b/tests/playground/test_base.py @@ -14,6 +14,11 @@ class MockEmbedding(BaseEmbedding): + @classmethod + def class_name(cls) -> str: + """Get class name.""" + return "MockEmbedding" + async def _aget_query_embedding(self, query: str) -> List[float]: del query return [0, 0, 1, 0, 0] diff --git a/tests/response_synthesizers/test_refine.py b/tests/response_synthesizers/test_refine.py index 3cf4eec9b563a..e65ec0e095046 100644 --- a/tests/response_synthesizers/test_refine.py +++ b/tests/response_synthesizers/test_refine.py @@ -1,6 +1,11 @@ from typing import Any, Dict, Optional, Type, cast from collections import OrderedDict -from pydantic import BaseModel + +try: + from pydantic.v1 import BaseModel +except ImportError: + from pydantic import BaseModel + import pytest from llama_index.indices.service_context import ServiceContext from llama_index.callbacks import CallbackManager From ca898f3260cb2b514eb8484dbc0b2443a6c4d903 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Tue, 29 Aug 2023 01:32:46 +0300 Subject: [PATCH 02/17] Add example how to run FalkorDB docker (#7441) --- .../knowledge_graph/FalkorDBGraphDemo.ipynb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/examples/index_structs/knowledge_graph/FalkorDBGraphDemo.ipynb b/docs/examples/index_structs/knowledge_graph/FalkorDBGraphDemo.ipynb index 1fd253271853c..2a7218c28d908 100644 --- a/docs/examples/index_structs/knowledge_graph/FalkorDBGraphDemo.ipynb +++ b/docs/examples/index_structs/knowledge_graph/FalkorDBGraphDemo.ipynb @@ -48,6 +48,22 @@ "## Using Knowledge Graph with FalkorDBGraphStore" ] }, + { + "cell_type": "markdown", + "id": "554d96c3", + "metadata": {}, + "source": [ + "### Start FalkorDB\n", + "\n", + "The easiest way to start FalkorDB as a Graph database is using the [falkordb](https://hub.docker.com/r/falkordb/falkordb:edge) docker image.\n", + "\n", + "To follow every step of this tutorial, launch the image as follows:\n", + "\n", + "```bash\n", + "docker run -p 6379:6379 -it --rm falkordb/falkordb:edge\n", + "```" + ] + }, { "cell_type": "code", "execution_count": 3, From 61cf225f7b409be6a457dcf11542a2ca72d75103 Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Mon, 28 Aug 2023 15:38:13 -0700 Subject: [PATCH 03/17] add openai finetuning class (#7442) --- docs/api_reference/finetuning.rst | 8 + docs/api_reference/index.rst | 1 + docs/end_to_end_tutorials/finetuning.md | 10 + docs/examples/finetuning/eval_questions.txt | 40 + .../finetuning/finetuning_events.jsonl | 61 ++ .../finetuning/openai_fine_tuning.ipynb | 874 ++++++++++++++++++ docs/examples/finetuning/train_questions.txt | 40 + llama_index/finetuning/__init__.py | 5 + llama_index/finetuning/openai/__init__.py | 1 + llama_index/finetuning/openai/base.py | 116 +++ .../finetuning/openai/validate_json.py | 178 ++++ llama_index/finetuning/types.py | 17 + 12 files changed, 1351 insertions(+) create mode 100644 docs/api_reference/finetuning.rst create mode 100644 docs/examples/finetuning/eval_questions.txt create mode 100644 docs/examples/finetuning/finetuning_events.jsonl create mode 100644 docs/examples/finetuning/openai_fine_tuning.ipynb create mode 100644 docs/examples/finetuning/train_questions.txt create mode 100644 llama_index/finetuning/__init__.py create mode 100644 llama_index/finetuning/openai/__init__.py create mode 100644 llama_index/finetuning/openai/base.py create mode 100644 llama_index/finetuning/openai/validate_json.py create mode 100644 llama_index/finetuning/types.py diff --git a/docs/api_reference/finetuning.rst b/docs/api_reference/finetuning.rst new file mode 100644 index 0000000000000..df4964c495a3e --- /dev/null +++ b/docs/api_reference/finetuning.rst @@ -0,0 +1,8 @@ +.. _Ref-Finetuning: + +Finetuning +============= + +.. automodule:: llama_index.finetuning + :members: + :inherited-members: diff --git a/docs/api_reference/index.rst b/docs/api_reference/index.rst index 0dda2e177dd85..f1e7f1348f8d5 100644 --- a/docs/api_reference/index.rst +++ b/docs/api_reference/index.rst @@ -24,5 +24,6 @@ API Reference for the ``llama-index`` package. struct_store.rst response.rst playground.rst + finetuning.rst example_notebooks.rst langchain_integrations/base.rst diff --git a/docs/end_to_end_tutorials/finetuning.md b/docs/end_to_end_tutorials/finetuning.md index a6351fb91ef68..01765ff70bd56 100644 --- a/docs/end_to_end_tutorials/finetuning.md +++ b/docs/end_to_end_tutorials/finetuning.md @@ -52,6 +52,16 @@ We use GPT-4 to automatically generate questions from any unstructured context, We then launch a finetuning job, and get back a distilled model. We can evaluate this model with [Ragas](https://github.com/explodinggradients/ragas) to benchmark against a naive GPT-3.5 pipeline. +```{toctree} +--- +maxdepth: 1 +--- +GPT-3.5 Fine-tuning Notebook (Colab) +GPT-3.5 Fine-tuning Notebook (in Repo) +``` + +**Old** + ```{toctree} --- maxdepth: 1 diff --git a/docs/examples/finetuning/eval_questions.txt b/docs/examples/finetuning/eval_questions.txt new file mode 100644 index 0000000000000..6002cb7d114cb --- /dev/null +++ b/docs/examples/finetuning/eval_questions.txt @@ -0,0 +1,40 @@ +What is the projected increase in global mean sea surface temperature (SST) by the end of the 21st century according to CMIP6 models under the SSP5-8.5 scenario? +What is driving the global increase in the frequency of extreme sea levels according to the provided context? +What is the potential ecological consequence of wetland salinization? +Question: According to the context information, which study explores the impacts of fishing and the environment on the Celtic Sea ecosystem since 1950? +Question: According to the provided context, what is the title of the report that discusses the impacts, adaptation, and vulnerability of the world's coral reefs to climate change? +What are some factors that can amplify vulnerability to climate-induced drivers in oceans and coastal ecosystems? +What are the potential effects of ocean acidification on coccolithophores and macroalgae, and how do they interact with warming? +What is one factor that can amplify the detrimental impacts of ocean acidification on the coccolithophore Emiliania huxleyi? +What is the title of the article mentioned in the context that discusses the Arctic Marine Pulses Model? +What is the title of the article that discusses the importance of diverse defense solutions for climate-resilient coasts? +What is the title of the scientific paper that discusses the ecological effects of elevated CO2 on marine and freshwater fishes? +What are the different types of adaptation solutions for ocean and coastal ecosystems that address climate-change risk? +What is a key barrier globally for ocean health, governance, and adaptation to climate change according to the report? +What are some mechanisms that can confer resilience to marine-dependent communities in the face of trigger events like marine heatwaves? +What is the estimated mean rate of change in seasonal timing for phytoplankton based on field observations? +What is the focus of all studies on phenological changes for marine mammals mentioned in the context? +What is the projected increase in the frequency of the current 1-in-100-year extreme sea level by 2050 across tide-gauge sites, regardless of emission scenario? +What is the projected future decline of the Atlantic meridional overturning circulation (AMOC) over the 21st century according to the IPCC AR6 report? +What are the projected changes in total seafloor biomass under climate change according to the updated simulations with the benthic biomass model? +What are some of the challenges faced by Earth System Models (ESMs) in accurately simulating primary production and biogeochemical tracers? +What percentage of the currently protected area is projected to provide refuges from both sea surface temperature (SST) and deoxygenation by 2050 under both RCP4.5 and RCP8.5 scenarios? +What is the proposed global conservation target for protecting the ocean by 2030 according to the UN CBD? +What are some technology-based approaches that can aid in enhancing resilience and reviving biodiversity in marine ecosystems? +What are the potential consequences of rapid sea level rise after the last glacial-interglacial transition? +What are the near-term adaptation options for existing coastal developments in response to sea level rise? +What is the likely range of global mean sea level rise between 1995-2014 and 2050 under the SSP5-8.5 emissions scenario? +What are the projected surface warming thresholds that exceed 2°C in the CMIP6 models for the end of the century in different Shared Socioeconomic Pathways (SSPs)? +What is the title of the publication that discusses the metabolic impacts of climate change on marine ecosystems and their implications for fish communities and fisheries? +What is the title of the report on climate change and the oceans? +What is the potential impact of global warming on marine species richness around the equator? +What are the impacts of mass coral bleaching events and disease outbreaks on coral reefs and coastal ecosystems? +What does experimental evidence suggest about coral responses to ocean acidification? +What are the projected declines in the oxygen content of the subsurface ocean over the 21st century according to the CMIP6 models? +What are some projected changes in the 21st century for ocean and coastal ecosystems in relation to climate change? +What percentage of the ocean was in fully or highly protected Marine Protected Areas (MPAs) in 2021? +What is the economic impact of ocean acidification on an Alaska crab fishery? +Question: According to the provided context on climate change and the oceans, which study highlights the transformative potential of managed retreat as a climate adaptation strategy? +What is the potential impact of marine heatwaves on global biodiversity and ecosystem services? +What are some consequences of abrupt ecosystem shifts in oceans and coastal ecosystems due to climate change? +What is the main cause of the increase in marine heatwaves (MHWs) between 1981 and 2017 according to the report? diff --git a/docs/examples/finetuning/finetuning_events.jsonl b/docs/examples/finetuning/finetuning_events.jsonl new file mode 100644 index 0000000000000..332dc575832aa --- /dev/null +++ b/docs/examples/finetuning/finetuning_events.jsonl @@ -0,0 +1,61 @@ +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 410\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nIt is challenging to apply this experimental approach to communities or ecosystems (see Figure \nBox\u00a03.1.1).To date, most research on community or ecosystem response to climate-induced drivers has been in large-volume (>10,000 l) \nmesocosms (Riebesell and Gattuso, 2014), or at natural analogues such as CO 2 seeps, in which only one driver (ocean acidification) is \naltered (see (4) in Figure Box\u00a03.1.1).Only very recently have two drivers been incorporated into climate-change manipulation studies \nexamining responses of primary producers to secondary consumers (see (5) in Figure Box\u00a03.1.1a; Nagelkerken et\u00a0al., 2020).Therefore, \n\u2018natural experiments\u2019 from the geological past (Reddin et\u00a0al., 2020) provide insights into how food webs and their constituents respond to \ncomplex change involving multiple drivers.Contemporary observations are occasionally long enough (>50\u00a0years) to capture community \nresponses to complex climate change.For example, Brun et\u00a0al.(2019) reported a shift in zooplankton community structure in the North \nAtlantic (1960\u20132014), with major biogeochemical ramifications.Conducting sufficiently long manipulation experiments to study the effect of adaptation on organisms is equally difficult (see Figure \nBox\u00a03.1.1b), with much research restricted to multi-year studies of the microevolution of fast-growing (more than one division per day) \nphytoplankton species responding to single drivers (Lohbeck et\u00a0al., 2012; Schaum et\u00a0al., 2016).In a few experimental evolution studies \n(see (7) in Figure Box\u00a03.1.1a; Brennan et\u00a0al., 2017), multiple drivers have been used, but none have used communities or ecosystems (see \nFigure Box\u00a03.1.1b).Nevertheless, the fossil record provides limited evidence of adaptations to less rapid (relative to present day) climate \nchange (Jackson et\u00a0al., 2018).Despite the need to explore ecological or biogeochemical responses to projected future ocean conditions, \nlogistical challenges require that assessments of climate-change impacts at scales larger than mesocosms use large-scale, long-term in \nsitu observational studies (as documented in Section\u00a03.4).\n\npage_label: 409\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n409Oceans and Coastal Ecosystems and Their Services Chapter 3\nunderlies inhibited thermal adaptation under nitrogen-limited \nconditions (low confidence) (Aranguren-Gassis et\u00a0 al., 2019).When \nselection is strong due to unfavourable environmental conditions, \nmicrobial populations can encounter functional and evolutionary \ntrade-offs evidenced by reducing growth rates while increasing \ntolerance and metabolism of reactive oxygen species (Lindberg and \nCollins, 2020).Other trade-offs can be observed in offspring quality \nand number (Lindberg and Collins, 2020).These findings contribute \ntowards a mechanistic framework describing the range of evolutionary \nstrategies in response to multiple drivers (Collins et\u00a0al., 2020), but other \nhazards, such as extreme events (e.g., MHWs), still need to be included \nbecause their characteristics may alter the potential for adaptation of \nspecies and populations to climate change (Gruber et\u00a0al., 2021).3.3.5 Ecological Response to Multiple Drivers\nAssessing ecological responses to multiple climate-induced drivers \nrequires a combination of approaches, including laboratory- and \nfield-based experiments, field observations (e.g., natural gradients, \nclimate analogues), study of paleo-analogues and the development \nof mechanistic and empirical models (Clapham, 2019; Gissi et\u00a0 al., \n2021).Experimental studies of food-web responses are often limited \nto an individual driver, although recent manipulations have used a \nmatrix of >1000-l mesocosms to explore ecological responses to both \nwarming and acidification (see Box\u00a0 3.1; Nagelkerken et\u00a0 al., 2020).Hence, complementary approaches are needed to indirectly explore \nthe mechanisms underlying ecosystem responses to global climate \nchange (Parmesan et\u00a0al., 2013).Observations from time series longer \nthan modes of natural variability (i.e., decades) are essential for \nrevealing and attributing ecological responses to climate change (e.g., \nSection\u00a03.4; Barton et\u00a0al., 2015b; Brun et\u00a0al., 2019).Also, paleorecords \nprovide insights into the influence of multiple drivers on marine \nbiota (Cross-Chapter Box\u00a0 PALEO in Chapter\u00a0 1; Reddin et\u00a0 al., 2020).Specifically, associations between vulnerabilities and traits of marine \nectotherms in laboratory experiments correspond with organismal \nresponses to ancient hyperthermal events (medium confidence) \n(Reddin et\u00a0 al., 2020).This corroboration suggests that responses to \nmultiple drivers inferred from the fossil record can help provide insights \ninto the future status of functional groups, and hence food webs, under \nrapid climate change.Multi-species and integrated end-to-end ecosystem models are \npowerful tools to explore and project outcomes to the often-interacting \ncumulative effects of climate change and other anthropogenic drivers \n(Section\u00a03.1; Kaplan and Marshall, 2016; Koenigstein et\u00a0al., 2016; Peck \nand Pinnegar, 2018; Tittensor et\u00a0 al., 2018; Gissi et\u00a0 al., 2021).These \nmodels can integrate some aspects of the knowledge accrued from \nmanipulation experiments, paleo- and contemporary observations, help \ntest the relative importance of specific drivers and driver combinations, \nand identify synergistic or antagonistic responses (Koenigstein et\u00a0al., \n2016; Payne et\u00a0al., 2016; Skogen et\u00a0al., 2018; Tittensor et\u00a0al., 2018).As these models are associated with wide-ranging uncertainties \n(SM3.2.2; Payne et\u00a0 al., 2016; Trolle et\u00a0 al., 2019; Heneghan et\u00a0 al., \n2021), they cannot be expected to accurately project the trajectories \nof complex marine ecosystems under climate change; hence, they are \nmost useful for assessing overall trends and in particular for providing a plausible envelope of trajectories across a range of assumptions \n(Fulton et\u00a0al., 2018; Peck et\u00a0al., 2018; Tittensor et\u00a0al., 2018).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are some approaches used to assess ecological responses to multiple climate-induced drivers in the context of climate change and the oceans?\nAnswer: "}, {"role": "assistant", "content": "Several approaches are used to assess ecological responses to multiple climate-induced drivers. These include laboratory- and field-based experiments, field observations such as natural gradients and climate analogues, the study of paleo-analogues, and the development of mechanistic and empirical models. Experimental studies often focus on individual drivers, but recent manipulations have used large-volume mesocosms to explore ecological responses to both warming and acidification. Observations from time series longer than modes of natural variability are essential for revealing and attributing ecological responses to climate change. Paleorecords also provide insights into the influence of multiple drivers on marine biota. Multi-species and integrated end-to-end ecosystem models are powerful tools to explore and project outcomes to the often-interacting cumulative effects of climate change and other anthropogenic drivers. These models can integrate some aspects of the knowledge accrued from manipulation experiments, paleo- and contemporary observations, help test the relative importance of specific drivers and driver combinations, and identify synergistic or antagonistic responses."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 409\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nOn a global \nscale, ecosystem models project a \u22125.7\u00a0 \u00b1\u00a0 4.1% (very likely range) \nto \u221215.5\u00a0 \u00b1\u00a0 8.5% decline in marine animal biomass with warming \nunder SSP1-2.6 and SSP5-8.5, respectively, by 2080\u20132099 relative to \n1995\u20132014, albeit with significant regional variation in both trends \nand uncertainties (medium confidence) (Section\u00a0 3.4.3.4; Tittensor \net\u00a0 al., 2021).Biological interactions may exacerbate or buffer the \nprojected impacts.For instance, trophic amplification (strengthening \nof responses to climate-induced drivers at higher trophic levels) may \nresult from combined direct and indirect food-web-mediated effects \n(medium confidence) (Section\u00a03.4.3.4; Lotze et\u00a0al., 2019).Alternatively, \ncompensatory species interactions can dampen strong impacts on \nspecies from ocean acidification, resulting in weaker responses at \nfunctional-group or community level than at species level (medium \nconfidence) (Marshall et\u00a0al., 2017; Hoppe et\u00a0al., 2018b; Olsen et\u00a0al., \n2018; Gissi et\u00a0al., 2021).Globally, the projected reduction of biomass \ndue to climate-induced drivers is relatively unaffected by fishing \npressure, indicating additive responses of fisheries and climate change \n(low confidence) (Lotze et\u00a0al., 2019).Regionally, projected interactions \nof climate-induced drivers, fisheries and other regional non-climate \ndrivers can be both synergistic and antagonistic, varying across regions, \nfunctional groups and species, and can cause nonlinear dynamics with \ncounterintuitive outcomes, underlining the importance of adaptations \nand associated trade-offs (high confidence) (Sections\u00a03.5.3, 3.6.3.1.2, \n4.5, 4.6; Weijerman et\u00a0al., 2015; Fulton et\u00a0al., 2018; Hansen et\u00a0al., 2019; \nTrolle et\u00a0al., 2019; Zeng et\u00a0al., 2019; Holsman et\u00a0al., 2020; Pethybridge \net\u00a0al., 2020; Gissi et\u00a0al., 2021).Given the limitations of individual ecological models discussed above, \nmodel intercomparisons, such as the Fisheries and Marine Ecosystem \nModel Intercomparison Project (Fish-MIP; Tittensor et\u00a0al., 2018) show \npromise in increasing the robustness of projected ecological outcomes \n(Tittensor et\u00a0 al., 2018).Model ensembles include a greater number \nof relevant processes and functional groups than any single model \nand thus capture a wider range of plausible responses.Among the \nglobal Fish-MIP models, there is high (temperate and tropical areas) \nto medium agreement (coastal and polar regions) on the direction of \nchange, but medium (temperate and tropical regions) to low agreement \n(coastal and polar regions) on magnitude of change (Lotze et\u00a0al., 2019; \nHeneghan et\u00a0al., 2021).Although model outputs are validated relative \nto observations to assess model skills (Payne et\u00a0 al., 2016; Tittensor \net\u00a0 al., 2018), the Fish-MIP models under-represent some sources of \nuncertainty, as they often do not include parameter uncertainties and \ndo not usually include impacts of ocean acidification, oxygen loss \nor evolutionary responses because there remains high uncertainty \nregarding the influences of these processes across functional groups.Ensemble model investigations like Fish-MIP have also identified gaps \nin our mechanistic understanding of ecosystems and their responses \nto anthropogenic forcing, leading to model improvement and more \nrigorous benchmarking.These investigations could inspire future \ntargeted observational and experimental research to test the validity \nof model assumptions (Payne et\u00a0al., 2016; Lotze et\u00a0al., 2019; Heneghan \net\u00a0 al., 2021).The state of the art in such experimental research is \npresented in Box\u00a03.1.\n\npage_label: 446\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThe new CMIP6 ESM ensemble projects \na decline in global zooplankton biomass by \u22123.9\u00a0 \u00b1\u00a0 8.2% (very \nlikely range) and \u22129.0\u00a0 \u00b1\u00a0 8.9% in the period 2081\u20132100 relative to \n1995\u20132014 under SSP1-2.6 and SSP5-8.5, respectively (Figure\u00a03.21d; \nKwiatkowski et\u00a0 al., 2020), thus reinforcing the SROCC assessment \nalbeit with greater inter-model uncertainties.Using an ensemble of global-scale marine ecosystem and fisheries \nmodels (Fish-MIP) (Tittensor et\u00a0 al., 2018) with the CMIP5 ESM \nensemble, SROCC concludes that projected ocean warming and \ndecreased phytoplankton production and biomass will reduce global \nmarine animal biomass during the 21st\u00a0century (medium confidence).The simulated declines (with very likely range) are \u22123.5\u00a0\u00b1\u00a04.8% and \n\u221214.0\u00a0 \u00b1\u00a0 14.6% under RCP2.6 and RCP8.5, respectively, by 2080\u2013\n2099 relative to 1995\u20132014 (SROCC Section\u00a0 5.2.3; Bindoff et\u00a0 al., \n2019a; Lotze et\u00a0al., 2019)6.Updated Fish-MIP simulations with CMIP6 \n(Figure\u00a03.21g,h,i) confirm the projected decline in total marine animal \nbiomass in the 21st\u00a0century (Tittensor et\u00a0al., 2021).The simulated Observed ecological regime shifts\nand their drivers in the oceans\n960 1970 1980 1990 2000 2010Regime 2Current state Critical threshold\nRegime 1\n2,5005,0007,50010,000Shift in magnitude and extent of abrupt community shifts\nin the global ocean(a)\n0Shock\n(b)\nFigure\u00a03.19 | \u00a0Observed ecological regime shifts and their drivers in the oceans.(a) A conceptual representation of ecosystem resilience and regime shifts.Shift \nfrom Regime 1 to Regime 2 can be triggered by either a large shock (i.e., an abrupt \nenvironmental transition) or gradual internal or external change that erodes the dominant \nbalancing feedbacks, reducing ecosystem resilience (indicated by the shallower dotted line, \nrelative to the deeper \u2018valley\u2019 reflecting higher resilience).(Based on Biggs et\u00a0al., 2018).(b) The sum of the magnitude and extent of the abrupt community shifts that has been \nestimated at each geographic cell in the global ocean during 1960\u20132014, calculated as \nthe ratio of the amplitude of the change in a particular\u00a0year to the average magnitude \nof the change over the entire time series (thus, is dimensionless).(Based on Beaugrand \net\u00a0al., 2019).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the projected decline in marine animal biomass with warming by 2080-2099 relative to 1995-2014, according to ecosystem models?\nAnswer: "}, {"role": "assistant", "content": "Ecosystem models project a decline in marine animal biomass with warming by 2080-2099 relative to 1995-2014 in the range of -5.7 \u00b1 4.1% to -15.5 \u00b1 8.5% under SSP1-2.6 and SSP5-8.5, respectively. However, there is significant regional variation in both trends and uncertainties."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 440\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThe ensemble projections of global changes in phytoplankton phenology include, \nunder SSP1-2.6 and SSP5-8.5, respectively, a total of five Coupled Model Intercomparison Project 6 Earth system models containing coupled ocean biogeochemical models that \ncover a wide range of complexity (Kwiatkowski et\u00a0al., 2019).(The phenology calculations are based on Racault et\u00a0al., 2017, using updated data.)\n\npage_label: 437\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n437Oceans and Coastal Ecosystems and Their Services Chapter 3\nas seen in breeding of surface-feeding and deeper-diving seabirds \n(Descamps et\u00a0al., 2019).These differential responses could determine \n\u2018winners\u2019 and \u2018losers\u2019 under future climate change (Lind\u00e9n, 2018).3.4.3.2.2 Projected changes\nThe CMIP6 ESM ensembles project that, by 2100, 18.8\u00a0 \u00b1\u00a0 19.0% \n(mean\u00a0 \u00b1\u00a0 very likely range) and 38.9\u00a0 \u00b1\u00a0 9.4% of the ocean surface \nwill\u00a0very likely undergo a change of 20 d or more (advance or delay) \nin the start of the phytoplankton growth period under SSP1-2.6 and \nSSP5-8.5, respectively (Figure\u00a0 3.17a,b) (low confidence\u00a0 due to the \ndependence with the projected changes in phytoplankton biomass, \nthe trends of which are reported with low confidence) (Section\u00a03.4.3.4; \nSROCC Section\u00a0 5.2.3; Bindoff et\u00a0 al., 2019a).Phytoplankton growth \nis projected to begin later in the Northern Hemisphere subtropics, \nand earlier at high latitudes in some regions around the Antarctic \nPeninsula, and over large areas in the Northern Hemisphere (low to \nmedium confidence as there are improved constraints from historical \nvariability in this region and consistency with CMIP5-based-studies \nresults) (Henson et\u00a0 al., 2018b; Asch et\u00a0 al., 2019).There is\u00a0 high \nagreement in model projections that the start of the phytoplankton Table\u00a03.18 | \u00a0Summary of previous IPCC assessments of phenological shifts and trophic mismatches\nObservations Projections\nAR5 WGII (Hoegh-Guldberg et\u00a0al., 2014; Larsen et\u00a0al., 2014)\n\u2018Changes to sea temperature have altered the phenology, or timing of key life-history events such as plankton blooms, and migratory patterns, \nand spawning in fish and invertebrates, over recent decades (medium confidence).There is medium to high agreement that these changes pose \nsignificant uncertainties and risks to fisheries, aquaculture and other coastal activities.\u2019\nThe highly productive high-latitude spring bloom systems in the northeast Atlantic are responding to warming (medium evidence, high agreement), \nwith the greatest changes being observed since the late 1970s in the phenology, distribution and abundance of plankton assemblages, and the \nreorganisation of fish assemblages, with a range of consequences for fisheries (high confidence).\u2018Observed changes in the phenology of plankton groups in the North Sea over the past 50\u00a0years are driven by climate forcing, in particular regional \nwarming (high confidence).\u2019\n\u2018On average, spring events in the ocean have advanced by 4.4\u00a0\u00b1\u00a00.7\u00a0days per decade (mean\u00a0\u00b1\u00a0SE).\u2019\n\u2018Shifts in the timing and magnitude of seasonal biomass production could disrupt matched phenologies in the food webs, leading to decreased \nsurvival of dependent species (medium confidence).If the timing of primary and secondary production is no longer matched to the timing of \nspawning or egg release, survival could be impacted, with cascading implications to higher trophic levels.This impact would be exacerbated if shifts \nin timing occur rapidly (medium confidence).\u2019\n\u2018There is medium to high confidence that climate-induced disruptions in the synchrony between timing of spawning and hatching of some fish and \nshellfish and the seasonal increases in prey availability can result in increased larval or juvenile mortality or changes in the condition factor of fish \nand shellfish species in the Arctic marine ecosystems.\u2019Projections of phenological shifts and \ntrophic mismatches were not assessed \nin this report.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the projected change in phytoplankton phenology by 2100 under Shared Socioeconomic Pathway (SSP)1-2.6 and SSP5-8.5?\nAnswer: "}, {"role": "assistant", "content": "The projected change in phytoplankton phenology by 2100 under Shared Socioeconomic Pathway (SSP)1-2.6 and SSP5-8.5 is that 18.8 \u00b1 19.0% and 38.9 \u00b1 9.4% of the ocean surface will very likely undergo a change of 20 days or more (either an advance or delay) in the start of the phytoplankton growth period, respectively. Phytoplankton growth is projected to begin later in the Northern Hemisphere subtropics, and earlier at high latitudes in some regions around the Antarctic Peninsula, and over large areas in the Northern Hemisphere."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 440\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThe ensemble projections of global changes in phytoplankton phenology include, \nunder SSP1-2.6 and SSP5-8.5, respectively, a total of five Coupled Model Intercomparison Project 6 Earth system models containing coupled ocean biogeochemical models that \ncover a wide range of complexity (Kwiatkowski et\u00a0al., 2019).(The phenology calculations are based on Racault et\u00a0al., 2017, using updated data.)\n\npage_label: 437\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n437Oceans and Coastal Ecosystems and Their Services Chapter 3\nas seen in breeding of surface-feeding and deeper-diving seabirds \n(Descamps et\u00a0al., 2019).These differential responses could determine \n\u2018winners\u2019 and \u2018losers\u2019 under future climate change (Lind\u00e9n, 2018).3.4.3.2.2 Projected changes\nThe CMIP6 ESM ensembles project that, by 2100, 18.8\u00a0 \u00b1\u00a0 19.0% \n(mean\u00a0 \u00b1\u00a0 very likely range) and 38.9\u00a0 \u00b1\u00a0 9.4% of the ocean surface \nwill\u00a0very likely undergo a change of 20 d or more (advance or delay) \nin the start of the phytoplankton growth period under SSP1-2.6 and \nSSP5-8.5, respectively (Figure\u00a0 3.17a,b) (low confidence\u00a0 due to the \ndependence with the projected changes in phytoplankton biomass, \nthe trends of which are reported with low confidence) (Section\u00a03.4.3.4; \nSROCC Section\u00a0 5.2.3; Bindoff et\u00a0 al., 2019a).Phytoplankton growth \nis projected to begin later in the Northern Hemisphere subtropics, \nand earlier at high latitudes in some regions around the Antarctic \nPeninsula, and over large areas in the Northern Hemisphere (low to \nmedium confidence as there are improved constraints from historical \nvariability in this region and consistency with CMIP5-based-studies \nresults) (Henson et\u00a0 al., 2018b; Asch et\u00a0 al., 2019).There is\u00a0 high \nagreement in model projections that the start of the phytoplankton Table\u00a03.18 | \u00a0Summary of previous IPCC assessments of phenological shifts and trophic mismatches\nObservations Projections\nAR5 WGII (Hoegh-Guldberg et\u00a0al., 2014; Larsen et\u00a0al., 2014)\n\u2018Changes to sea temperature have altered the phenology, or timing of key life-history events such as plankton blooms, and migratory patterns, \nand spawning in fish and invertebrates, over recent decades (medium confidence).There is medium to high agreement that these changes pose \nsignificant uncertainties and risks to fisheries, aquaculture and other coastal activities.\u2019\nThe highly productive high-latitude spring bloom systems in the northeast Atlantic are responding to warming (medium evidence, high agreement), \nwith the greatest changes being observed since the late 1970s in the phenology, distribution and abundance of plankton assemblages, and the \nreorganisation of fish assemblages, with a range of consequences for fisheries (high confidence).\u2018Observed changes in the phenology of plankton groups in the North Sea over the past 50\u00a0years are driven by climate forcing, in particular regional \nwarming (high confidence).\u2019\n\u2018On average, spring events in the ocean have advanced by 4.4\u00a0\u00b1\u00a00.7\u00a0days per decade (mean\u00a0\u00b1\u00a0SE).\u2019\n\u2018Shifts in the timing and magnitude of seasonal biomass production could disrupt matched phenologies in the food webs, leading to decreased \nsurvival of dependent species (medium confidence).If the timing of primary and secondary production is no longer matched to the timing of \nspawning or egg release, survival could be impacted, with cascading implications to higher trophic levels.This impact would be exacerbated if shifts \nin timing occur rapidly (medium confidence).\u2019\n\u2018There is medium to high confidence that climate-induced disruptions in the synchrony between timing of spawning and hatching of some fish and \nshellfish and the seasonal increases in prey availability can result in increased larval or juvenile mortality or changes in the condition factor of fish \nand shellfish species in the Arctic marine ecosystems.\u2019Projections of phenological shifts and \ntrophic mismatches were not assessed \nin this report.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the two Shared Socioeconomic Pathways (SSPs) under which the ensemble projections of global changes in phytoplankton phenology were conducted?\nAnswer: "}, {"role": "assistant", "content": "The ensemble projections of global changes in phytoplankton phenology were conducted under Shared Socioeconomic Pathways SSP1-2.6 and SSP5-8.5."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 532\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n532Chapter 3 Oceans and Coastal Ecosystems and Their Services\nOrr, J.C., et\u00a0al., 2005: Anthropogenic ocean acidification over the twenty-first \ncentury and its impact on calcifying organisms.Nature, 437(7059), 681\u2013\n686, doi:10.1038/nature04095.Orr, J.C., et\u00a0al., 2017: Biogeochemical protocols and diagnostics for the CMIP6 \nOcean Model Intercomparison Project (OMIP).Geosci.Model Dev., 10(6), \n2169\u20132199, doi:10.5194/gmd-10-2169-2017.Ortega, A., et\u00a0 al., 2019: Important contribution of macroalgae to oceanic \ncarbon sequestration.Nat.Geosci., 12(9), 748\u2013754, doi:10.1038/s41561-\n019-0421-8.Ortiz, J.-C., et\u00a0 al., 2018: Impaired recovery of the Great Barrier Reef under \ncumulative stress.Sci.Adv., 4(7), eaar6127, doi:10.1126/sciadv.aar6127.Ort\u00edz Li\u00f1\u00e1n, M. E. and V. V\u00e1zquez Sol\u00eds, 2021: The tourism inventory: a tool \nfor territorial management of tourism in natural attractions in the state of \nSan Luis Potosi, Mexico.Investig.Tur\u00edsticas, 21, 305\u2013327, doi:10.14198/\nINTURI2021.21.14.Oschlies, A., P .Brandt, L. Stramma and S. Schmidtko, 2018: Drivers and \nmechanisms of ocean deoxygenation.Nat.Geosci., 11(7), 467\u2013473, \ndoi:10.1038/s41561-018-0152-2.Osman, E.O., et\u00a0al., 2018: Thermal refugia against coral bleaching throughout \nthe northern Red Sea.Glob.Change Biol., 24(2), e474\u2013e484, doi:10.1111/\ngcb.13895.\u00d6sterblom, H., C.C.C.Wabnitz and D. Tladi, 2020: Towards Ocean Equity.World \nResources Institute, Washington, DC, Accessed 28th December 2021, https://\nwww.oceanpanel.org/blue-papers/towards-ocean-equity.Ostle, C., et\u00a0al., 2019: The rise in ocean plastics evidenced from a 60-year time \nseries.Nat.Commun., 10(1), 1622, doi:10.1038/s41467-019-09506-1.Ostrowski, A., R.M.Connolly and M. Sievers, 2021: Evaluating multiple stressor \nresearch in coastal wetlands: a systematic review.Mar.Environ.Res., 164, \n105239, doi:10.1016/j.marenvres.2020.105239.Otero, J., et\u00a0al., 2014: Basin-scale phenology and effects of climate variability on \nglobal timing of initial seaward migration of Atlantic salmon (Salmo salar).Glob.Change Biol., 20(1), 61\u201375, doi:10.1111/gcb.12363.Ottosen, K.M., P .Steingrund, E. Magnussen and M.R.Payne, 2018: Distribution \nand timing of spawning Faroe Plateau cod in relation to warming spring \ntemperatures.Fish.Res., 198, 14\u201323, doi:10.1016/j.fishres.2017.10.022.Ouyang, X. and S.Y .Lee, 2020: Improved estimates on global carbon stock and \ncarbon pools in tidal wetlands.Nat.Commun., 11(1), 317, doi:10.1038/\ns41467-019-14120-2.Ouyang, X., S.Y .Lee, R.M.Connolly and M.J. Kainz, 2018: Spatially-explicit \nvaluation of coastal wetlands for cyclone mitigation in Australia and China.Sci.Rep., 8(1), 3035, doi:10.1038/s41598-018-21217-z.Owen, G., 2020: What makes climate change adaptation effective?A systematic \nreview of the literature.Glob.Environ.\n\npage_label: 506\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nScience, \n371(6529), aba4658, doi:10.1126/science.aba4658.Duarte, C.M., et\u00a0 al., 2013: Is ocean acidification an open-ocean syndrome?Understanding anthropogenic impacts on seawater pH.Estuaries Coasts, \n36(2), 221\u2013236, doi:10.1007/s12237-013-9594-3.Dubik, B.A., et\u00a0 al., 2019: Governing fisheries in the face of change: social \nresponses to long-term geographic shifts in a U.S. fishery.Mar.Policy, 99, \n243\u2013251, doi:10.1016/j.marpol.2018.10.032.Ducrotoy, J.P ., et\u00a0 al., 2019: Chapter\u00a0 33\u2014temperate estuaries: their ecology \nunder future environmental changes.In: Coasts and Estuaries [Wolanski, \nE., J.W.Day, M. Elliott and R.Ramachandran(eds.)].Elsevier, Amsterdam, \nNetherlands; Oxford, UK; Cambridge, USA, pp.577\u2013594.ISBN 978-\n0128140031.Dueri, S., L. Bopp and O. Maury, 2014: Projecting the impacts of climate change \non skipjack tuna abundance and spatial distribution.Glob.Change Biol., \n20(3), 742\u2013753, doi:10.1111/gcb.12460.Duffy-Anderson, J.T., et\u00a0 al., 2019: Responses of the Northern Bering Sea \nand Southeastern Bering Sea pelagic ecosystems following record-\nbreaking low winter sea ice.Geophys.Res.Lett., 46(16), 9833\u20139842, \ndoi:10.1029/2019GL083396.Dufour, F ., H. Arrizabalaga, X. Irigoien and J. Santiago, 2010: Climate impacts \non albacore and bluefin tunas migrations phenology and spatial distribution.Prog.Oceanogr., 86(1\u20132), 283\u2013290, doi:10.1016/j.pocean.2010.04.007.Duke, N.C., L.B.Hutley, J.R. Mackenzie and D. Burrows, 2021: Processes and \nfactors driving change in mangrove forests: an evaluation based on the mass \ndieback event in Australia\u2019s Gulf of Carpentaria.In: Ecosystem Collapse and \nClimate Change [Canadell, J.G.and R.B.Jackson(eds.)].Springer International \nPublishing, Cham, pp.221\u2013264.ISBN 978-3030713300.Dulvy, N.K., et\u00a0al.,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the paper mentioned in the context that discusses the impact of anthropogenic ocean acidification on calcifying organisms?\nAnswer: "}, {"role": "assistant", "content": "The title of the paper that discusses the impact of anthropogenic ocean acidification on calcifying organisms is \"Anthropogenic ocean acidification over the twenty-first century and its impact on calcifying organisms.\""}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 86(1\u20132), 283\u2013290, doi:10.1016/j.pocean.2010.04.007.Duke, N.C., L.B.Hutley, J.R. Mackenzie and D. Burrows, 2021: Processes and \nfactors driving change in mangrove forests: an evaluation based on the mass \ndieback event in Australia\u2019s Gulf of Carpentaria.In: Ecosystem Collapse and \nClimate Change [Canadell, J.G.and R.B.Jackson(eds.)].Springer International \nPublishing, Cham, pp.221\u2013264.ISBN 978-3030713300.Dulvy, N.K., et\u00a0al., 2008: Climate change and deepening of the North Sea fish \nassemblage: a biotic indicator of warming seas.J. Appl.Ecol., 45(4), 1029\u2013\n1039, doi:10.1111/j.1365-2664.2008.01488.x.Dundas, S.J., et\u00a0 al., 2020: Integrating oceans into climate policy: any green \nnew deal needs a splash of blue.Conserv.Lett., 13(5), e12716, doi:10.1111/\nconl.12716.Dunn, D.C., et\u00a0al., 2018: A strategy for the conservation of biodiversity on mid-\nocean ridges from deep-sea mining.Sci.Adv., 4(7), eaar4313, doi:10.1126/\nsciadv.aar4313.\nQuery: What is the title of the paper mentioned in the context that discusses the impact of anthropogenic ocean acidification on calcifying organisms?\nOriginal Answer: The title of the paper that discusses the impact of anthropogenic ocean acidification on calcifying organisms is \"Anthropogenic ocean acidification over the twenty-first century and its impact on calcifying organisms.\"\nNew Answer: "}, {"role": "assistant", "content": "The title of the paper that discusses the impact of anthropogenic ocean acidification on calcifying organisms is \"Anthropogenic ocean acidification over the twenty-first century and its impact on calcifying organisms.\""}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 532\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nChange, 62, 102071, doi:10.1016/j.gloenvcha.2020.102071.Padilla-Gami\u00f1o, J.L., J.D.Gait\u00e1n-Espitia, M.W.Kelly and G.E.Hofmann, 2016: \nPhysiological plasticity and local adaptation to elevated pCO 2 in calcareous \nalgae: an ontogenetic and geographic approach.Evol.Appl., 9(9), 1043\u2013\n1053, doi:10.1111/eva.12411.Paerl, H.W., et\u00a0 al., 2016: Mitigating cyanobacterial harmful algal blooms \nin aquatic ecosystems impacted by climate change and anthropogenic \nnutrients.Harmful Algae, 54, 213\u2013222, doi:10.1016/j.hal.2015.09.009.Paerl, H.W., T.G.Otten and R. Kudela, 2018: Mitigating the expansion of harmful \nalgal blooms across the freshwater-to-marine continuum.Environ.Sci.Technol., 52(10), 5519\u20135529, doi:10.1021/acs.est.7b05950.Pal, J.S.and E.A.B.Eltahir, 2016: Future temperature in southwest Asia projected \nto exceed a threshold for human adaptability.Nat.Clim.Change, 6(2), 197\u2013\n200, doi:10.1038/nclimate2833.Paldor, A. and H.A.Michael, 2021: Storm surges cause simultaneous salinization \nand freshening of coastal aquifers, exacerbated by climate change.Water \nResour.Res., 57(5), e2020WR02913, doi:10.1029/2020WR029213.Palma, D., et\u00a0 al., 2019: Cruising the marginal ice zone: climate change and \nArctic tourism.Polar Geogr., 42(4), 215\u2013235, doi:10.1080/108893\n7X.2019.1648585.Palomares, M.L.D., et\u00a0 al., 2020: Fishery biomass trends of exploited fish \npopulations in marine ecoregions, climatic zones and ocean basins.Estuar.Coast.Shelf Sci., 243, 106896, doi:10.1016/j.ecss.2020.106896.Palter, J.B., T.L.Fr\u00f6licher, D. Paynter and J.G.John, 2018: Climate, ocean circulation, \nand sea level changes under stabilization and overshoot pathways to 1.5 K \nwarming.Earth Syst.Dynam., 9(2), 817\u2013828, doi:10.5194/esd-9-817-2018.Palumbi, S.R., D.J.Barshis, N. Traylor-Knowles and R.A. Bay, 2014: Mechanisms \nof reef coral resistance to future climate change.Science, 344(6186), 895\u2013\n898, doi:10.1126/science.1251336.Palutikof, J.P ., R.B.Street and E.P .Gardiner, 2019: Decision support platforms \nfor climate change adaptation: an overview and introduction.Clim.Change, \n153(4), 459\u2013476, doi:10.1007/s10584-019-02445-2.Panassa, E., C. V\u00f6lker, D. Wolf-Gladrow and J. Hauck, 2018: Drivers of \ninterannual variability of summer mixed layer depth in the Southern Ocean \nbetween 2002 and 2011.J. Geophys.Res.Oceans, 123(8), 5077\u20135090, \ndoi:10.1029/2018JC013901.Pandolfi, J.M., S.R.Connolly, D.J.Marshall and A.L.Cohen, 2011: Projecting \ncoral reef futures under global warming and ocean acidification.Science, \n333(6041), 418\u2013422, doi:10.1126/science.1204794.Pandolfi, J.M.and W. Kiessling, 2014: Gaining insights from past reefs to inform \nunderstanding of coral reef response to global climate change.Curr.Opin.Environ.\n\npage_label: 524\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nInfect., 147, e243, \ndoi:10.1017/S0950268819001316.Lohbeck, K.T., U. Riebesell and T.B.H.Reusch, 2012: Adaptive evolution of a key \nphytoplankton species to ocean acidification.Nat.Geosci., 5(5), 346\u2013351, \ndoi:10.1038/ngeo1441.Lomas, M.W., et\u00a0 al., 2010: Increased ocean carbon export in the Sargasso \nSea linked to climate variability is countered by its enhanced mesopelagic \nattenuation.Biogeosciences, 7(1), 57\u201370, doi:10.5194/bg-7-57-2010.Long, W.C., P .Pruisner, K.M.Swiney and R.J. Foy, 2019: Effects of ocean \nacidification on the respiration and feeding of juvenile red and blue king \ncrabs (Paralithodes camtschaticus and P .platypus).ICES J. Mar.Sci., 76(5), \n1335\u20131343, doi:10.1093/icesjms/fsz090.Lonhart, S.I., et\u00a0al., 2019: Shifts in the distribution and abundance of coastal \nmarine species along the eastern Pacific Ocean during marine heatwaves \nfrom 2013 to 2018.Mar.Biodivers.Rec., 12(1), 13, doi:10.1186/s41200-019-\n0171-8.Lopes, J.F ., C.L.Lopes and J.M.Dias, 2019: Climate change impact in the Ria \nde Aveiro lagoon ecosystem: a case study.J. Mar.Sci.Eng., 7(10), 352, \ndoi:10.3390/jmse7100352.Loseto, L.L., et\u00a0al., 2018: Beluga whales (Delphinapterus leucas), environmental \nchange and marine protected areas in the Western Canadian Arctic.Estuar.Coast.Shelf Sci., 212, 128\u2013137, doi:10.1016/j.ecss.2018.05.026.Lotze, H.K., et\u00a0al., 2019: Global ensemble projections reveal trophic amplification \nof ocean biomass declines with climate change.Proc.Natl.Acad.Sci.U.S.A., \n116(26), 12907\u201312912, doi:10.1073/pnas.1900194116.Louren\u00e7o, C.R., et\u00a0al., 2016: Upwelling areas as climate change refugia for the \ndistribution and genetic diversity of a marine macroalga.J.Biogeogr., 43(8), \n1595\u20131607,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title and DOI of the article discussing the physiological plasticity and local adaptation to elevated pCO2 in calcareous algae?\nAnswer: "}, {"role": "assistant", "content": "The title of the article is \"Physiological plasticity and local adaptation to elevated pCO2 in calcareous algae: an ontogenetic and geographic approach\" and its DOI is 10.1111/eva.12411."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: Sci., 212, 128\u2013137, doi:10.1016/j.ecss.2018.05.026.Lotze, H.K., et\u00a0al., 2019: Global ensemble projections reveal trophic amplification \nof ocean biomass declines with climate change.Proc.Natl.Acad.Sci.U.S.A., \n116(26), 12907\u201312912, doi:10.1073/pnas.1900194116.Louren\u00e7o, C.R., et\u00a0al., 2016: Upwelling areas as climate change refugia for the \ndistribution and genetic diversity of a marine macroalga.J.Biogeogr., 43(8), \n1595\u20131607, doi:10.1111/jbi.12744.Lovelock, C.E., et\u00a0al., 2017a: Assessing the risk of carbon dioxide emissions from \nblue carbon ecosystems.Front.Ecol.Environ., 15(5), 257\u2013265, doi:10.1002/\nfee.1491.Lovelock, C.E.and C.M.Duarte, 2019: Dimensions of Blue Carbon and emerging \nperspectives.Biol.Lett., 15(3), 20180781, doi:10.1098/rsbl.2018.0781.Lovelock, C.E., et\u00a0al., 2017b: Mangrove dieback during fluctuating sea levels.Sci.Rep., 7(1), 1680, doi:10.1038/s41598-017-01927-6.Lovelock, C.E.and R. Reef, 2020: Variable impacts of climate change on blue \ncarbon.One Earth, 3(2), 195\u2013211, doi:10.1016/j.oneear.2020.07.010.Lowerre-Barbieri, S.K., I.A. Catal\u00e1n, A. Frug\u00e5rd Opdal and C. J\u00f8rgensen, 2019: \nPreparing for the future: integrating spatial ecology into ecosystem-based \nmanagement.ICES J. Mar.Sci., 76(2), 467\u2013476, doi:10.1093/icesjms/fsy209.Lubchenco, J., E.B.Cerny-Chipman, J.N.\nQuery: What is the title and DOI of the article discussing the physiological plasticity and local adaptation to elevated pCO2 in calcareous algae?\nOriginal Answer: The title of the article is \"Physiological plasticity and local adaptation to elevated pCO2 in calcareous algae: an ontogenetic and geographic approach\" and its DOI is 10.1111/eva.12411.\nNew Answer: "}, {"role": "assistant", "content": "The title of the article is \"Physiological plasticity and local adaptation to elevated pCO2 in calcareous algae: an ontogenetic and geographic approach\" and its DOI is 10.1111/eva.12411."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 460\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n460Chapter 3 Oceans and Coastal Ecosystems and Their Services\nstrains (Section\u00a05.9.4; Barton et\u00a0al., 2015a).Laboratory studies show \nthat ocean acidification decreases the fitness, growth or survival of \nmany economically and culturally important larval or juvenile shelled \nmollusks (high confidence) (Cao et\u00a0 al., 2018; Onitsuka et\u00a0 al., 2018; \nStevens and Gobler, 2018; Griffith et\u00a0al., 2019a; Mellado et\u00a0al., 2019) \nand of several valuable wild-harvest crab species (Barton et\u00a0al., 2015a; \nPunt et\u00a0al., 2015; Miller et\u00a0al., 2016; Swiney et\u00a0al., 2017; Gravinese \net\u00a0al., 2018; Tomasetti et\u00a0al., 2018; Long et\u00a0al., 2019; Trigg et\u00a0al., 2019).Ocean acidification alters larval settlement and metamorphosis of fish \nin laboratory studies (high confidence) (Cattano et\u00a0al., 2018; Espinel-\nVelasco et\u00a0al., 2018), suggesting possible changes in fish survival and \nthus fishery characteristics.Deoxygenation can decrease size and \nabundance of marine species and suppress trophic interactions (Levin, \n2003), decrease the diversity within marine ecosystems (Sperling et\u00a0al., \n2016) while temporarily increasing catchability and increasing the risk \nof overfishing (Breitburg et\u00a0 al., 2018) and decrease the ecosystem \nservices provided by specific fisheries (Orio et\u00a0al., 2021).The chronic \neffects of deoxygenation on wild fisheries are complex and highly \ninteractive with co-occurring drivers and overall ecosystem responses \n(medium evidence, high agreement) (Townhill et\u00a0al., 2017; Rose et\u00a0al., \n2019).Detecting and attributing marine ecosystem responses to \nocean acidification and deoxygenation outside of laboratory studies \nremains challenging because of the strong influence of co-occurring \nenvironmental changes on natural systems (Section\u00a03.3.5; Rose et\u00a0al., \n2019; Doo et\u00a0al., 2020).Ocean and coastal organisms will continue moving poleward under \nRCP8.5 (high confidence) (Section\u00a03.4.3.1.3; Figure\u00a03.18), and this is \nexpected to decrease fisheries harvests in low latitudes and alter species \ncomposition and abundance in higher latitudes (high confidence) \n(Table\u00a03.26; Figure\u00a03.23; Asch et\u00a0al., 2018; Morley et\u00a0al., 2018; Tai et\u00a0al., \n2019; Erauskin-Extramiana et\u00a0al., 2020; Shelton et\u00a0al., 2021).Species \nthat succeed in new ranges or conditions may offer opportunities to \ndiversify regional fisheries or aquaculture (Sections\u00a0 3.6.3.1.2, 5.8.4, \n5.9.4; Bindoff et\u00a0 al., 2019a), or they may outcompete indigenous \nspecies and act as invasive species (Sections\u00a03.4.2.10, 3.5.2).Temperature will continue to be a major driver of fisheries changes \nglobally, but other non-climate factors like organism physiology and \necosystem response (Section\u00a03.3) and fishing pressure (Chapter\u00a05), as \nwell as other climate-induced drivers like acidification, deoxygenation \nand sea ice loss (Section\u00a03.2), will play critical roles in future global \nand local fisheries changes (high confidence).Warming, acidification \nand business-as-usual fishing policy under RCP8.5 are projected \nto place around 60% of global fisheries at very high risk (medium \nconfidence) (Cheung et\u00a0 al., 2018).Model intercomparison showed \nthat ocean acidification and protection affect ecosystems more than \nfishing pressure, and ecological adaptation will significantly determine \nimpacts on fishery biomass, catch and value until approximately 2050 \n(medium confidence) (Olsen et\u00a0 al., 2018).Ecosystem responses to \nwarming water, fishing pressure, food-web changes, MHWs and sea \nice algal populations have been responsible for highly variable or \ncollapsing populations of Northern Hemisphere high-latitude forage \nfish species including sand lances (Ammodytes spp.\n\npage_label: 520\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nKoenigstein, S., et\u00a0al., 2016: Modelling climate change impacts on marine fish \npopulations: process-based integration of ocean warming, acidification \nand other environmental drivers.Fish Fish., 17(4), 972\u20131004, doi:10.1111/\nfaf.12155.Kok, S., et\u00a0al., 2021: The potential of nature-based flood defences to leverage \npublic investment in coastal adaptation: cases from the Netherlands, \nIndonesia and Georgia.Ecol.Econ., 179, 106828, doi:10.1016/j.ecolecon.2020.106828.Kompor, W., C. Ekkawatpanit and D. Kositgittiwong, 2018: Assessment of ocean \nwave energy resource potential in Thailand.Ocean Coast.Manag., 160, 64\u2013\n74, doi:10.1016/j.ocecoaman.2018.04.003.Konar, M. and H. Ding, 2020: A Sustainable Ocean Economy for 2050: \nApproximating Its Benefits and Costs.High Level Panel for a Sustainable \nOcean Economy, Washington, D.C., USA, Accessed 28th December 2021, \nhttps://oceanpanel.org/sites/default/files/2020-07/Ocean%20Panel_\nEconomic%20Analysis_FINAL.pdf.Kondrik, D., D. Pozdnyakov and L. Pettersson, 2017: Particulate inorganic carbon \nproduction within E. huxleyi blooms in subpolar and polar seas: a satellite \ntime series study (1998\u20132013).Int.J.Remote Sens., 38(22), 6179\u20136205, doi\n:10.1080/01431161.2017.1350304.Kong, C.E., S. Yoo and C.J.Jang, 2019: East China Sea ecosystem under multiple \nstressors: heterogeneous responses in the sea surface chlorophyll-a.Deep Sea \nRes.Part I Oceanogr.Res.Pap., 151, 103078, doi:10.1016/j.dsr.2019.103078.Kool, R., J. Lawrence, M. Drews and R. Bell, 2020: Preparing for sea-level \nrise through adaptive managed retreat of a New Zealand stormwater \nand wastewater network.Infrastructures, 5(11), 92, doi:10.3390/\ninfrastructures5110092.Kopp, R.E., et\u00a0al., 2019: Usable science for managing the risks of sea-level rise.Earth\u2019s Future, 7(12), 1235\u20131269, doi:10.1029/2018EF001145.Kopp, R.E., et\u00a0 al., 2016: Temperature-driven global sea-level variability in \nthe common\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context, what is the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population?\nAnswer: "}, {"role": "assistant", "content": "The provided context does not contain specific information about the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: R., J. Lawrence, M. Drews and R. Bell, 2020: Preparing for sea-level \nrise through adaptive managed retreat of a New Zealand stormwater \nand wastewater network.Infrastructures, 5(11), 92, doi:10.3390/\ninfrastructures5110092.Kopp, R.E., et\u00a0al., 2019: Usable science for managing the risks of sea-level rise.Earth\u2019s Future, 7(12), 1235\u20131269, doi:10.1029/2018EF001145.Kopp, R.E., et\u00a0 al., 2016: Temperature-driven global sea-level variability in \nthe common era.Proc.Natl.Acad.Sci.U.S.A., 113(11), E1434\u2013E1441, \ndoi:10.1073/pnas.1517056113.Kornder, N.A., B.M.Riegl and J. Figueiredo, 2018: Thresholds and drivers of \ncoral calcification responses to climate change.Glob.Change Biol., 24(11), \n5084\u20135095, doi:10.1111/gcb.14431.Koslow, J.A.et\u00a0 al., 2019: The evolving response of mesopelagic fishes to \ndeclining midwater oxygen concentrations in the southern and central \nCalifornia Current.ICES J. Mar.Sci., 76(3), 626\u2013638, doi:10.1093/icesjms/\nfsy154.Kotta, J., et\u00a0al., 2018: Predicting the cover and richness of intertidal macroalgae \nin remote areas: a case study in the Antarctic Peninsula.Ecol.Evol., 8(17), \n9086\u20139094, doi:10.1002/ece3.4463.\nQuery: Question: According to the provided context, what is the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population?\nOriginal Answer: The provided context does not contain specific information about the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population.\nNew Answer: "}, {"role": "assistant", "content": "The provided context does not contain specific information about the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 491\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n491Oceans and Coastal Ecosystems and Their Services Chapter 3\nshellfish harvesting (Turner et\u00a0 al., 2020a) and account for 11% of \nglobal artisanal fisheries participants (Harper et\u00a0al., 2020b), they are \noften not specifically counted in datasets and excluded from decision \nmaking and support programmes (Cross-Chapter\u00a0 Box\u00a0 GENDER in \nChapter\u00a0 18; Harper et\u00a0 al., 2020b; Michalena et\u00a0 al., 2020).Targeted \nefforts to incorporate knowledge diversity, and include artisanal \nfishers, women and Indigenous Peoples within international, regional \nand local policy planning, promote marine adaptation that supports \nachievement of gender equality (SDG5) and reduces inequalities \n(SDG10) (limited evidence, high agreement) (FAO, 2015).Integrated \nplanning, financing and implementation can help overcome these \nlimitations (Section\u00a0 3.6.3.3.2; Cross-Chapter\u00a0 Box\u00a0 FINANCE in \nChapter\u00a0 17), ensuring that marine adaptations do not compromise \noverall human equity or specific SDGs (\u00d6sterblom et\u00a0al., 2020; Nash \net\u00a0al., 2021), but are in fact fully synergistic with these goals (Bennett \net\u00a0al., 2021).3.6.4.3 Relevant Policy Frameworks for Ocean Adaptation\nThe intricacy, scope, time scales and uncertainties associated with \nclimate change challenge ocean governance, which already is \nextremely complex because it encompasses a variety of overlapping \nspatial scales, concerns and governance structures (see Figure\u00a0CB3.1 in \nSROCC Chapter\u00a01; Prakash et\u00a0al., 2019).Assessment of how established \nglobal agreements and regional, sectoral or scientific bodies address \nclimate adaptation and resilience, and how current practices can be \nimproved, is found in SM3.5.3.There is growing momentum to include the ocean in international \nclimate policy (robust evidence), paving the way for a more integrated approach to both mitigation and adaptation.Following adoption of \nthe Paris Agreement in 2015, the UN SDGs (Table\u00a0 3.31) came into \nforce in 2016, including SDG14 specifically dedicated to Life Below \nWater (Table\u00a03.31).In 2017, the first UN Ocean Conference was held \n(United Nations, 2017), the UNFCCC adopted the Ocean Pathway to \nincrease ocean-targeted multilateral climate action (COP23, 2017) \nand the UN Assembly declared 2021\u20132030 the Decade for Ocean \nScience for Sustainable Development (Visbeck, 2018; Lee et\u00a0al., 2020).Next, 14 world leaders formed the High-Level Panel for a Sustainable \nOcean Economy to produce the New Ocean Action Agenda, founded \non 100% sustainable management of national ocean spaces by 2025 \n(Ocean Panel, 2020).All of these initiatives position oceans centrally \nwithin the climate-policy and biodiversity-conservation landscapes \nand seek to develop a coherent effort and common frameworks to \nachieve marine sustainability (Visbeck, 2018; Lee et\u00a0 al., 2020), new \neconomic opportunities (Konar and Ding, 2020; Lee et\u00a0al., 2020), more \nequitable outcomes (\u00d6sterblom et\u00a0 al., 2020) and decisive climate \nmitigation and adaptation (Hoegh-Guldberg et\u00a0al., 2019a), to achieve \ntruly transformative change (Claudet et\u00a0al., 2020a).There is high confidence in the literature that multilateral environmental \nagreements need better alignment and integration to support \nachievement of ambitious international development, climate mitigation \nand adaptation goals (Swilling et\u00a0al., 202; Duarte et\u00a0al., 2020; Friedman \net\u00a0al., 2020; Conservation International and IUCN, 2021; P\u00f6rtner et\u00a0al., \n2021b; Sumaila et\u00a0al., 2021).The ocean targets of the CBD (e.g., the Post-\n2020 Global Biodiversity Framework), the SDGs (Agenda 2030) and the \nParis Agreement are already inclusive and synergistic (Duarte et\u00a0al., 2020).\n\npage_label: 489\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nOcean renewable-energy expansion faces other technological \nobstacles including lack of implementable or scalable energy-capture \ndevices, access to offshore sites, competing coastal uses, potential environmental impacts and lack of power-grid infrastructure at the \ncoast (Aderinto and Li, 2018; Neill et\u00a0al., 2018).3.6.4 Contribution to the Sustainable Development \nGoals and Other Relevant Policy Frameworks\nThe impacts of climate change on ocean and coastal ecosystems and \ntheir services threaten achievement of the UN SDGs by 2030 (high \nconfidence), particularly ocean targets (Table\u00a03.31; Nilsson et\u00a0al., 2016; \nPecl et\u00a0al., 2017; IPCC, 2018; Singh et\u00a0al., 2019a; Claudet et\u00a0al., 2020a).Nevertheless, local to international decision-making bodies have \nassigned the lowest priority to SDG14, Life Below Water (Nash et\u00a0al., \n2020).3.6.4.1 Climate Mitigation Effects on Ocean-Related SDGs\nSROCC underscored the need for ambitious mitigation to control \nclimate hazards in the ocean to achieve SDGs (medium evidence, high \nagreement) (Bindoff et\u00a0al., 2019a; Oppenheimer et\u00a0al., 2019).Delays in \nachieving ocean-dependent SDGs observed in SROCC and SR15 can be \naddressed with ambitious planned adaptation and mitigation action \n(high agreement) (Hoegh-Guldberg et\u00a0al., 2019b).Since the ocean can \ncontribute substantially to the attainment of mitigation targets aiming \nto limit warming to 1.5\u00b0C above pre-industrial levels (Hoegh-Guldberg \net\u00a0al., 2019b), and to adaptation solutions facilitating attainment of \nsocial and economic SDGs, climate policy is treating the ocean less as \na victim of climate change and more as a central participant in solving \nthe global climate challenge (Cooley et\u00a0 al., 2019; Hoegh-Guldberg \net\u00a0al., 2019a; Dundas et\u00a0al., 2020).Relationships between Climate Action (SDG13) targets and SDG14 \ntargets are mostly synergistic (Figure\u00a0 3.26; Fuso Nerini et\u00a0 al., 2019).Responding to climate-change impacts requires transformative \ngovernance (high confidence) (Chapters\u00a0 1, 18; Collins et\u00a0 al., 2019a; \nBrodie Rudolph et\u00a0al., 2020; Claudet et\u00a0al., 2020a), especially for extreme \nevents and higher-impact scenarios (e.g., higher emissions) (Fedele et\u00a0al., \n2019), and for achieving SDGs through one of the global ecosystems \ntransitions (Chapter\u00a018; Sachs et\u00a0al., 2019; Brodie Rudolph et\u00a0al., 2020).Opportunities to transform ocean governance exist in developing new \ninternational and local agreements, regulations and policies that reduce \nthe risks of relocating ocean and coastal activities (Section\u00a03.6.3.1.1) \nor in reinventing established practices (Section\u00a0 3.6.3.3.3).Policy \ntransformations improving ocean sustainability under SDG14 also help \naddress SDG13 (Brodie Rudolph et\u00a0al., 2020;\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are some of the global initiatives and frameworks that aim to integrate the ocean into climate policy and achieve marine sustainability?\nAnswer: "}, {"role": "assistant", "content": "Several global initiatives and frameworks aim to integrate the ocean into climate policy and achieve marine sustainability. These include the adoption of the Paris Agreement in 2015 and the United Nations Sustainable Development Goals (SDGs), which came into force in 2016. SDG14 is specifically dedicated to Life Below Water. In 2017, the first UN Ocean Conference was held, and the UNFCCC adopted the Ocean Pathway to increase ocean-targeted multilateral climate action. The same year, the UN Assembly declared 2021\u20132030 the Decade for Ocean Science for Sustainable Development. Additionally, 14 world leaders formed the High-Level Panel for a Sustainable Ocean Economy to produce the New Ocean Action Agenda, which is based on 100% sustainable management of national ocean spaces by 2025. These initiatives aim to position oceans centrally within the climate-policy and biodiversity-conservation landscapes and develop a coherent effort and common frameworks to achieve marine sustainability."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 2020a), especially for extreme \nevents and higher-impact scenarios (e.g., higher emissions) (Fedele et\u00a0al., \n2019), and for achieving SDGs through one of the global ecosystems \ntransitions (Chapter\u00a018; Sachs et\u00a0al., 2019; Brodie Rudolph et\u00a0al., 2020).Opportunities to transform ocean governance exist in developing new \ninternational and local agreements, regulations and policies that reduce \nthe risks of relocating ocean and coastal activities (Section\u00a03.6.3.1.1) \nor in reinventing established practices (Section\u00a0 3.6.3.3.3).Policy \ntransformations improving ocean sustainability under SDG14 also help \naddress SDG13 (Brodie Rudolph et\u00a0al., 2020; Dundas et\u00a0al., 2020; Claudet, \n2021; Sumaila et\u00a0al., 2021).Emergent situations, such as the COVID-19 \npandemic, may provide opportunities to implement transformative \n\u2018green recovery plans\u2019 that support achievement of the SDGs and NDCs \n(Cross-Chapter\u00a0Box\u00a0COVID in Chapter\u00a07).3.6.4.2 Contribution of Ocean Adaptation to SDGs\nMarine-focused adaptations show promise in helping achieve \nsocial SDGs, especially when they are designed to achieve multiple \nbenefits (medium confidence) (Figure\u00a0 3.26; Ntona and Morgera, \n2018; Claudet et\u00a0al., 2020a).Technology- and infrastructure-focused \nadaptations (Section\u00a0 3.6.2.2) can help relieve coastal communities\nQuery: What are some of the global initiatives and frameworks that aim to integrate the ocean into climate policy and achieve marine sustainability?\nOriginal Answer: Several global initiatives and frameworks aim to integrate the ocean into climate policy and achieve marine sustainability. These include the adoption of the Paris Agreement in 2015 and the United Nations Sustainable Development Goals (SDGs), which came into force in 2016. SDG14 is specifically dedicated to Life Below Water. In 2017, the first UN Ocean Conference was held, and the UNFCCC adopted the Ocean Pathway to increase ocean-targeted multilateral climate action. The same year, the UN Assembly declared 2021\u20132030 the Decade for Ocean Science for Sustainable Development. Additionally, 14 world leaders formed the High-Level Panel for a Sustainable Ocean Economy to produce the New Ocean Action Agenda, which is based on 100% sustainable management of national ocean spaces by 2025. These initiatives aim to position oceans centrally within the climate-policy and biodiversity-conservation landscapes and develop a coherent effort and common frameworks to achieve marine sustainability.\nNew Answer: "}, {"role": "assistant", "content": "There are numerous global initiatives and frameworks that aim to integrate the ocean into climate policy and achieve marine sustainability. These include the Paris Agreement, adopted in 2015, and the United Nations Sustainable Development Goals (SDGs), which were implemented in 2016, with SDG14 specifically focusing on Life Below Water. The first UN Ocean Conference took place in 2017, and the UNFCCC introduced the Ocean Pathway to enhance ocean-focused multilateral climate action. In the same year, the UN Assembly announced 2021\u20132030 as the Decade for Ocean Science for Sustainable Development. Furthermore, 14 global leaders established the High-Level Panel for a Sustainable Ocean Economy to create the New Ocean Action Agenda, which is centered on 100% sustainable management of national ocean spaces by 2025. These initiatives aim to place oceans at the heart of climate-policy and biodiversity-conservation efforts and to develop a unified approach and shared frameworks to achieve marine sustainability."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 491\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nHowever, specific policy instruments and sectors within them could be \nadditionally integrated, especially to address such cross-cutting impacts \nSynergies and trade-offs between Sustainable Development Goals (SDGs) Climate Action(13), Life Below \nWater (14), and social, economic and governance SDGs\nAgreement\nIndivisible Reinforcing Enabling Consistent ConstrainingSDG interactions\nHigh Medium Low High Medium LowSDG14: Life Below Water targets\n14.1.Reduce pollution\n14.2 Protection and restoration\n14.3 Reduce ocean acidification\n14.4 Sustainable fishing\n14.5 Conservation\n14.6 No overfishing subsidies\n14.7 Sustainable resources\n14.B Small-scale fisheries\n14.C Sea lawClimate\naction\n(SDG13)\nto\nSDG14SDG14 to Social SDGs SDG2\nSDG3SDG1\nSDG5\nSDG6SDG4\nSDG7SDG14 to Economic SDGs\nSDG9\nSDG10SDG8\nSDG12SDG 11\nSDG16\nSDG17SDG14 to\nGovernance SDGs\n14.A Knowledge\nFigure\u00a03.26 | \u00a0Synergies and trade-offs between SDG13 Climate Action, SDG14 Life Below Water and social, economic and governance SDGs.Achieving SDG13 \nprovides positive outcomes and supports the achievement of all SDG14 targets.In turn, meeting SDG14 drives mostly positive interactions with social, economic and governance \nSDGs.The interaction types, \u2018Indivisible\u2019 (inextricably linked to the achievement of another goal), \u2018Reinforcing\u2019 (aids the achievement of another goal), \u2018Enabling\u2019 (creates conditions \nthat further another goal), \u2018Consistent\u2019 (no significant positive or negative interactions) and \u2018Constraining\u2019 (limits options on another goal), follow Nilsson et\u00a0al.\u2019s (2016) scoring \nsystem based on the authors\u2019 assessment, and agreement denotes consistency across author ratings.(Full data are available in Table\u00a03.SM.7.)\n\npage_label: 490\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBlue-economy growth that includes sustainable \nshipping, tourism, renewable ocean energy and transboundary fisheries \nmanagement (Pinsky et\u00a0al., 2018) have the potential to contribute to \nEconomic Development (SDG8), affordable and clean energy (SDG7) as \nwell as global mitigation efforts (SDG13) (Hoegh-Guldberg et\u00a0al., 2019b; \nDuarte et\u00a0 al., 2020).Participatory approaches and co-management \nsystems (Section\u00a03.6.2.1) in many maritime sectors can contribute to \nSDG11 and SDG12 while helping align the blue economy and the SDGs \n(high agreement) (Lee et\u00a0al., 2020; Okafor-Yarwood et\u00a0al., 2020).Developing marine adaptation pathways that offer multiple benefits \nrequires transformational adaptation (high confidence) (Claudet \net\u00a0al., 2020a; Friedman et\u00a0al., 2020; Wilson et\u00a0al., 2020b; Nash et\u00a0al., \n2021) that avoids risky and maladaptive actions (Magnan and \nDuvat, 2018; Ojea et\u00a0 al., 2020).Ocean and coastal extreme events \nand other hazards disproportionately harm the most vulnerable \ncommunities in SIDS, tropical and Arctic regions, and Indigenous \nPeoples (Chapter\u00a08.2.1.2).Presently implemented adaptation activity, \nat the aggregate level, adversely affects multiple gender targets under \nSDG5 (high confidence) (Cross-Chapter\u00a0Box\u00a0GENDER in Chapter\u00a018).Although women make up over half of the global seafood production \nworkforce (fishing and processing sectors), provide more than half the \nartisanal landings in the Pacific region (Harper et\u00a0al., 2013), dominate \nsome seafood sectors such as seaweed (Howard and Pecl, 2019) and Table\u00a03.31 | \u00a0Sustainable Development Goals, grouped into broader categories as discussed in this sectiona\nCategory Goal\nSocietySDG1: No Poverty\nSDG2: Zero Hunger\nSDG3: Good Health and Well-Being\nSDG4: Quality Education\nSDG5: Gender Equality\nSDG6: Clean Water and Sanitation\nSDG7: Affordable and Clean Energy\nEconomySDG8: Decent Work and Economic Growth\nSDG9: Industry, Innovation and Infrastructure\nSDG10: Reduced Inequality\nSDG11: Sustainable Cities and Communities\nSDG12: Responsible Consumption and Production\nEnvironmentSDG13: Climate Action\nSDG14: Life Below Water\nSDG15: Life on Land\nGovernanceSDG16: Peace and Justice Strong Institutions\nSDG17: Partnerships to Achieve the Goals\n(a) See http://sdgs.un.org/goals\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the three types of interactions between SDG14 Life Below Water and social, economic, and governance SDGs, as identified in the report?\nAnswer: "}, {"role": "assistant", "content": "The three types of interactions between SDG14 Life Below Water and social, economic, and governance SDGs identified in the report are 'Indivisible', 'Reinforcing', and 'Enabling'. 'Indivisible' refers to being inextricably linked to the achievement of another goal. 'Reinforcing' aids the achievement of another goal, and 'Enabling' creates conditions that further another goal. There are also two other interaction types mentioned, 'Consistent' and 'Constraining', but they do not have significant positive or negative interactions."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 509\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n509Oceans and Coastal Ecosystems and Their Services Chapter 3\nFischer, D., et\u00a0 al., 2012: Interaction between hydrocarbon seepage, \nchemosynthetic communities, and bottom water redox at cold seeps of \nthe Makran accretionary prism: insights from habitat-specific pore water \nsampling and modeling.Biogeosciences, 9(6), 2013\u20132031, doi:10.5194/bg-\n9-2013-2012.Fischer, G., et\u00a0al., 2020: Long-term changes of particle flux in the canary basin \nbetween 1991 and 2009 and comparison to sediment trap records off \nMauritania.Front.Earth Sci., 8, 280, doi:10.3389/feart.2020.00280.Fischer, G., et\u00a0al., 2019: Changes in the dust-influenced biological carbon pump \nin the Canary current system: implications from a coastal and an offshore \nsediment trap record off Cape Blanc, Mauritania.Glob.Biogeochem.Cycles, \n33(8), 1100\u20131128, doi:10.1029/2019GB006194.Fitton, J.M., et\u00a0al., 2021: Challenges to climate change adaptation in coastal \nsmall towns: examples from Ghana, Uruguay, Finland, Denmark, and Alaska.Ocean Coast.Manag., 212, 105787, doi:10.1016/j.ocecoaman.2021.105787.Fitzer, S.C., V.R.Phoenix, M. Cusack and N.A.Kamenos, 2014: Ocean acidification \nimpacts mussel control on biomineralisation.Sci.Rep., 4, 6218, doi:10.1038/\nsrep06218.FitzGerald, D.M.and Z. Hughes, 2019: Marsh processes and their response to \nclimate change and sea-level rise.Annu.Rev.Earth Planet.Sci., 47(1), 481\u2013\n517, doi:10.1146/annurev-earth-082517-010255.Flanagan, P .H., O.P .Jensen, J.W.Morley and M.L.Pinsky, 2019: Response of \nmarine communities to local temperature changes.Ecography, 42(1), 214\u2013\n224, doi:10.1111/ecog.03961.Flannery, W., et\u00a0 al., 2016: Exploring the winners and losers of marine \nenvironmental governance/Marine spatial planning: Cui bono?/\u201cMore than \nfishy business\u201d: epistemology, integration and conflict in marine spatial \nplanning/Marine spatial planning: power and scaping/Surely not all planning \nis evil?/Marine spatial planning: a Canadian perspective/Maritime spatial \nplanning \u2013 \u201cad utilitatem omnium\u201d/Marine spatial planning: \u201cit is better \nto be on the train than being hit by it\u201d/Reflections from the perspective \nof recreational anglers and boats for hire/Maritime spatial planning and \nmarine renewable energy.Plan.Theory Pract., 17(1), 121\u2013151, doi:10.108\n0/14649357.2015.1131482.Flombaum, P ., W.-L. Wang, F .W.Primeau and A.C. Martiny, 2020: Global \npicophytoplankton niche partitioning predicts overall positive response to \nocean warming.Nat.Geosci., 13(2), 116\u2013120, doi:10.1038/s41561-019-\n0524-2.Flood, J.F .and L.B.Cahoon, 2011: Risks to coastal Wastewater collection \nsystems from sea-level rise and climate change.J.Coast.Res., 27(4), 652\u2013\n660, doi:10.2112/JCOASTRES-D-10-00129.1.Flood, S., N.A.Cradock-Henry, P .Blackett and P .Edwards, 2018: Adaptive \nand interactive climate futures: systematic review of \u2018serious games\u2019 for \nengagement and decision-making.Environ.Res.Lett., 13(6), 063005, \ndoi:10.1088/1748-9326/aac1c6.\n\npage_label: 535\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nChange Biol., 22(12), 3927\u20133936, \ndoi:10.1111/gcb.13423.Queir\u00f3s, A.M., et\u00a0 al., 2019: Connected macroalgal-sediment systems: blue \ncarbon and food webs in the deep coastal ocean.Ecol.Monogr., 89(3), \ne01366, doi:10.1002/ecm.1366.Queste, B.Y ., C. Vic, K.J.Heywood and S.A. Piontkovski, 2018: Physical controls \non oxygen distribution and denitrification potential in the north west Arabian \nSea.Geophys.Res.Lett., 45(9), 4143\u20134152, doi:10.1029/2017GL076666.Quevedo, J.M.D., Y .Uchiyama and R. Kohsaka, 2020: Perceptions of the \nseagrass ecosystems for the local communities of Eastern Samar, Philippines: \npreliminary results and prospects of blue carbon services.Ocean Coast.Manag., 191, 105181, doi:10.1016/j.ocecoaman.2020.105181.Rabalais, N.N.and M.M.Baustian, 2020: Historical shifts in benthic infaunal \ndiversity in the northern Gulf of Mexico since the appearance of seasonally \nsevere hypoxia.Diversity, 12(2), 49, doi:10.3390/d12020049.Rabalais, N.N., et\u00a0al., 2010: Dynamics and distribution of natural and human-\ncaused hypoxia.Biogeosciences, 7(2), 585\u2013619, doi:10.5194/bg-7-585-\n2010.Racault, M.-F ., S. Sathyendranath, N. Menon and T. Platt, 2017: Phenological \nresponses to ENSO in the global oceans.Surv.Geophys., 38(1), 277\u2013293, \ndoi:10.1007/s10712-016-9391-1.Rafaj, P ., I. Bertok, J. Cofala and W. Sch\u00f6pp, 2013: Scenarios of global mercury \nemissions from anthropogenic sources.Atmos.Environ., 79, 472\u2013479, \ndoi:10.1016/j.atmosenv.2013.06.042.Rahman, M.M., et\u00a0al., 2019: Salinization in large river deltas: drivers, impacts \nand socio-hydrological feedbacks.Water Secur., 6, 100024, doi:10.1016/j.wasec.2019.100024.Raja, N.B.and W. Kiessling,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the paper mentioned in the context that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps?\nAnswer: "}, {"role": "assistant", "content": "The title of the paper that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps is \"Interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps of the Makran accretionary prism: insights from habitat-specific pore water sampling and modeling.\""}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: P ., I. Bertok, J. Cofala and W. Sch\u00f6pp, 2013: Scenarios of global mercury \nemissions from anthropogenic sources.Atmos.Environ., 79, 472\u2013479, \ndoi:10.1016/j.atmosenv.2013.06.042.Rahman, M.M., et\u00a0al., 2019: Salinization in large river deltas: drivers, impacts \nand socio-hydrological feedbacks.Water Secur., 6, 100024, doi:10.1016/j.wasec.2019.100024.Raja, N.B.and W. Kiessling, 2021: Out of the extratropics: the evolution of the \nlatitudinal diversity gradient of Cenozoic marine plankton.Proc.R. Soc.B, \n288(1950), 20210545, doi:10.1098/rspb.2021.0545.Rakib, M. A., et\u00a0 al., 2020: Groundwater salinization and associated co-\ncontamination risk increase severe drinking water vulnerabilities in \nthe southwestern coast of Bangladesh.Chemosphere, 246, 125646, \ndoi:10.1016/j.chemosphere.2019.125646.Ramachandra, T.V.and D. Hebbale, 2020: Bioethanol from macroalgae: \nprospects and challenges.Renew.Sustain.Energy Rev., 117, 109479, \ndoi:10.1016/j.rser.2019.109479.Ramajo, L., et\u00a0 al., 2016: Food supply confers calcifiers resistance to ocean \nacidification.Sci.Rep., 6(1), 19374, doi:10.1038/srep19374.Ramajo, L., et\u00a0 al., 2020: Upwelling intensity modulates the fitness and \nphysiological performance of coastal species: implications for the aquaculture \nof the scallop Argopecten purpuratus in the Humboldt current system.Sci.Total Environ., 745, 140949, doi:10.1016/j.scitotenv.2020.140949.\nQuery: What is the title of the paper mentioned in the context that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps?\nOriginal Answer: The title of the paper that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps is \"Interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps of the Makran accretionary prism: insights from habitat-specific pore water sampling and modeling.\"\nNew Answer: "}, {"role": "assistant", "content": "The title of the paper that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps is \"Interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps of the Makran accretionary prism: insights from habitat-specific pore water sampling and modeling.\""}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 509\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nFlynn, E.E., B.E.Bjelde, N.A.Miller and A.E.Todgham, 2015: Ocean acidification \nexerts negative effects during warming conditions in a developing Antarctic \nfish.Conserv.Physiol., 3(1), cov033, doi:10.1093/conphys/cov033.Folkersen, M.V., 2018: Ecosystem valuation: changing discourse in a time of \nclimate change.Ecosyst.Serv., 29, 1\u201312, doi:10.1016/j.ecoser.2017.11.008.Foo, S.A. and M. Byrne, 2017: Marine gametes in a changing ocean: impacts of \nclimate change stressors on fecundity and the egg.Mar.Environ.Res., 128, \n12\u201324, doi:10.1016/j.marenvres.2017.02.004.Ford, J. and D. Clark, 2019: Preparing for the impacts of climate change along \nCanada\u2019s Arctic coast: the importance of search and rescue.Mar.Policy, 108, \n103662, doi:10.1016/j.marpol.2019.103662.Ford, J.D.and D. King, 2015: A framework for examining adaptation readiness.Mitig.Adapt.Strateg.Glob.Change, 20(4), 505\u2013526, doi:10.1007/s11027-\n013-9505-8.Ford, J.D., et\u00a0al., 2020: The resilience of Indigenous peoples to environmental \nchange.One Earth, 2(6), 532\u2013543, doi:10.1016/j.oneear.2020.05.014.Fordyce, A.J., T.D.Ainsworth, S.F .Heron and W. Leggat, 2019: Marine heatwave \nhotspots in coral reef environments: physical drivers, ecophysiological outcomes, and impact upon structural complexity.Front.Mar.Sci., 6, 498, \ndoi:10.3389/fmars.2019.00498.Forsblom, L., et\u00a0al., 2019: Environmental variables driving species and genus \nlevel changes in annual plankton biomass.J. Plankton Res., 41(6), 925\u2013938, \ndoi:10.1093/plankt/fbz063.F\u00f6rster, J., E. McLeod, M.M.Bruton-Adams and H. Wittmer, 2019: Climate change \nimpacts on small island states: ecosystem services risks and opportunities.In: \nAtlas of Ecosystem Services: Drivers, Risks, and Societal Responses [Schr\u00f6ter, \nM., A. Bonn, S. Klotz, R. Seppelt and C.Baessler(eds.)].Springer International \nPublishing, Cham, pp.353\u2013359.ISBN 978-3319962290.Forster, P .M., A.C. Maycock, C.M.McKenna and C.J.Smith, 2020: Latest climate \nmodels confirm need for urgent mitigation.Nat.Clim.Change, 10(1), 7\u201310, \ndoi:10.1038/s41558-019-0660-0.Fossheim, M., et\u00a0al., 2015: Recent warming leads to a rapid borealization of fish \ncommunities in the Arctic.Nat.Clim.Change, 5(7), 673\u2013677, doi:10.1038/\nnclimate2647.Foster, G.L., P .Hull, D.J.Lunt and J.C. Zachos, 2018: Placing our current \n\u2018hyperthermal\u2019 in the context of rapid climate change in our geological \npast.Philos.Trans.Royal Soc.A Math.Phys.Eng.Sci., 376(2130), 20170086, \ndoi:10.1098/rsta.2017.0086.Foster, K.L., B.M.Braune, A.J.Gaston and M.L.Mallory, 2019: Climate influence \non legacy organochlorine pollutants in Arctic seabirds.Environ.Sci.Technol., \n53(5), 2518\u20132528, doi:10.1021/acs.est.8b07106.\n\npage_label: 504\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nConserv., 48, 1\u201311, doi:10.1016/j.jnc.2018.12.001.Dahlke, F ., et\u00a0al., 2020a: Fish embryo vulnerability to combined acidification and \nwarming coincides with a low capacity for homeostatic regulation.J. Exp.Biol., 223(11), jeb212589, doi:10.1242/jeb.212589.Dahlke, F .T., et\u00a0al., 2018: Northern cod species face spawning habitat losses \nif global warming exceeds 1.5\u00b0C.Sci.Adv., 4(11), eaas8821, doi:10.1126/\nsciadv.aas8821.Dahlke, F .T., et\u00a0 al., 2017: Effects of ocean acidification increase embryonic \nsensitivity to thermal extremes in Atlantic cod, Gadus morhua.Glob.Change \nBiol., 23(4), 1499\u20131510, doi:10.1111/gcb.13527.Dahlke, F .T., S. Wohlrab, M. Butzin and H.-O.P\u00f6rtner, 2020b: Thermal bottlenecks \nin the life cycle define climate vulnerability of fish.Science, 369(6499), 65\u2013\n70, doi:10.1126/science.aaz3658.Dall\u2019Olmo, G., et\u00a0 al., 2016: Substantial energy input to the mesopelagic \necosystem from the seasonal mixed-layer pump.Nat.Geosci., 9(11), 820\u2013\n823, doi:10.1038/ngeo2818.Dam, H.G., 2013: Evolutionary adaptation of marine zooplankton to global \nchange.Annu.Rev.Mar.Sci., 5(1), 349\u2013370, doi:10.1146/annurev-\nmarine-121211-172229.Dangendorf, S., et\u00a0al., 2017: Reassessment of 20th\u00a0century global mean sea \nlevel rise.Proc.Natl.Acad.Sci.U.S.A., 114(23), 5946\u20135951, doi:10.1073/\npnas.1616007114.Danovaro, R., 2018: Climate change impacts on the biota and on vulnerable \nhabitats of the deep Mediterranean Sea.Rend.Lincei Sci.Fis.Nat., 29(3), \n525\u2013541, doi:10.1007/s12210-018-0725-4.Danovaro, R., et\u00a0al., 2020: Ecological variables for developing a global deep-\nocean monitoring and conservation strategy.Nat.Ecol.Evol., 4(2), 181\u2013192, \ndoi:10.1038/s41559-019-1091-z.Darling, E.S.and\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title and DOI of the study that examines the negative effects of ocean acidification during warming conditions in a developing Antarctic fish?\nAnswer: "}, {"role": "assistant", "content": "The title of the study is \"Ocean acidification exerts negative effects during warming conditions in a developing Antarctic fish\" and its DOI is 10.1093/conphys/cov033."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 5946\u20135951, doi:10.1073/\npnas.1616007114.Danovaro, R., 2018: Climate change impacts on the biota and on vulnerable \nhabitats of the deep Mediterranean Sea.Rend.Lincei Sci.Fis.Nat., 29(3), \n525\u2013541, doi:10.1007/s12210-018-0725-4.Danovaro, R., et\u00a0al., 2020: Ecological variables for developing a global deep-\nocean monitoring and conservation strategy.Nat.Ecol.Evol., 4(2), 181\u2013192, \ndoi:10.1038/s41559-019-1091-z.Darling, E.S.and I.M.C\u00f4t\u00e9, 2018: Seeking resilience in marine ecosystems.Science, 359(6379), 986\u2013987, doi:10.1126/science.aas9852.Darling, E.S., et\u00a0 al., 2019: Social\u2013environmental drivers inform strategic \nmanagement of coral reefs in the Anthropocene.Nat.Ecol.Evol., 3(9), 1341\u2013\n1350, doi:10.1038/s41559-019-0953-8.Darmaraki, S., S. Somot, F .Sevault and P .Nabat, 2019: Past variability of \nMediterranean Sea marine heatwaves.Geophys.Res.Lett., 46(16), 9813\u2013\n9823, doi:10.1029/2019GL082933.\nQuery: What is the title and DOI of the study that examines the negative effects of ocean acidification during warming conditions in a developing Antarctic fish?\nOriginal Answer: The title of the study is \"Ocean acidification exerts negative effects during warming conditions in a developing Antarctic fish\" and its DOI is 10.1093/conphys/cov033.\nNew Answer: "}, {"role": "assistant", "content": "The title of the study is \"Ocean acidification exerts negative effects during warming conditions in a developing Antarctic fish\" and its DOI is 10.1093/conphys/cov033."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 498\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nGlob.Environ.Change, 6, 102054, doi:10.1016/j.gloenvcha.2020.102054.Bostr\u00f6m-Einarsson, L., et\u00a0al., 2020: Coral restoration\u2014A systematic review of \ncurrent methods, successes, failures and future directions.PLoS ONE, 15(1), \ne226631, doi:10.1371/journal.pone.0226631.Bouderbala, A., 2019: The impact of climate change on groundwater resources \nin coastal aquifers: case of the alluvial aquifer of Mitidja in Algeria.Environ.Earth Sci., 78(24), 698, doi:10.1007/s12665-019-8702-5.Bourque, J., et\u00a0al., 2020: Climate-associated drivers of plasma cytokines and \ncontaminant concentrations in Beaufort Sea polar bears (Ursus maritimus).Sci.Total Environ., 745, 140978, doi:10.1016/j.scitotenv.2020.140978.Bouyoucos, I.A., et\u00a0 al., 2020: Thermal tolerance and hypoxia tolerance are \nassociated in blacktip reef shark (Carcharhinus melanopterus) neonates.J. \nExp.Biol., 223(14), jeb221937, doi:10.1242/jeb.221937.Bowen, W.D., et\u00a0al., 2020: Exploring causal components of plasticity in grey seal \nbirthdates: effects of intrinsic traits, demography, and climate.Ecol.Evol., \n10(20), 11507\u201311522, doi:10.1002/ece3.6787.Bowler, D.E., et\u00a0al., 2020: Mapping human pressures on biodiversity across the \nplanet uncovers anthropogenic threat complexes.People Nat., 2(2), 380\u2013\n394, doi:10.1002/pan3.10071.Bowman, K.L., C.H.Lamborg and A.M. Agather, 2020: A global perspective on \nmercury cycling in the ocean.Sci.Total Environ., 710, 136166, doi:10.1016/j.scitotenv.2019.136166.Boyce, D.G., et\u00a0al., 2020: Future ocean biomass losses may widen socioeconomic \nequity gaps.Nat.Commun., 11(1), 2235, doi:10.1038/s41467-020-15708-9.Boyd, P .W., 2019: Physiology and iron modulate diverse responses of diatoms to \na warming Southern Ocean.Nat.Clim.Change, 9(2), 148\u2013152, doi:10.1038/\ns41558-018-0389-1.Boyd, P .W., et\u00a0al., 2019: Multi-faceted particle pumps drive carbon sequestration \nin the ocean.Nature, 568(7752), 327\u2013335, doi:10.1038/s41586-019-1098-\n2.Boyd, P .W., et\u00a0 al., 2018: Experimental strategies to assess the biological \nramifications of multiple drivers of global ocean change\u2014a review.Glob.Change Biol., 24(6), 2239\u20132261, doi:10.1111/gcb.14102.Boyd, P .W., et\u00a0al., 2016: Biological responses to environmental heterogeneity \nunder future ocean conditions.Glob.Change Biol., 22(8), 2633\u20132650, \ndoi:10.1111/gcb.13287.Boyd, P .W., et\u00a0al., 2015a: Physiological responses of a Southern Ocean diatom \nto complex future ocean conditions.Nat.Clim.Change, 6, 207\u2013213, \ndoi:10.1038/nclimate2811.\n\npage_label: 544\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nNat.Clim.Change, 11, 973\u2013981, \ndoi:10.1038/s41558-021-01173-9.Todd, P .A., et\u00a0al., 2019: Towards an urban marine ecology: characterizing the \ndrivers, patterns and processes of marine ecosystems in coastal cities.Oikos, \n128(9), 1215\u20131242, doi:10.1111/oik.05946.Toimil, A., et\u00a0 al., 2020: Addressing the challenges of climate change risks \nand adaptation in coastal areas: a review.Coast.Eng., 156, 103611, \ndoi:10.1016/j.coastaleng.2019.103611.Tomasetti, S.J., B.K.Morrell, L.R.Merlo and C.J.Gobler, 2018: Individual and \ncombined effects of low dissolved oxygen and low pH on survival of early \nstage larval blue crabs, Callinectes sapidus.PLoS ONE, 13(12), e0208629, \ndoi:10.1371/journal.pone.0208629.Tommasi, D., et\u00a0 al., 2017: Managing living marine resources in a dynamic \nenvironment: the role of seasonal to decadal climate forecasts.Prog.Oceanogr., 152, 15\u201349, doi:10.1016/j.pocean.2016.12.011.Tompkins, E.L., et\u00a0 al., 2020: Adapting to change: people and policies.In: \nDeltas in the Anthropocene [Nicholls, R.J., W.N.Adger, C.W.Hutton and S.E.Hanson(eds.)].Springer International Publishing, Cham, pp.201\u2013222.ISBN \n978-3030235178.T\u00f6rnqvist, T.E., D.R.Cahoon, J.T.Morris and J.W.Day, 2021: Coastal wetland \nresilience, accelerated sea-level rise, and the importance of timescale.AGU \nAdv., 2(1), e2020AV00034, doi:10.1029/2020AV000334.T\u00f6rnqvist, T.E., K.L.Jankowski, Y .-X.Li and J.L.Gonz\u00e1lez, 2020: Tipping points of \nMississippi Delta marshes due to accelerated sea-level rise.Sci.Adv., 6(21), \neaaz5512, doi:10.1126/sciadv.aaz5512.Torres, O., et\u00a0al., 2021: Characterizing mean and extreme diurnal variability of \nocean CO 2 system variables across marine environments.Geophys.Res.Lett., \n48(5), e2020GL090228, doi:10.1029/2020GL090228.Torstensson, A., et\u00a0 al., 2021: Sea-ice microbial communities in the Central \nArctic Ocean: limited responses to short-term pCO 2 perturbations.Limnol.Oceanogr., 66(S1), S383\u2013S400, doi:10.1002/lno.11690.Toth, L.T., et\u00a0al., 2019: The unprecedented loss of Florida\u2019s reef-building corals \nand the emergence of a novel coral-reef assemblage.Ecology,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title and publication year of the report on climate change and the oceans mentioned in the context?\nAnswer: "}, {"role": "assistant", "content": "The title of the report is \"Experimental strategies to assess the biological ramifications of multiple drivers of global ocean change\u2014a review\" and it was published in 2018."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: mean and extreme diurnal variability of \nocean CO 2 system variables across marine environments.Geophys.Res.Lett., \n48(5), e2020GL090228, doi:10.1029/2020GL090228.Torstensson, A., et\u00a0 al., 2021: Sea-ice microbial communities in the Central \nArctic Ocean: limited responses to short-term pCO 2 perturbations.Limnol.Oceanogr., 66(S1), S383\u2013S400, doi:10.1002/lno.11690.Toth, L.T., et\u00a0al., 2019: The unprecedented loss of Florida\u2019s reef-building corals \nand the emergence of a novel coral-reef assemblage.Ecology, 100(9), \ne02781, doi:10.1002/ecy.2781.Towle, E.K., I.C.Enochs and C. Langdon, 2015: Threatened Caribbean coral is \nable to mitigate the adverse effects of ocean acidification on calcification by \nincreasing feeding rate.PLoS ONE, 10(4), e0123394, doi:10.1371/journal.pone.0123394.Townhill, B.L., et\u00a0al., 2019: Marine recreational fishing and the implications of \nclimate change.Fish Fish., 20(5), 977\u2013992, doi:10.1111/faf.12392.Townhill, B.L., et\u00a0 al., 2017: Consequences of climate-induced low oxygen \nconditions for commercially important fish.Mar.Ecol.Prog.Ser., 580, 191\u2013\n204, doi:10.3354/meps12291.\nQuery: What is the title and publication year of the report on climate change and the oceans mentioned in the context?\nOriginal Answer: The title of the report is \"Experimental strategies to assess the biological ramifications of multiple drivers of global ocean change\u2014a review\" and it was published in 2018.\nNew Answer: "}, {"role": "assistant", "content": "The original answer doesn't match the new context provided."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 430\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n430Chapter 3 Oceans and Coastal Ecosystems and Their Services\net\u00a0 al., 2020b; Fiechter et\u00a0 al., 2021), are confounded by local-scale \noceanographic processes (Siedlecki et\u00a0al., 2021) and by lateral input of \nanthropogenic land-based nutrients (Kessouri et\u00a0al., 2021), suggesting \nthat such projections should be accorded low confidence.More generally, changes in upwelling intensity are observed to affect \norganismal metabolism, population productivity and recruitment, and food-web structure (medium confidence) (van der Sleen et\u00a0 al., \n2018; Brodeur et\u00a0al., 2019; Ramajo et\u00a0al., 2020).But low confidence \nin projected trends in upwelling make it difficult to extrapolate these \nresults to understand potential changes in the ecology of EBUS.Projected changes in fish biomass within EBUS (Carozza et\u00a0al., 2019) \nare therefore accorded low confidence.Finally, although MHWs are \nan important emerging hazard in the global ocean, with intensity, Table\u00a03.13 | \u00a0Summary of previous IPCC assessments of eastern boundary upwelling systems (EBUS)\nObservations Projections\nAR5 (Hoegh-Guldberg et\u00a0al., 2014; Lluch-Cota et\u00a0al., 2014)\n\u2018[EBUS] are vulnerable to changes that influence the intensity of currents, upwelling and \nmixing (and hence changes in sea surface temperature, wind strength and direction), as well \nas O 2 content, carbonate chemistry, nutrient content and the supply of organic carbon to \ndeep offshore locations (high confidence).\u2019\nClimate-change-induced intensification of ocean upwelling in some EBUS, as observed in \npast decades, may lead to regional cooling, rather than warming, of surface waters and \ncause enhanced productivity (medium confidence), but also enhanced hypoxia, acidification \nand associated biomass reduction in fish and invertebrate stocks.Owing to contradictory \nobservations, there is currently uncertainty about the future trends of major upwelling \nsystems and how their drivers will shape ecosystem characteristics ( low confidence).\u2018Declining O 2 and shoaling of the aragonite saturation horizon through ocean acidification \nincrease the risk of upwelling water being low in pH and O 2, with impacts on coastal \necosystems and fisheries [...].These risks and uncertainties are likely to involve significant \nchallenges for fisheries and associated livelihoods along the west coasts of South America, \nAfrica and North America (low to medium confidence).\u2019\n\u2018There is robust evidence and medium agreement that the California Current has \nexperienced [...] an increase of the overall magnitude of upwelling events from 1967 to \n2010 (high confidence).This is consistent with changes expected under climate change \nyet remains complicated by the influence of decadal-scale variability (low confidence).\u2019 \nDeclining oxygen concentrations and shoaling of the hypoxic boundary layer likely \u2018reduced \nthe available habitat for key benthic communities as well as fish and other mobile species.Together with the shoaling of the saturation horizon, these changes have increased the \nincidence of low O 2 and low pH water flowing onto the continental shelf (high confidence; \n40 to 120 m), causing problems for industries such as the shellfish aquaculture industry.\u2019\nDespite its apparent sensitivity to environmental variability, there is limited evidence of \necological changes in the Benguela Current EBUS due to climate change.\u2018Like other ocean sub-regions, [EBUS] are projected to warm under climate change, with \nincreased stratification and intensified winds as westerly winds shift poleward (likely).However, cooling has also been predicted for some [EBUS], resulting from the intensification \nof wind-driven upwelling.\u2019\n\u2018There is medium agreement, despite limited evidence, that upwelling intensity and \nassociated variables (e.g., temperature, nutrient and O 2 concentrations) from the Benguela \nsystem will change as a result of climate change.\u2019\nAny projected increase in upwelling intensity has potential disadvantages.\n\npage_label: 429\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n429Oceans and Coastal Ecosystems and Their Services Chapter 3\nhas strongly decreased in the North Sea (Free et\u00a0al., 2019), and fisheries \nyields have also decreased in the Celtic Sea, attributed primarily to \nwarming and secondarily to long-term exploitation (Hernvann and \nGascuel, 2020; M\u00e9rillet et\u00a0al., 2020).Conversely, fish species diversity \nand overall productivity have increased in the Gulf of Maine, even with \nwarming (Le Bris et\u00a0al., 2018; Friedland et\u00a0al., 2020a; Friedland et\u00a0al., \n2020b).Fisheries yields have decreased in the Yellow Sea, East China \nSea and South China Sea partially due to overexploitation (Ma et\u00a0al., \n2019; Wang et\u00a0al., 2019c), with warming exerting more influence on \nthe yield of cold-water species than on temperate- and warm-water \ngroups (Ma et\u00a0 al., 2019).The combined effects of exploitation and \nmulti-decadal climate fluctuations make it difficult to assess global \nclimate-change impacts on fisheries yields (Chapter\u00a05; Ma et\u00a0al., 2019; \nBentley et\u00a0al., 2020b; Johnson et\u00a0al., 2020).Since AR5, increasing spatio-temporal extent of hypoxia has been \nprojected due to enhanced benthic respiration and reduced oxygen \nsolubility from warming (Del Giudice et\u00a0 al., 2020).Similar to the \nopen ocean, large shifts in the phenology of phytoplankton blooms \nhave been projected for shelf seas throughout subpolar and polar \nwaters (medium confidence) (Henson et\u00a0al., 2018a; Asch et\u00a0al., 2019).Zooplankton, which are important prey for many fish species and sea \nbirds, are expected to decrease in abundance on the northeast shelf \nof the USA (Grieve et\u00a0 al., 2017); however, responses vary by shelf \necosystem (Chust et\u00a0 al., 2014b).Trends towards tropicalisation will \ncontinue in the future (high confidence) (Cheung et\u00a0al., 2015; Stortini \net\u00a0al., 2015; Allyn et\u00a0al., 2020; Maltby et\u00a0al., 2020; Costa et\u00a0al., 2021), \nbut uncertainty of future projections of fisheries production increases \nsubstantially beyond 2040 (Maltby et\u00a0al., 2020).Nevertheless, shelf-\nsea fisheries at lower latitudes are most vulnerable to climate change \n(Monnereau et\u00a0 al., 2017).Under future climate change marked by \nmore frequent and intense extreme events and the influences of \nmultiple drivers, more flexible and adaptive management approaches \ncould reduce climate impacts on species while also supporting industry \nadaptation (high confidence) (Section\u00a03.6.3.1.2; Shackell et\u00a0al., 2014; \nStortini et\u00a0al., 2015; Hare et\u00a0al., 2016; Stortini et\u00a0al., 2017; Greenan \net\u00a0al., 2019; Oca\u00f1a et\u00a0al., 2019; Maltby et\u00a0al., 2020).3.4.2.9 Upwelling\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the key risks to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to projected changes in upwelling-favourable winds?\nAnswer: "}, {"role": "assistant", "content": "The key risks to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to projected changes in upwelling-favourable winds include changes that influence the intensity of currents, upwelling and mixing. These changes can affect sea surface temperature, wind strength and direction, as well as oxygen content, carbonate chemistry, nutrient content and the supply of organic carbon to deep offshore locations. Climate-change-induced intensification of ocean upwelling in some EBUS may lead to regional cooling of surface waters and cause enhanced productivity, but also enhanced hypoxia, acidification and associated biomass reduction in fish and invertebrate stocks. There is also a risk of upwelling water being low in pH and oxygen, which can impact coastal ecosystems and fisheries. These risks and uncertainties are likely to pose significant challenges for fisheries and associated livelihoods along the west coasts of South America, Africa and North America."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 2020).Nevertheless, shelf-\nsea fisheries at lower latitudes are most vulnerable to climate change \n(Monnereau et\u00a0 al., 2017).Under future climate change marked by \nmore frequent and intense extreme events and the influences of \nmultiple drivers, more flexible and adaptive management approaches \ncould reduce climate impacts on species while also supporting industry \nadaptation (high confidence) (Section\u00a03.6.3.1.2; Shackell et\u00a0al., 2014; \nStortini et\u00a0al., 2015; Hare et\u00a0al., 2016; Stortini et\u00a0al., 2017; Greenan \net\u00a0al., 2019; Oca\u00f1a et\u00a0al., 2019; Maltby et\u00a0al., 2020).3.4.2.9 Upwelling Zones\nEastern boundary upwelling systems (EBUS) comprise four important \nsocial\u2013ecological systems in the Pacific (California and Peru-Humboldt) \nand Atlantic (Canary and Benguela) ocean basins.Each is characterised \nby high primary production, sustained by wind-driven upwelling that \ndraws cold, nutrient-rich, generally low-pH and low-oxygen water to \nthe surface (Bindoff et\u00a0 al., 2019a).Despite their small relative size, \nthe primary productivity in EBUS supports a vast biomass of marine \nconsumers, including some of the world\u2019s most productive fisheries \n(Pauly and Zeller, 2016), along with many species of conservation \nsignificance (Bakun et\u00a0al., 2015).Although upwelling is important in many other oceanic regions, we \nfocus here on the most documented examples provided by the EBUS.\nQuery: What are the key risks to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to projected changes in upwelling-favourable winds?\nOriginal Answer: The key risks to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to projected changes in upwelling-favourable winds include changes that influence the intensity of currents, upwelling and mixing. These changes can affect sea surface temperature, wind strength and direction, as well as oxygen content, carbonate chemistry, nutrient content and the supply of organic carbon to deep offshore locations. Climate-change-induced intensification of ocean upwelling in some EBUS may lead to regional cooling of surface waters and cause enhanced productivity, but also enhanced hypoxia, acidification and associated biomass reduction in fish and invertebrate stocks. There is also a risk of upwelling water being low in pH and oxygen, which can impact coastal ecosystems and fisheries. These risks and uncertainties are likely to pose significant challenges for fisheries and associated livelihoods along the west coasts of South America, Africa and North America.\nNew Answer: "}, {"role": "assistant", "content": "The potential hazards to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to anticipated alterations in upwelling-favorable winds encompass modifications that impact the strength of currents, upwelling, and mixing. These alterations can influence sea surface temperature, wind power and direction, as well as oxygen levels, carbonate chemistry, nutrient levels, and the delivery of organic carbon to deep offshore areas. Intensification of ocean upwelling in some EBUS due to climate change may result in regional cooling of surface waters and increased productivity, but also heightened hypoxia, acidification, and associated reduction in fish and invertebrate biomass. There's also a risk that upwelling water may be low in pH and oxygen, which can affect coastal ecosystems and fisheries. These risks and uncertainties are likely to present significant challenges for fisheries and associated livelihoods along the west coasts of South America, Africa, and North America."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 431\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nPrevious assessments of polar seas (Table\u00a03.14) concluded that climate \nchange has already profoundly influenced polar ecosystems, through \nchanging species distributions and abundances from primary producers \nto top predators, including both ecologically and economically important \nspecies (high confidence), and that it will continue to do so (Table\u00a03.14).Since SROCC, evidence demonstrates that warmer oceans, less sea \nice and increased advection results in increasing primary production \nin the Arctic, albeit with regional variation (high confidence), while \ntrends remain spatially heterogeneous and less clear in the Antarctic \n(medium confidence) (Cross-Chapter\u00a0 Paper 6; Del Castillo et\u00a0 al., \n2019; Lewis et\u00a0al., 2020; Pinkerton et\u00a0al., 2021; Song et\u00a0al., 2021a).Furthermore, climate warming influences key mechanisms determining \nenergy transfer between trophic levels including (a) altered size \nspectra, (b) shifts in trophic pathways, (c) phenological mismatches \nand (d) increased top-down trophic regulation (Table\u00a03.15); however, \nthe scale of impacts from changes in these mechanisms on ecosystem \nproductivity in warming polar oceans remains unresolved and is hence \nassigned low confidence.Major community shifts, both gradual and abrupt, are observed in polar \noceans in response to warming trends and MHWs (Arctic only) (high \nconfidence) (Figure\u00a03.12; Cross-Chapter\u00a0Paper 6; Beaugrand et\u00a0al., 2019; \nMeredith et\u00a0al., 2019; Huntington et\u00a0al., 2020).In general, abundances \nand ranges of Arctic fish species are declining and contracting, while \nranges of boreal fish species are expanding, both geographically and \nin terms of feeding interactions and ecological roles (high confidence) \n(Huserbr\u00e5ten et\u00a0al., 2019; Meredith et\u00a0al., 2019; Huntington et\u00a0al., 2020; \nPecuchet et\u00a0al., 2020a), with variable outcomes for large commercial \nfish stocks (Cross-Chapter\u00a0Paper 6; Kjesbu et\u00a0al., 2014; Holsman et\u00a0al., \n2018; Free et\u00a0al., 2019).The extreme seasonal solar radiation cycles of \nthese high latitudes may both act as a barrier for species immigration \nand change predator\u2013prey dynamics in previously ice-covered areas, \nfactors not currently considered in projections (limited evidence) \n(Kaartvedt and Titelman, 2018; Ljungstr\u00f6m et\u00a0al., 2021).Responses by \nmarine mammals and birds to the ongoing changes in polar ecosystems \nare both positive and negative (Meredith et\u00a0al., 2019; Bestley et\u00a0al., \n2020).Phenological, behavioural, physiological and distributional \nchanges are observed in marine mammals and birds in response to \naltered ecological interactions and habitat degradation, especially to \nloss of sea ice (high confidence) (see Box\u00a0 3.2; Cross-Chapter\u00a0 Paper \n6; Beltran et\u00a0 al., 2019; Cusset et\u00a0 al., 2019; Descamps et\u00a0 al., 2019; \nMeredith et\u00a0al., 2019; Huntington et\u00a0al., 2020).Reproductive failures \nand declining abundances attributed to warmer polar oceans and \nless sea ice cover are observed in populations of polar bears, Ursus \nmaritimus, seals, whales and marine birds (high confidence) (see \nBox\u00a0 3.2; Duffy-Anderson et\u00a0 al., 2019; Ropert-Coudert et\u00a0 al., 2019; \nBestley et\u00a0al., 2020; Chambault et\u00a0al., 2020; Moln\u00e1r et\u00a0al., 2020; Stenson \net\u00a0al., 2020).The ongoing changes in polar marine ecosystems can lead \nto temporary increases in biodiversity and functional diversity (e.g., \ndue to immigration of boreal species in the Arctic, high confidence), \nbut reduced trophic-transfer efficiencies and functional redundancy, \nwith uncertain consequences for ecosystem resilience and vulnerability \n(limited evidence, low agreement) (Griffith et\u00a0al., 2019b; Alabia et\u00a0al., \n2020; du Pontavice et\u00a0al., 2020; Alabia et\u00a0al., 2021; Frainer et\u00a0al., 2021).Calcareous polar organisms are among the groups most sensitive \nto ocean acidification (high confidence) (Section\u00a0 3.3.2).Niemi et\u00a0 al.\n\npage_label: 432\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThere is high agreement and robust evidence \nthat phytoplankton species will change because of sea ice retreat and related changes in \ntemperature and radiation, and this is very likely to benefit fisheries productivity [in the \nArctic spring bloom system].\u2019\n\u2018\u2018Unique and threatened systems\u2019 (RFC1), [including Arctic and coral reefs], display a \ntransition from high to very high risk of transition at temperatures between 1.5\u00b0C and 2\u00b0C \nof global warming, as opposed to at 2.6\u00b0C of global warming in AR5 (high confidence).\u2019\nSROCC (Bindoff et\u00a0al., 2019a)\nClimate-induced changes in seasonal sea ice extent and thickness as well as ocean \nstratification are altering marine primary production ( high confidence), with impacts on \necosystems (medium confidence).Changes in the timing, duration and magnitude of primary production have occurred in both \npolar oceans, with marked regional or local variability (high confidence).In both polar regions, climate-induced changes in ocean and sea ice conditions have \nexpanded the range of temperate species and contracted the range of polar fish and \nice-associated species (high confidence).Ocean acidification will affect several key Arctic species (medium confidence).Future climate-induced changes in the polar oceans, sea ice, snow and permafrost will \ndrive habitat and biome shifts, with associated changes in the ranges and abundance of \necologically important species (medium confidence).Projected range expansion of sub-Arctic marine species will increase pressure for high-Arctic \nspecies (medium confidence), with regionally variable impacts.Both polar oceans will be increasingly affected by CO 2 uptake, causing corrosive conditions \nfor calcium carbonate shell-producing organisms (high confidence), with associated impacts \non marine organisms and ecosystems (medium confidence).The projected effects of climate-induced stressors on polar marine ecosystems present risks \nfor commercial and subsistence fisheries, with implications for regional economies, cultures \nand the global supply of fish, shellfish, and Antarctic krill (high confidence).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are some observed impacts of climate change on polar marine ecosystems, including changes in species distributions and abundances, and the influence of warmer oceans and reduced sea ice?\nAnswer: "}, {"role": "assistant", "content": "Climate change has significantly impacted polar marine ecosystems, with changes in species distributions and abundances from primary producers to top predators. Warmer oceans and reduced sea ice have led to increased primary production in the Arctic, although the trends are less clear in the Antarctic. These changes have also influenced key mechanisms determining energy transfer between trophic levels, such as altered size spectra, shifts in trophic pathways, phenological mismatches, and increased top-down trophic regulation. \n\nMajor community shifts have been observed in polar oceans in response to warming trends. In the Arctic, the abundances and ranges of fish species are declining and contracting, while the ranges of boreal fish species are expanding. The extreme seasonal solar radiation cycles of these high latitudes may act as a barrier for species immigration and change predator\u2013prey dynamics in previously ice-covered areas. \n\nMarine mammals and birds have shown both positive and negative responses to these changes, with observed changes in their behavior, physiology, and distribution, especially due to loss of sea ice. Reproductive failures and declining abundances have been observed in populations of polar bears, seals, whales, and marine birds due to warmer polar oceans and less sea ice cover. \n\nThe ongoing changes can lead to temporary increases in biodiversity and functional diversity, but also reduced trophic-transfer efficiencies and functional redundancy, with uncertain consequences for ecosystem resilience and vulnerability. Calcareous polar organisms are among the groups most sensitive to ocean acidification."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 431\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n(2021) reports that >80% of sampled sea snail, Limacina helicina, a key \nspecies in pelagic food webs, displayed signs of shell dissolution in the \nAmundsen Gulf.However, bacteria, phytoplankton, zooplankton and \nbenthic communities are found to be detrimentally impacted, resilient \nor even positively influenced by ocean acidification in observational\n\npage_label: 502\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBal, E. Goetze and K.T.C.A.Peijnenburg, 2021: Oceanic \ndispersal barriers in a holoplanktonic gastropod.J. Evol.Biol., 34(1), 224\u2013\n240, doi:10.1111/jeb.13735.Chow, J., 2018: Mangrove management for climate change adaptation and \nsustainable development in coastal zones.J.Sustain.For., 37(2), 139\u2013156, \ndoi:10.1080/10549811.2017.1339615.Chowdhury, M.S.N., et\u00a0 al., 2019: Oyster breakwater reefs promote adjacent \nmudflat stability and salt marsh growth in a monsoon dominated subtropical \ncoast.Sci.Rep., 9(1), 8549, doi:10.1038/s41598-019-44925-6.Christensen, J.H., et al., 2007: Regional climate projections.In: Climate Change \n2007: The Physical Science Basis.Contribution of Working Group I to the \nFourth Assessment Report of the Intergovernmental Panel on Climate \nChange.[Solomon, S., D. Qin, M. Manning, Z. Chen, M. Marquis, K. B. Averyt, \nM. Tignor and H. L. Miller (eds.)].Cambridge University Press, Cambridge, UK \nand New York, NY , USA, pp.847\u2013940.ISBN 978-0521880091.Christensen, V., et\u00a0al., 2014: A century of fish biomass decline in the ocean.Mar.Ecol.Prog.Ser., 512, 155\u2013166, doi:10.3354/meps10946.Christian, J.R., 2014: Timing of the departure of ocean biogeochemical cycles \nfrom the preindustrial state.Plos One, 9(11), e109820, doi:10.1371/journal.pone.0109820.Christie, H., et\u00a0al., 2019: Shifts between sugar kelp and turf algae in Norway: \nregime shifts or fluctuations between different opportunistic seaweed \nspecies?Front.Mar.Sci., 6, 72, doi:10.3389/fmars.2019.00072.Christodoulou, A., P .Christidis and H. Demirel, 2019: Sea-level rise in ports: a \nwider focus on impacts.Marit.Econ.Logist., 21(4), 482\u2013496, doi:10.1057/\ns41278-018-0114-z.Chu, J.W.F .and V. Tunnicliffe, 2015: Oxygen limitations on marine animal \ndistributions and the collapse of epibenthic community structure during \nshoaling hypoxia.Glob.Change Biol., 21(8), 2989\u20133004, doi:10.1111/\ngcb.12898.Chung, W.-S., et\u00a0 al., 2014: Ocean acidification slows retinal function in a \ndamselfish through interference with GABA A receptors.J. Exp.Biol., 217(3), \n323\u2013326, doi:10.1242/jeb.092478.Church, J.A.and N.J. White, 2011: Sea-level rise from the late 19th to the early \n21st\u00a0 century.Surv.Geophys., 32(4-5), 585\u2013602, doi:10.1007/s10712-011-\n9119-1.Chust, G., et\u00a0al., 2014a: Biomass changes and trophic amplification of plankton \nin a warmer ocean.Glob.Change Biol., 20(7), 2124\u20132139, doi:10.1111/\ngcb.12562.Chust, G., et\u00a0 al., 2014b: Are Calanus spp.shifting poleward in the North \nAtlantic?A habitat modelling approach.ICES J. Mar.Sci., 71(2), 241\u2013253, \ndoi:10.1093/icesjms/fst147.Chust, G., et\u00a0al., 2019: Earlier migration and distribution changes of albacore \nin the Northeast Atlantic.Fish.Oceanogr., 28(5), 505\u2013516, doi:10.1111/\nfog.12427.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What percentage of sampled sea snail, Limacina helicina, in the Amundsen Gulf displayed signs of shell dissolution according to the report?\nAnswer: "}, {"role": "assistant", "content": "More than 80% of the sampled sea snail, Limacina helicina, in the Amundsen Gulf displayed signs of shell dissolution according to the report."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 424\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n424Chapter 3 Oceans and Coastal Ecosystems and Their Services\nTable\u00a03.9 | \u00a0Summary of previous IPCC assessments of sandy beaches.Observations Projections\nAR5 (Wong et\u00a0al., 2014)\n\u2018Globally, beaches and dunes have in general undergone net erosion over the past century \nor longer.\u2019\n\u2018Attributing shoreline changes to climate change is still difficult owing to the multiple natural \nand anthropogenic drivers contributing to coastal erosion.\u2019\u2018In the absence of adaptation, beaches, sand dunes and cliffs currently eroding will continue \nto do so under increasing sea level (high confidence).\u2019\n\u2018Coastal squeeze is expected to accelerate with a rising sea level.In many locations, finding \nsufficient sand to rebuild beaches and dunes artificially will become increasingly difficult and \nexpensive as present supplies near project sites are depleted ( high confidence).\u2019\n\u2018In the absence of adaptation measures, beaches and sand dunes currently affected by \nerosion will continue to be affected under increasing sea levels ( high confidence).\u2019\nSROCC (Bindoff et\u00a0al., 2019a)\nCoastal ecosystems are already impacted by the combination of SLR, other climate-related \nocean changes and adverse effects from human activities on ocean and land ( high \nconfidence).Attributing such impacts to SLR, however, remains challenging due to \nthe influence of other climate-related and non-climate drivers such as infrastructure \ndevelopment and human-induced habitat degradation ( high confidence).Coastal \necosystems, including salt marshes, mangroves, vegetated dunes and sandy beaches, can \nbuild vertically and expand laterally in response to SLR, though this capacity varies across \nsites (high confidence) as a consequence of human actions that fragment wetland habitats \nand restrict landward migration.Coastal ecosystems also progressively lose their ability \nto adapt to climate-induced changes and provide ecosystem services, including acting as \nprotective barriers (high confidence).\u2018Loss of breeding substrate, including mostly coastal habitats such as sandy beaches, can \nreduce the available nesting or pupping habitat for land-breeding marine turtles, lizards, \nseabirds and pinnipeds (high confidence).\u2019\n\u2018Overall, changes in sandy beach morphology have been observed from climate-related \nevents, such as storm surges, intensified offshore winds and from coastal degradation \ncaused by humans (high confidence), with impacts on beach habitats (e.g., benthic \nmegafauna) (medium confidence).\u2019\u2018Sandy beach ecosystems will increasingly be at risk of eroding, reducing the habitable area \nfor dependent organisms (high confidence).\u2019\n\u2018Sandy shorelines are expected to continue to reduce their area and change their topography \ndue to SLR and increased extreme climatic erosive events.This will be especially important in \nlow-lying coastal areas with high population and building densities ( medium confidence).\u2019\n\u2018Assuming that the physiological underpinning of the relationship between body size and \ntemperature can be applied to warming (medium confidence), the body size of sandy beach \ncrustaceans is expected to decrease under warming (low evidence, medium agreement).\u2019\nSandy beaches transition from undetectable to moderate risk between 0.9\u00b0C and 1.8\u00b0C \n(medium confidence) of global sea surface warming and from moderate to high risk at \n2.3\u00b0C\u20133.0\u00b0C of global sea surface warming (medium confidence).\u2018Projected changes in mean and extreme sea levels and warming under RCP8.5 are expected \nto result in high risk of impacts on sandy beach ecosystems by the end of the 21st\u00a0century \n(medium confidence), taking account of the slow recovery rate of sandy-beach vegetation, \nthe direct loss of habitats and the high climatic sensitivity of some fauna.\u2019\n\u2018Under RCP2.6, the risk of impacts on sandy beaches is expected to be only slightly higher \nthan the present-day level (low confidence).However, pervasive coastal urbanisation lowers \nthe buffering capacity and recovery potential of sandy beach ecosystems to impacts from \nSLR and warming, and thus is expected to limit their resilience to climate change ( high \nconfidence).\u2019\n\u2018Coastal squeeze and human-driven habitat deterioration will reduce the natural capacity of \nthese ecosystems to adapt to climate impacts (high confidence).\u2019\nby 2100 under all scenarios except SSP1-1.9 (high confidence).\n\npage_label: 539\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nICES J. Mar.Sci., 74(4), 895\u2013925, doi:10.1093/icesjms/fsw254.Schoutens, K., et\u00a0al., 2020: Nature-based shoreline protection by tidal marsh \nplants depends on trade-offs between avoidance and attenuation of \nhydrodynamic forces.Estuar.Coast.Shelf Sci., 236, 106645, doi:10.1016/j.ecss.2020.106645.Schuerch, M., T. Spencer and B. Evans, 2019: Coupling between tidal mudflats \nand salt marshes affects marsh morphology.Mar.Geol., 412, 95\u2013106, \ndoi:10.1016/j.margeo.2019.03.008.Schuerch, M., et\u00a0al., 2018: Future response of global coastal wetlands to sea-\nlevel rise.Nature, 561(7722), 231\u2013234, doi:10.1038/s41586-018-0476-5.Schultz, J.A., R.N.Cloutier and I.M.C\u00f4t\u00e9, 2016: Evidence for a trophic cascade \non rocky reefs following sea star mass mortality in British Columbia.PeerJ, \n4, e1980, doi:10.7717/peerj.1980.Schwaner, C., et\u00a0 al., 2020: Experimental acidification increases susceptibility \nof Mercenaria mercenaria to infection by Vibrio species.Mar.Environ.Res., \n154, 104872, doi:10.1016/j.marenvres.2019.104872.Schwieterman, D.G., et\u00a0 al., 2019: Combined effects of acute temperature \nchange and elevated pCO 2 on the metabolic rates and hypoxia tolerances \nof clearnose skate (Rostaraja eglanteria), summer flounder (Paralichthys dentatus), and thorny skate (Amblyraja radiata).Biology, 8(3), 56, \ndoi:10.3390/biology8030056.Sciandra, A., et\u00a0 al., 2003: Response of coccolithophorid Emiliania huxleyi to \nelevated partial pressure of CO 2 under nitrogen limitation.Mar.Ecol.Prog.Ser., 261, 111\u2013122, doi:10.3354/meps261111.Scobie, M., 2018: Accountability in climate change governance and Caribbean \nSIDS.Environ.Dev.Sustain., 20(2), 769\u2013787, doi:10.1007/s10668-017-9909-\n9.Scobie, M., 2019a: Climate change, human rights, and migration.In: Emerging \nThreats to Human Rights: Resources, Violence, and Deprivation of Citizenship\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the book that discusses the ecology of sandy shores?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide the title of a book that discusses the ecology of sandy shores."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: A., et\u00a0 al., 2003: Response of coccolithophorid Emiliania huxleyi to \nelevated partial pressure of CO 2 under nitrogen limitation.Mar.Ecol.Prog.Ser., 261, 111\u2013122, doi:10.3354/meps261111.Scobie, M., 2018: Accountability in climate change governance and Caribbean \nSIDS.Environ.Dev.Sustain., 20(2), 769\u2013787, doi:10.1007/s10668-017-9909-\n9.Scobie, M., 2019a: Climate change, human rights, and migration.In: Emerging \nThreats to Human Rights: Resources, Violence, and Deprivation of Citizenship \n[Smith-Cannoy, H.(ed.)].Temple University Press, Philadelphia, USA.Scobie, M., 2019b: Global marine and ocean governance, and Caribbean SIDS.In: Global Environmental Governance and Small States: Architectures and \nAgency in the Caribbean.Edward Elgar Publishing, Cheltenham, UK, pp.90\u2013117.ISBN 978-1786437266.Scott, F ., et\u00a0 al., 2020: Hydro-morphological characterization of coral \nreefs for wave runup prediction.Front.Mar.Sci., 7, 361, doi:10.3389/\nfmars.2020.00361.Scott, M. E., et\u00a0al., 2019: Latitudinal and seasonal variation in space use by a \nlarge, predatory reef fish, Plectropomus leopardus.Funct.Ecol., 33(4), 670\u2013\n680, doi:10.1111/1365-2435.13271.Seabra, R., et\u00a0 al., 2019: Reduced nearshore warming associated with \neastern boundary upwelling systems.Front.Mar.Sci., 6, 104, doi:10.3389/\nfmars.2019.00104.Secretariat of the Convention on Biological Diversity, 2009: Connecting \nBiodiversity and Climate Change Mitigation and Adaptation: Report of the \nSecond Ad Hoc Technical Expert Group on Biodiversity and Climate Change.Technical Series No.\nQuery: What is the title of the book that discusses the ecology of sandy shores?\nOriginal Answer: The context does not provide the title of a book that discusses the ecology of sandy shores.\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide the title of a book that discusses the ecology of sandy shores."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 532\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nSustain., 7, 52\u201358, doi:10.1016/j.cosust.2013.11.020.Papageorgiou, M., 2016: Coastal and marine tourism: a challenging factor in \nmarine spatial planning.Ocean Coast.Manag., 129, 44\u201348, doi:10.1016/j.ocecoaman.2016.05.006.Pardo, J.C.F .and T.M.Costa, 2021: Multiple-stressor effects of warming and \nacidification on the embryonic development of an estuarine fiddler crab.Estuar.Coast.Shelf Sci., 254, 107296, doi:10.1016/j.ecss.2021.107296.Parker, L.M., et\u00a0al., 2017: Adult exposure to ocean acidification is maladaptive \nfor larvae of the Sydney rock oyster Saccostrea glomerata in the presence of \nmultiple stressors.Biol.Lett., 13(2), 20160798, doi:10.1098/rsbl.2016.0798.Parker, L.M., et\u00a0al., 2012: Adult exposure influences offspring response to ocean \nacidification in oysters.Glob.Change Biol., 18(1), 82\u201392, doi:10.1111/\nj.1365-2486.2011.02520.x.Parker, V.T.and K.E.Boyer, 2019: Sea-level rise and climate change impacts on an \nurbanized Pacific coast estuary.Wetlands, 39(6), 1219\u20131232, doi:10.1007/\ns13157-017-0980-7.Parmesan, C., et\u00a0al., 2013: Beyond climate change attribution in conservation \nand ecological research.Ecol.Lett., 16(s1), 58\u201371, doi:10.1111/ele.12098.Parreira, F ., et\u00a0al., 2021: Biodiversity consequences of Caulerpa prolifera takeover \nof a coastal lagoon.Estuar.Coast.Shelf Sci., 255, 107344, doi:10.1016/j.ecss.2021.107344.Parsons, D.M., et\u00a0al., 2020: An uncertain future: effects of ocean acidification \nand elevated temperature on a New Zealand snapper (Chrysophrys \nauratus) population.Mar.Environ.Res., 161, 105089, doi:10.1016/j.marenvres.2020.105089.Parsons, M., C. Brown, J. Nalau and K. Fisher, 2018: Assessing adaptive capacity \nand adaptation: insights from Samoan tourism operators.Clim.Dev., 10(7), \n644\u2013663, doi:10.1080/17565529.2017.1410082.Parsons, M. and J. Nalau, 2019: Adaptation policy and planning in Pacific \nsmall island developing states.In: Research Handbook on Climate Change \nAdaptation Policy.Edward Elgar Publishing, Cheltenham, UK.ISBN 978-\n1786432513.Pathak, S., 2020: Marine bioprospecting: bioactive compounds from Cnidarians \nand Molluscs \u2013 a review.In: Proceedings of the National Conference on \nInnovations in Biological Sciences (NCIBS).Saurashtra University, Gujarat, \nIndia, doi:10.2139/ssrn.3567752.Patr\u00edcio, A.R., et\u00a0al., 2019: Climate change resilience of a globally important sea \nturtle nesting population.Glob.Change Biol., 25(2), 522\u2013535, doi:10.1111/\ngcb.14520.Patton, A.K., et\u00a0al., 2019: Finding eulachon: the use and cultural importance of \nThaleichthys pacificus on the northern Northwest Coast of North America.J. \nArchaeol.Sci.Rep., 23, 687\u2013699, doi:10.1016/j.jasrep.2018.11.033.\n\npage_label: 506\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nStige, 2021: Associations between \ntiming and magnitude of spring blooms and zooplankton dynamics in the \nsouthwestern Barents Sea.Mar.Ecol.Prog.Ser., 668, 57\u201372, doi:10.3354/\nmeps13740.Donner, S.D., 2009: Coping with commitment: projected thermal stress on coral \nreefs under different future scenarios.PLoS ONE, 4(6), e5712, doi:10.1371/\njournal.pone.0005712.Donner, S.D.and J. Carilli, 2019: Resilience of Central Pacific reefs subject \nto frequent heat stress and human disturbance.Sci.Rep., 9(1), 3484, \ndoi:10.1038/s41598-019-40150-3.Donner, S.D., M. Kandlikar and S. Webber, 2016: Measuring and tracking the \nflow of climate change adaptation aid to the developing world.Environ.Res.Lett., 11(5), 054006, doi:10.1088/1748-9326/11/5/054006.Donner, S.D., G.J.Rickbeil and S.F .Heron, 2017: A new, high-resolution global \nmass coral bleaching database.PLoS ONE, 12(4), e175490, doi:10.1371/\njournal.pone.0175490.Donohoe, H.M. and R.D.Needham, 2006: Ecotourism: the evolving contemporary \ndefinition.J.Ecotour., 5(3), 192\u2013210, doi:10.2167/joe152.0.Doo, S.S., et\u00a0 al., 2020: The challenges of detecting and attributing ocean \nacidification impacts on marine ecosystems.ICES J. Mar.Sci., 77(7\u20138), 2411\u2013\n2422, doi:10.1093/icesjms/fsaa094.Doughty, C.L., K.C.Cavanaugh, R.F .Ambrose and E.D.Stein, 2019: Evaluating \nregional resiliency of coastal wetlands to sea level rise through hypsometry-\nbased modeling.Glob.Change Biol., 25(1), 78\u201392, doi:10.1111/gcb.14429.Douglass, J.G., R.H. Chamberlain, Y .Wan and P .H.Doering, 2020: Submerged \nvegetation responses to climate variation and altered hydrology in a \nsubtropical estuary: interpreting 33\u00a0years of change.Estuaries Coasts, 43(6), \n1406\u20131424, doi:10.1007/s12237-020-00721-4.Dowd, W.W., F .A.King and M.W.Denny, 2015: Thermal variation, thermal \nextremes and the physiological performance of individuals.J. Exp.Biol., \n218(12), 1956\u20131967, doi:10.1242/jeb.114926.Drakou,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on an article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: J.G., R.H. Chamberlain, Y .Wan and P .H.Doering, 2020: Submerged \nvegetation responses to climate variation and altered hydrology in a \nsubtropical estuary: interpreting 33\u00a0years of change.Estuaries Coasts, 43(6), \n1406\u20131424, doi:10.1007/s12237-020-00721-4.Dowd, W.W., F .A.King and M.W.Denny, 2015: Thermal variation, thermal \nextremes and the physiological performance of individuals.J. Exp.Biol., \n218(12), 1956\u20131967, doi:10.1242/jeb.114926.Drakou, E. G., J. Virdin and L. Pendleton, 2018: Mapping the global distribution \nof locally-generated marine ecosystem services: the case of the West \nand Central Pacific Ocean tuna fisheries.Ecosyst.Serv., 31, 278\u2013288, \ndoi:10.1016/j.ecoser.2018.05.008.du Pontavice, H., et\u00a0al., 2020: Climate change undermines the global functioning \nof marine food webs.Glob.Change Biol., 26(3), 1306\u20131318, doi:10.1111/\ngcb.14944.Duarte, B., et\u00a0 al., 2018: Climate change impacts on seagrass meadows and \nmacroalgal forests: an integrative perspective on acclimation and adaptation \npotential.Front.Mar.Sci., 5, 190, doi:10.3389/fmars.2018.00190.Duarte, C.M., et\u00a0al., 2020: Rebuilding marine life.Nature, 580(7801), 39\u201351, \ndoi:10.1038/s41586-020-2146-7.Duarte, C.M., et\u00a0al., 2021: The soundscape of the Anthropocene ocean.\nQuery: What is the title of the article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper?\nOriginal Answer: The context does not provide information on an article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper.\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide information on an article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 501\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nCavanagh, R.D., et\u00a0al., 2021: Future risk for Southern Ocean ecosystem services \nunder climate change.Front.Mar.Sci., 7(1224), 615214, doi:10.3389/\nfmars.2020.615214.Caves, E.M. and S. Johnsen, 2021: The sensory impacts of climate change: \nbathymetric shifts and visually mediated interactions in aquatic species.Proc.R. Soc.B, 288(1949), 20210396, doi:10.1098/rspb.2021.0396.Cavicchioli, R., et\u00a0al., 2019: Scientists\u2019 warning to humanity: microorganisms \nand climate change.Nat.Rev.Microbiol., 17(9), 569\u2013586, doi:10.1038/\ns41579-019-0222-5.CBD, 2009: Scientific Synthesis of the Impacts of Ocean Acidification on Marine \nBiodiversity.Secretariat of the Convention on Biological Diversity (CBD) \nTechnical Series No.46.CBD, Montreal, Canada.61 pp.CBD, 2020: Zero Draft of the Post-2020 Global Biodiversity Framework.Open-\nEnded Working Group on the Post-2020 Global Biodiversity Framework, \nKunming, China, Accessed 24th December 2021, https://www.cbd.int/\narticle/2020-01-10-19-02-38.Cerrano, C., et\u00a0 al., 2013: Red coral extinction risk enhanced by ocean \nacidification.Sci.Rep., 3, 1457, doi:10.1038/srep01457.Chambault, P ., et\u00a0al., 2020: The impact of rising sea temperatures on an Arctic \ntop predator, the narwhal.Sci.Rep., 10(1), 18678, doi:10.1038/s41598-020-\n75658-6.Chambers, L.E., P .Dann, B. Cannell and E.J.Woehler, 2014: Climate as a driver \nof phenological change in southern seabirds.Int.J.Biometeorol., 58(4), 603\u2013\n612, doi:10.1007/s00484-013-0711-6.Chami, R., T. Cosimano, C. Fullenkamp and S. Oztosun, 2019: Nature\u2019s Solution \nto Climate Change.Finance and Development, 56(4), 34\u201338.Champion, C., S. Brodie and M. A. Coleman, 2021: Climate-driven range shifts \nare rapid yet variable among recreationally important coastal-pelagic fishes.Front.Mar.Sci., 8(156), 622299, doi:10.3389/fmars.2021.622299.Champion, C., A.J.Hobday, S.R.Tracey and G.T.Pecl, 2018: Rapid shifts in \ndistribution and high-latitude persistence of oceanographic habitat revealed \nusing citizen science data from a climate change hotspot.Glob.Change Biol., \n24(11), 5440\u20135453, doi:10.1111/gcb.14398.Chan, F .T., et\u00a0al., 2019: Climate change opens new frontiers for marine species \nin the Arctic: current trends and future invasion risks.Glob.Change Biol., \n25(1), 25\u201338, doi:10.1111/gcb.14469.Chan, H.M., et\u00a0 al., 2021: Levels of metals and persistent organic pollutants \nin traditional foods consumed by First Nations living on-reserve in Canada.Can.J.Public Health, 112(1), 81\u201396, doi:10.17269/s41997-021-00495-7.Chan, K.Y .K., D. Gr\u00fcnbaum, M. Arnberg and S. Dupont, 2016: Impacts of ocean \nacidification on survival, growth, and swimming behaviours differ between \nlarval urchins and brittlestars.ICES J. Mar.Sci., 73(3), 951\u2013961, doi:10.1093/\nicesjms/fsv073.Chapman, C.C., et\u00a0al., 2020: Defining Southern Ocean fronts and their influence \non biological and physical processes in a changing climate.Nat.Clim.\n\npage_label: 503\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n503Oceans and Coastal Ecosystems and Their Services Chapter 3\nClaudet, J., et\u00a0al., 2020a: A Roadmap for using the UN decade of ocean science \nfor sustainable development in support of science, policy, and action.One \nEarth, 2(1), 34\u201342, doi:10.1016/j.oneear.2019.10.012.Claudet, J., C. Loiseau, M. Sostres and M. Zupan, 2020b: Underprotected marine \nprotected areas in a global biodiversity hotspot.One Earth, 2(4), 380\u2013384, \ndoi:10.1016/j.oneear.2020.03.008.Clay, P .M., et\u00a0al., 2020: Ocean and coastal indicators: understanding and coping \nwith climate change at the land-sea interface.Clim.Change, 163(4), 1773\u2013\n1793, doi:10.1007/s10584-020-02940-x.Clements, J.C. and H.L.Hunt, 2015: Marine animal behaviour in a high CO 2 \nocean.Mar.Ecol.Prog.Ser., 536, 259\u2013279, doi:10.3354/meps11426.Cockerell, B., et\u00a0al., 2020: Representation does not necessarily reduce threats \nto biodiversity: Australia\u2019s Commonwealth marine protected area system, \n2012\u20132018.Biol.Conserv., 252, 108813, doi:10.1016/j.biocon.2020.108813.Cohen, M.C.L., et\u00a0al., 2020: Impacts of Holocene and modern sea-level changes \non estuarine mangroves from northeastern Brazil.Earth Surf.Process.Landforms, 45(2), 375\u2013392, doi:10.1002/esp.4737.Cohen, P .J., et\u00a0al., 2019: Securing a Just space for small-scale fisheries in the \nblue economy.Front.Mar.Sci., 6, 171, doi:10.3389/fmars.2019.00171.Cohen, R.E., et\u00a0 al., 2018: Marine host-pathogen dynamics: influences of \nglobal climate change.Oceanography, 31(2), 182\u2013193, doi:10.5670/\noceanog.2018.201.Cohen-Shacham, E., et\u00a0al., 2019: Core principles for successfully implementing \nand upscaling nature-based solutions.Environ.Sci.Policy, 98, 20\u201329, \ndoi:10.1016/j.envsci.2019.04.014.Coldren, G.A., J.A.Langley, I.C.Feller and S.K.Chapman, 2019: Warming \naccelerates mangrove expansion and surface elevation gain in a subtropical \nwetland.J.Ecol.,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the report on climate change and the oceans?\nAnswer: "}, {"role": "assistant", "content": "The title of the report on climate change and the oceans is not specified in the provided context."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: host-pathogen dynamics: influences of \nglobal climate change.Oceanography, 31(2), 182\u2013193, doi:10.5670/\noceanog.2018.201.Cohen-Shacham, E., et\u00a0al., 2019: Core principles for successfully implementing \nand upscaling nature-based solutions.Environ.Sci.Policy, 98, 20\u201329, \ndoi:10.1016/j.envsci.2019.04.014.Coldren, G.A., J.A.Langley, I.C.Feller and S.K.Chapman, 2019: Warming \naccelerates mangrove expansion and surface elevation gain in a subtropical \nwetland.J.Ecol., 107(1), 79\u201390, doi:10.1111/1365-2745.13049.Cole, V.J., et\u00a0 al., 2016: Effects of multiple climate change stressors: ocean \nacidification interacts with warming, hyposalinity, and low food supply on \nthe larvae of the brooding flat oyster Ostrea angasi.Mar.Biol., 163(5), 125, \ndoi:10.1007/s00227-016-2880-4.Coleman, M. A. and H.D.Goold, 2019: Harnessing synthetic biology for kelp \nforest conservation.J.Phycol., 55(4), 745\u2013751, doi:10.1111/jpy.12888.Coleman, M. A., A.J.P .Minne, S. Vranken and T. Wernberg, 2020a: Genetic \ntropicalisation following a marine heatwave.Sci.Rep., 10(1), 12726, \ndoi:10.1038/s41598-020-69665-w.\nColeman, M. A., et\u00a0 al., 2020b: Restore or redefine: future trajectories for \nrestoration.Front.Mar.Sci., 7, 237, doi:10.3389/fmars.2020.00237.Collins, M., et\u00a0al., 2019a: Extremes, Abrupt Changes and Managing Risks.In: \nIPCC Special Report on the Ocean and Cryosphere in a Changing Climate.\nQuery: What is the title of the report on climate change and the oceans?\nOriginal Answer: The title of the report on climate change and the oceans is not specified in the provided context.\nNew Answer: "}, {"role": "assistant", "content": "The title of the report on climate change and the oceans is not specified in the provided context."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 388\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n388Chapter 3 Oceans and Coastal Ecosystems and Their Services\nUsing peer-reviewed research spanning the full range of scientific approaches (paleorecords, observations, \nexperiments and models), we can assess the level of confidence in the impact of climate change on observed \nmodifications in marine ecosystems. We refer to this as multiple lines of evidence, meaning that the evidence comes \nfrom the diverse approaches described above. This allows policymakers and managers to address the specific actions \nneeded to reduce climate change and other impacts.\nCoral reefsImpacts\nCoral\nBleaching\nLimited MediumEvidence availability\nRobustMangroves\nBeaches\nFisheries\nMangrove\ndiebackExamples of well-known impacts of anthropogenic climate change\nPaleorecor d Observations ExperimentsEvidence of impactsExamples of\nnature-based adaptation\nsolutions\nRestoration and \nconservation\nRestoration and \nconservation\nRecovery of sand dunes\nEcosystem-based\nmanagement\nBeach\nerosion\nSpecies shifts\nModel\nFigure\u00a0FAQ3.1.1 | \u00a0Examples of well-known impacts of anthropogenic climate change and associated nature-based adaptation. To attribute changes \nin marine ecosystems to anthropogenic climate change, scientists use multiple lines of evidence including paleorecords, contemporary observations, manipulation \nexperiments and models.Box FAQ 3.1 (continued)\n\npage_label: 469\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n469Oceans and Coastal Ecosystems and Their Services Chapter 3\nFrequently Asked Questions\nFAQ 3.4 | Which industries and jobs are most vulnerable to the impacts of climate change in the oceans?The global ocean underpins human well-being through the provision of resources that directly and indirectly feed and employ many millions \nof people.In many regions, climate change is degrading ocean health and altering stocks of marine resources.Together with over-harvesting, \nclimate change is threatening the future of the sustenance provided to Indigenous Peoples, the livelihoods of artisanal fisheries, and \nmarine-based industries including tourism, shipping and transportation.The ocean is the lifeblood of the planet.In addition to regulating planetary cycles of carbon, water and heat, \nthe ocean and its vast resources support human livelihoods, cultural practices, jobs and industries.The impacts \nof climate change on the ocean can influence human activities and employment by altering resource availability, \nspreading pathogens, flooding shorelines and degrading ocean ecosystems.Fishing and mariculture are highly \nexposed to change.The global ocean and inland waters together provide more than 3.3\u00a0billion people at least \n20% of the protein they eat and provide livelihoods for 60\u00a0million people.Changes in the nutritional quality or \nabundance of food from the oceans could influence billions of people.Substantial economic losses for fisheries resulting from recent climate-driven harmful algal blooms and marine \npathogen outbreaks have been recorded in Asia, North America and South America.A 2016 event in Chile caused \nan estimated loss of 800\u00a0million USD in the farmed-salmon industry and led to regional government protests.The \nrecent closure of the Dungeness crab and razor clam fishery in the USA due to a climate-driven algal bloom harmed \n84% of surveyed residents from 16 California coastal communities.Fishers and service industries that support \ncommercial and recreational fishing experienced the most substantial economic losses, and fishers were the least \nable to recover their losses.This same event also disrupted subsistence and recreational fishing for razor clams, \nimportant activities for Indigenous Peoples and local communities in the Pacific Northwest of the USA.Other goods from the ocean, including non-food products like dietary supplements, food preservatives, pharmaceuticals, \nbiofuels, sponges and cosmetic products, as well as luxury products like jewellery coral, cultured pearls and aquarium \nspecies, will change in abundance or quality due to climate change.For instance, ocean warming is endangering the \n\u2018candlefish\u2019 ooligan (Thaleichthys pacificus), whose oil is a traditional food source and medicine of Indigenous Peoples \nof the Pacific Northwest of North America.Declines in tourism and real estate values, associated with climate-driven \nharmful algal blooms, have also been recorded in the USA, France and England.Small-scale fisheries livelihoods and jobs are the most vulnerable to climate-driven changes in marine resources and \necosystem services.The abundance and composition of their harvest depend on suitable environmental conditions and \non IKLK developed over generations.Large-scale fisheries, though still vulnerable, are more able to adapt to climate \nchange due to greater mobility and greater resources for changing technologies.These fisheries are already adapting \nby broadening catch diversity, increasing their mobility to follow shifting species, and changing gear, technology and \nstrategies.Adaptation in large-scale fisheries, however, is at times constrained by regulations and governance challenges.Jobs, industries and livelihoods which depend on particular species or are tied to the coast can also be at risk from \nclimate change.Species-dependent livelihoods (e.g., a lobster fishery or oyster farm) are vulnerable due to a lack \nof substitutes if the fished species are declining, biodiversity is reduced, or mariculture is threatened by climate \nchange or ocean acidification.Coastal activities and industries ranging from fishing (e.g., gleaning on a tidal flat) \nto tourism to shipping and transportation are also vulnerable to sea level rise and other climate-change impacts on \nthe coastal environment.The ability of coastal systems to protect the shoreline will decline due to sea level rise and \nsimultaneous degradation of nearshore systems, including coral reefs, kelp forests and coastal wetlands.The vulnerability of communities to losses in marine ecosystem services varies within and among communities.Tourists seeking to replace lost cultural services can adapt by engaging in the activity elsewhere.But communities \nwho depend on tourism for income or who have strong cultural identity linked to the ocean have a more \ndifficult time.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are some of the impacts of anthropogenic climate change on ocean and coastal ecosystems, according to the provided context?\nAnswer: "}, {"role": "assistant", "content": "Anthropogenic climate change has several impacts on ocean and coastal ecosystems. It is degrading ocean health and altering stocks of marine resources, which in turn threatens the sustenance provided to Indigenous Peoples, the livelihoods of artisanal fisheries, and marine-based industries including tourism, shipping and transportation. Climate change can influence human activities and employment by altering resource availability, spreading pathogens, flooding shorelines and degrading ocean ecosystems. Fishing and mariculture are highly exposed to these changes. Climate-driven harmful algal blooms and marine pathogen outbreaks have led to substantial economic losses for fisheries. Non-food products from the ocean, like dietary supplements, food preservatives, pharmaceuticals, biofuels, sponges and cosmetic products, as well as luxury products, will change in abundance or quality due to climate change. Small-scale fisheries livelihoods and jobs are particularly vulnerable to these climate-driven changes in marine resources and ecosystem services. Species-dependent livelihoods and coastal activities and industries are also at risk due to climate change impacts. The ability of coastal systems to protect the shoreline will decline due to sea level rise and simultaneous degradation of nearshore systems, including coral reefs, kelp forests and coastal wetlands."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 417\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n417Oceans and Coastal Ecosystems and Their Services Chapter 3\nsystems, currently most advanced for coral reefs, can help people and industries prepare for MHWs and also collect \ndata on their effects. Identifying and protecting locations and habitats with reduced exposure to MHWs is a key \nscientific endeavour. For example, corals may be protected from MHWs in tidally stirred waters or in reefs where \ncooler water upwells from subsurface. Marine protected areas and no-take zones, in addition to terrestrial protection \nsurrounding vulnerable coastal ecosystems, cannot prevent MHWs from occurring. But, depending on the location \nand adherence by people to restrictions on certain activities, the cumulative effect of other stressors on vulnerable \necosystems can be reduced, potentially helping to enhance the rate of recovery of marine life.\nAnomalous atmospheric pattern\nReduced cooling by atmosphere\nReduced cold water advection\nAssociation with El Ni\u00f1o'Blob' causesHow are marine heatwaves affecting marine life and human communities?\nEcological impacts Cascading effects Socioeconomic \nimpacts\nSpecies shift\nDecrease of original inhabitants\nNew species invasions\nHarmful algae blooms\nPrey plankton decreaseEcosystem structure change\nNew species interactions\nFood limitation to megafauna\nand seabirds\nMass mortality eventsFishing closures and delays\nWhale entanglements in fishing \ngear\nSubstitution of fisheries\nProhibition of aquaculture \nproducts\nFood security issues\n54%Due to climate change, ocean heatwave days have increased by \n54% over the past centur y. Marine heatwaves cause mass mortalities \nin a wide variety of marine species.\nNeeds for seasonal prediction | real-time monitoring | real-time predictio nNeeds for real-time monitoring | monitoring responseNeeds for education | adaptation\nFigure\u00a0FAQ3.2.1 | \u00a0Impact pathway of a massive extreme marine heatwave, the northwest Pacific \u2018Blob\u2019, from causal mechanisms to initial effects, \nresulting nonlinear effects and the consequent impacts for humans. Lessons learnt from the Blob include the need to advance seasonal forecasts, real-time \npredictions, monitoring responses, education, possible fisheries impacts and adaptation.Box FAQ 3.2 (continued)\n\npage_label: 416\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n416Chapter 3 Oceans and Coastal Ecosystems and Their Services\nFrequently Asked Questions\nFAQ 3.2 | How are marine heatwaves affecting marine life and human communities?Heatwaves happen in the ocean as well as in the atmosphere.Marine heatwaves (MHWs) are extended periods of unusually warm ocean \ntemperatures relative to the typical temperatures for that location and time of\u00a0year.Due to climate change, the number of days with MHWs has \nincreased by 54% over the past century.These MHWs cause mortalities in a wide variety of marine species, from corals to kelp to seagrasses \nto fish to seabirds, and have consequent effects on ecosystems and industries like aquaculture and fisheries.Extreme events in the ocean can have damaging effects on marine ecosystems and the human communities that \ndepend on them.The most common form of ocean extremes are MHWs, which are becoming more frequent and \nintense due to global warming.Because seawater absorbs and releases heat more slowly than air, temperature \nextremes in the ocean are not as pronounced as over land, but they can persist for much longer, often for weeks \nto months over areas covering hundreds of thousands of square kilometres.These MHWs can be more detrimental \nfor marine species, in comparison with land species, because marine species are usually adapted to relatively stable \ntemperatures.A commonly used definition of MHWs is a period of at least 5\u00a0days whose temperatures are warmer than 90% \nof the historical records for that location and time of\u00a0year.Marine heatwaves are described by their abruptness, \nmagnitude, duration, intensity and other metrics.In addition, targeted methods are used to characterize MHWs \nthat threaten particular ecosystems; for example, the accumulated heat stress above typical summer temperatures, \ndescribed by \u2018degree heating weeks\u2019, is used to estimate the likelihood of coral bleaching.Over the past century, MHWs have doubled in frequency, become more intense, lasted for longer and extended \nover larger areas.Marine heatwaves have occurred in every ocean region over the past few decades, most markedly \nin association with regional climate phenomena such as the El Ni\u00f1o/Southern Oscillation.During the 2015\u20132016 El \nNi\u00f1o event, 70% of the world\u2019s ocean surface encountered MHWs.Such MHWs cause mortality of a wide variety of marine species, from corals to kelp to seagrasses to fish to seabirds, \nand they have consequent effects on ecosystems and industries such as mariculture and fisheries.Warm-water coral \nreefs, estuarine seagrass meadows and cold-temperate kelp forests are among the ecosystems most threatened by \nMHWs since they are attached to the seafloor (see FAQ 3.2).Unusually warm temperatures cause bleaching and \nassociated death of warm-water corals, which can lead to shifts to low-diversity or algae-dominated reefs, changes \nin fish communities and deterioration of the physical reef structure, which causes habitat loss and increases the \nvulnerability of nearby shorelines to large-wave events and SLR.Since the early 1980s, the frequency and severity \nof mass coral bleaching events have increased sharply worldwide.For example, from 2016 through 2020, the Great \nBarrier Reef experienced mass coral bleaching three times in 5\u00a0years.Mass loss of kelp from MHWs effects on the canopy-forming species has occurred across ocean basins, including \nthe coasts of Japan, Canada, Mexico, Australia and New Zealand.In southern Norway and the northeast USA, \nmortality from MHWs contributed to the decline of sugar kelp over the past two decades and the spread of turf \nalgal ecosystems that prevent recolonisation by the original canopy-forming species.One of the largest and longest-duration MHWs, nicknamed the \u2018Blob\u2019, occurred in the Northeast Pacific Ocean, \nextending from California north towards the Bering Sea, from 2013 through 2015.Warming from the MHW persisted \ninto 2016 off the West Coast of the USA and into 2018 in the deeper waters of a Canadian fjord.The consequent \neffects of this expansive MHW included widespread shifts in abundance, distribution and nutritional value of \ninvertebrates and fish, a bloom of toxic algae off the West Coast of the USA that impacted fisheries, the decline of \nCalifornia kelp forests that contributed to the collapse of the abalone fishery, and mass mortality of seabirds.The projected increase in the frequency, severity, duration and areal extent of MHWs threaten many marine species \nand ecosystems.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the impacts of marine heatwaves on species and ecosystems, according to the provided context?\nAnswer: "}, {"role": "assistant", "content": "Marine heatwaves (MHWs) have a significant impact on a wide variety of marine species and ecosystems. They cause mortalities in species ranging from corals to kelp, seagrasses, fish, and seabirds. These events can lead to shifts in species populations, with original inhabitants decreasing and new species invading. They can also cause harmful algae blooms and changes in the ecosystem structure. \n\nFor example, unusually warm temperatures can cause bleaching and associated death of warm-water corals, leading to shifts to low-diversity or algae-dominated reefs, changes in fish communities, and deterioration of the physical reef structure. This causes habitat loss and increases the vulnerability of nearby shorelines to large-wave events. \n\nMHWs have also contributed to the mass loss of kelp across various ocean basins, including the coasts of Japan, Canada, Mexico, Australia, and New Zealand. In southern Norway and the northeast USA, mortality from MHWs contributed to the decline of sugar kelp over the past two decades and the spread of turf algal ecosystems that prevent recolonisation by the original canopy-forming species. \n\nOne of the largest and longest-duration MHWs, nicknamed the \u2018Blob\u2019, resulted in widespread shifts in abundance, distribution, and nutritional value of invertebrates and fish, a bloom of toxic algae off the West Coast of the USA that impacted fisheries, the decline of California kelp forests that contributed to the collapse of the abalone fishery, and mass mortality of seabirds. \n\nThe projected increase in the frequency, severity, duration, and areal extent of MHWs threatens many marine species and ecosystems."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 522\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBiogeosciences, \n14(19), 4545\u20134561, doi:10.5194/bg-14-4545-2017.Last, P .R., et\u00a0 al., 2011: Long-term shifts in abundance and distribution of a \ntemperate fish fauna: a response to climate change and fishing practices.Glob.Ecol.Biogeogr., 20(1), 58\u201372, doi:10.1111/j.1466-8238.2010.00575.x.Lasut, M.T., et\u00a0 al.(ed.), 2018: From Coral Triangle to Trash Triangle\u2014How \nthe Hot spot of Global Marine Biodiversity Is Threatened by Plastic Waste.Proceedings of the International Conference on Microplastic Pollution in the \nMediterranean Sea.Springer International Publishing, Cham, 107\u2013113.ISBN \n978-3319712796.Lau, J.D., C.C.Hicks, G.G.Gurney and J.E.Cinner, 2019: What matters to whom \nand why?Understanding the importance of coastal ecosystem services in \ndeveloping coastal communities.Ecosyst.Serv., 35, 219\u2013230, doi:10.1016/j.ecoser.2018.12.012.Laubenstein, T.D., M.D.Jarrold, J.L.Rummer and P .L.Munday, 2020: Beneficial \neffects of diel CO 2 cycles on reef fish metabolic performance are diminished \nunder elevated temperature.Sci.Total Environ., 735, 139084, doi:10.1016/j.scitotenv.2020.139084.Laubenstein, T.D., J.L.Rummer, M.I.McCormick and P .L.Munday, 2019: A \nnegative correlation between behavioural and physiological performance under ocean acidification and warming.Sci.Rep., 9(1), 4265, doi:10.1038/\ns41598-018-36747-9.Laubenstein, T.D., et\u00a0 al., 2018: Correlated effects of ocean acidification and \nwarming on behavioral and metabolic traits of a large pelagic fish.Diversity, \n10(2), 35, doi:10.3390/D10020035.Lauchlan, S.S. and I. Nagelkerken, 2020: Species range shifts along multistressor \nmosaics in estuarine environments under future climate.Fish Fish., 21(1), \n32\u201346, doi:10.1111/faf.12412.Laufk\u00f6tter, C., et\u00a0al., 2015: Drivers and uncertainties of future global marine \nprimary production in marine ecosystem models.Biogeosciences, 12(23), \n6955\u20136984, doi:10.5194/bg-12-6955-2015.Laufk\u00f6tter, C., J. Zscheischler and T.L.Fr\u00f6licher, 2020: High-impact marine \nheatwaves attributable to human-induced global warming.Science, \n369(6511), 1621\u20131625, doi:10.1126/science.aba0690.Laurel, B.J., et\u00a0 al., 2021: Regional warming exacerbates match/mismatch \nvulnerability for cod larvae in Alaska.Prog.Oceanogr., 193, 102555, \ndoi:10.1016/j.pocean.2021.102555.Laurent, A., et\u00a0al., 2017: Eutrophication-induced acidification of coastal waters \nin the northern Gulf of Mexico: insights into origin and processes from a \ncoupled physical-biogeochemical model.Geophys.Res.Lett., 44(2), 946\u2013\n956, doi:10.1002/2016GL071881.Lavidas, G., 2019: Energy and socio-economic benefits from the development \nof wave energy in Greece.Renew.Energy, 132, 1290\u20131300, doi:10.1016/j.renene.2018.09.007.Lavidas, G. and V. Venugopal, 2016: Prospects and applicability of wave energy \nfor South Africa.Int.J.Sustain.Energy, 37(3), 230\u2013248, doi:10.1080/14786\n451.2016.1254216.\n\npage_label: 541\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n541Oceans and Coastal Ecosystems and Their Services Chapter 3\nSmith, K.L., et\u00a0al., 2018: Episodic organic carbon fluxes from surface ocean to \nabyssal depths during long-term monitoring in NE Pacific.Proc.Natl.Acad.Sci.U.S.A., 115(48), 12235\u201312240, doi:10.1073/pnas.1814559115.Smith, S.M., et\u00a0al., 2021: Tropicalization and kelp loss shift trophic composition \nand lead to more winners than losers in fish communities.Glob.Change \nBiol., 27(11), 2537\u20132548, doi:10.1111/gcb.15592.Smith, T.B., et\u00a0al., 2014: A depth refugium from catastrophic coral bleaching \nprevents regional extinction.Ecology, 95(6), 1663\u20131673, doi:10.1890/13-\n0468.1.Snelgrove, P .V.R., et\u00a0 al., 2018: Global carbon cycling on a heterogeneous \nseafloor.Trends Ecol.Evol., 33(2), 96\u2013105, doi:10.1016/j.tree.2017.11.004.Soares, M.B., M. Daly and S. Dessai, 2018: Assessing the value of seasonal \nclimate forecasts for decision-making.Wiley Interdiscip.Rev.Clim.Change, \n9(4), e523, doi:10.1002/wcc.523.Solaun, K. and E. Cerd\u00e1, 2019: Climate change impacts on renewable energy \ngeneration.A review of quantitative projections.Renew.Sustain.Energy \nRev., 116, 109415, doi:10.1016/j.rser.2019.109415.Song, G., et\u00a0 al., 2020a: Summertime oxygen depletion and acidification in \nBohai Sea, China.Front.Mar.Sci., 7, 252, doi:10.3389/fmars.2020.00252.Song, H., et\u00a0al., 2020b: Flat latitudinal diversity gradient caused by the Permian\u2013\nTriassic mass extinction.Proc.Natl.Acad.Sci.U.S.A., 117(30), 17578\u201317583, \ndoi:10.1073/pnas.1918953117.Song, H., et\u00a0al., 2021a: Strong and regionally distinct links between ice-retreat \ntiming and phytoplankton production in the Arctic Ocean.Limnol.Oceanogr., \n66(6), 2498\u20132508, doi:10.1002/lno.11768.Song, H., et\u00a0al., 2021b: Thresholds of temperature change for mass\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the paper that discusses the shift in trophic composition and winners and losers in fish communities due to tropicalization and kelp loss?\nAnswer: "}, {"role": "assistant", "content": "The title of the paper that discusses the shift in trophic composition and winners and losers in fish communities due to tropicalization and kelp loss is \"Tropicalization and kelp loss shift trophic composition and lead to more winners than losers in fish communities.\""}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: H., et\u00a0al., 2020b: Flat latitudinal diversity gradient caused by the Permian\u2013\nTriassic mass extinction.Proc.Natl.Acad.Sci.U.S.A., 117(30), 17578\u201317583, \ndoi:10.1073/pnas.1918953117.Song, H., et\u00a0al., 2021a: Strong and regionally distinct links between ice-retreat \ntiming and phytoplankton production in the Arctic Ocean.Limnol.Oceanogr., \n66(6), 2498\u20132508, doi:10.1002/lno.11768.Song, H., et\u00a0al., 2021b: Thresholds of temperature change for mass extinctions.Nat.Commun., 12(1), 4694, doi:10.1038/s41467-021-25019-2.Soper, F .M., et\u00a0 al., 2019: Non-native mangroves support carbon storage, \nsediment carbon burial, and accretion of coastal ecosystems.Glob.Change \nBiol., 25(12), 4315\u20134326, doi:10.1111/gcb.14813.S\u00f8reide, J.E., et\u00a0 al., 2010: Timing of blooms, algal food quality and Calanus \nglacialis reproduction and growth in a changing Arctic.Glob.Change Biol., \n16(11), 3154\u20133163, doi:10.1111/j.1365-2486.2010.02175.x.Sorte, C.J.B., et\u00a0al., 2019: Thermal tolerance limits as indicators of current and \nfuture intertidal zonation patterns in a diverse mussel guild.Mar.Biol., 166, \n6, doi:10.1007/s00227-018-3452-6.Sorte, C.J.B., et\u00a0al., 2017: Long-term declines in an intertidal foundation species \nparallel shifts in community composition.Glob.Change Biol., 23(1), 341\u2013\n352, doi:10.1111/gcb.13425.Sousa, A.I., J.F .da Silva, A. Azevedo and A.I.\nQuery: What is the title of the paper that discusses the shift in trophic composition and winners and losers in fish communities due to tropicalization and kelp loss?\nOriginal Answer: The title of the paper that discusses the shift in trophic composition and winners and losers in fish communities due to tropicalization and kelp loss is \"Tropicalization and kelp loss shift trophic composition and lead to more winners than losers in fish communities.\"\nNew Answer: "}, {"role": "assistant", "content": "The paper discussing the shift in trophic composition and the concept of winners and losers in fish communities due to tropicalization and kelp loss is titled \"Tropicalization and kelp loss shift trophic composition and lead to more winners than losers in fish communities.\""}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 460\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n460Chapter 3 Oceans and Coastal Ecosystems and Their Services\nstrains (Section\u00a05.9.4; Barton et\u00a0al., 2015a).Laboratory studies show \nthat ocean acidification decreases the fitness, growth or survival of \nmany economically and culturally important larval or juvenile shelled \nmollusks (high confidence) (Cao et\u00a0 al., 2018; Onitsuka et\u00a0 al., 2018; \nStevens and Gobler, 2018; Griffith et\u00a0al., 2019a; Mellado et\u00a0al., 2019) \nand of several valuable wild-harvest crab species (Barton et\u00a0al., 2015a; \nPunt et\u00a0al., 2015; Miller et\u00a0al., 2016; Swiney et\u00a0al., 2017; Gravinese \net\u00a0al., 2018; Tomasetti et\u00a0al., 2018; Long et\u00a0al., 2019; Trigg et\u00a0al., 2019).Ocean acidification alters larval settlement and metamorphosis of fish \nin laboratory studies (high confidence) (Cattano et\u00a0al., 2018; Espinel-\nVelasco et\u00a0al., 2018), suggesting possible changes in fish survival and \nthus fishery characteristics.Deoxygenation can decrease size and \nabundance of marine species and suppress trophic interactions (Levin, \n2003), decrease the diversity within marine ecosystems (Sperling et\u00a0al., \n2016) while temporarily increasing catchability and increasing the risk \nof overfishing (Breitburg et\u00a0 al., 2018) and decrease the ecosystem \nservices provided by specific fisheries (Orio et\u00a0al., 2021).The chronic \neffects of deoxygenation on wild fisheries are complex and highly \ninteractive with co-occurring drivers and overall ecosystem responses \n(medium evidence, high agreement) (Townhill et\u00a0al., 2017; Rose et\u00a0al., \n2019).Detecting and attributing marine ecosystem responses to \nocean acidification and deoxygenation outside of laboratory studies \nremains challenging because of the strong influence of co-occurring \nenvironmental changes on natural systems (Section\u00a03.3.5; Rose et\u00a0al., \n2019; Doo et\u00a0al., 2020).Ocean and coastal organisms will continue moving poleward under \nRCP8.5 (high confidence) (Section\u00a03.4.3.1.3; Figure\u00a03.18), and this is \nexpected to decrease fisheries harvests in low latitudes and alter species \ncomposition and abundance in higher latitudes (high confidence) \n(Table\u00a03.26; Figure\u00a03.23; Asch et\u00a0al., 2018; Morley et\u00a0al., 2018; Tai et\u00a0al., \n2019; Erauskin-Extramiana et\u00a0al., 2020; Shelton et\u00a0al., 2021).Species \nthat succeed in new ranges or conditions may offer opportunities to \ndiversify regional fisheries or aquaculture (Sections\u00a0 3.6.3.1.2, 5.8.4, \n5.9.4; Bindoff et\u00a0 al., 2019a), or they may outcompete indigenous \nspecies and act as invasive species (Sections\u00a03.4.2.10, 3.5.2).Temperature will continue to be a major driver of fisheries changes \nglobally, but other non-climate factors like organism physiology and \necosystem response (Section\u00a03.3) and fishing pressure (Chapter\u00a05), as \nwell as other climate-induced drivers like acidification, deoxygenation \nand sea ice loss (Section\u00a03.2), will play critical roles in future global \nand local fisheries changes (high confidence).Warming, acidification \nand business-as-usual fishing policy under RCP8.5 are projected \nto place around 60% of global fisheries at very high risk (medium \nconfidence) (Cheung et\u00a0 al., 2018).Model intercomparison showed \nthat ocean acidification and protection affect ecosystems more than \nfishing pressure, and ecological adaptation will significantly determine \nimpacts on fishery biomass, catch and value until approximately 2050 \n(medium confidence) (Olsen et\u00a0 al., 2018).Ecosystem responses to \nwarming water, fishing pressure, food-web changes, MHWs and sea \nice algal populations have been responsible for highly variable or \ncollapsing populations of Northern Hemisphere high-latitude forage \nfish species including sand lances (Ammodytes spp.\n\npage_label: 431\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n(2021) reports that >80% of sampled sea snail, Limacina helicina, a key \nspecies in pelagic food webs, displayed signs of shell dissolution in the \nAmundsen Gulf.However, bacteria, phytoplankton, zooplankton and \nbenthic communities are found to be detrimentally impacted, resilient \nor even positively influenced by ocean acidification in observational\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context, which study investigated the impact of ocean acidification on herring larvae survival?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on a specific study investigating the impact of ocean acidification on herring larvae survival."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 406\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nAcidification and hypoxia can contribute to a decrease or shift in thermal \ntolerance, while the magnitude of this effect depends on the duration \nof exposure (Tripp-Valdez et\u00a0al., 2017; Cattano et\u00a0al., 2018; Calder\u00f3n-Li\u00e9vanos et\u00a0al., 2019; Schwieterman et\u00a0al., 2019).Warming and hypoxia \nare mostly positively correlated and tolerances to both phenomena \nare often linked after long-term acclimation (e.g., Bouyoucos et\u00a0 al., \n2020).Acute short-term heat shocks can impair hypoxia tolerance, \nfor instance, in intertidal fish (McArley et\u00a0al., 2020).This is relevant \nfor shallow waters, specifically for MHWs (Section\u00a0 3.2.2.1; Hobday \net\u00a0al., 2016a; IPCC, 2018; Collins et\u00a0al., 2019a).Ocean acidification can \nincrease hypoxia tolerance in some cases, possibly by downregulating \nactivity (Faleiro et\u00a0 al., 2015) and/or changing blood oxygenation \n(Montgomery et\u00a0al., 2019).Other studies, however, reported additive \nnegative effects of acidification and warming on hypoxia tolerance \n(Schwieterman et\u00a0al., 2019; G\u00f6tze et\u00a0al., 2020), in line with the oxygen- \nand capacity-limited thermal tolerance (OCLTT) hypothesis presented \nin AR5 (P\u00f6rtner et\u00a0 al., 2014): Warming causes increased metabolic \nrates and oxygen demand in ectotherms, which at some point exceed \nsupply capacities (which also depend on environmental oxygen \navailability) and reduce aerobic scope.In consequence, expansion of \nOMZs and other regions where warming, hypoxia and acidification \ncombine will further reduce habitat for many fish and invertebrates \n(high confidence) (Sections\u00a03.4.3.2, 3.4.3.3).Food availability modulates, and may be more influential than, \nother driver responses by affecting the energetic and nutritional \nstatus of animals (Cole et\u00a0 al., 2016; Stiasny et\u00a0 al., 2019; Cominassi \net\u00a0al., 2020).Laboratory studies conducted under an excess of food \nrisk underestimating the ecological effects of climate-induced \ndrivers, because increased feeding rates may help mitigate adverse \neffects (Nowicki et\u00a0 al., 2012; Towle et\u00a0 al., 2015; Cominassi et\u00a0 al., \n2020).Lowered food availability from reduced open-ocean primary \nproduction (Sections\u00a03.2.3.3, 3.4.4.2.1) will act as an additional driver, \namplifying the detrimental effects of other drivers.However, warming \nand higher CO 2 availability may increase primary productivity in some \ncoastal areas (Section\u00a03.4.4.1), ameliorating the adverse direct effects \non animals (e.g., Sswat et\u00a0al., 2018).Due to the few studies addressing \nfood availability under multiple-driver scenarios (Thomsen et\u00a0al., 2013; \nPistevos et\u00a0al., 2015; Towle et\u00a0al., 2015; Ramajo et\u00a0al., 2016; Brown \net\u00a0al., 2018a; Cominassi et\u00a0al., 2020), there is medium confidence in its \nmodulating effect on climate-induced driver responses.Animal behaviour can be affected by ocean acidification, warming \nand hypoxia.While warming and hypoxia mostly induce avoidance \nbehaviour, potentially leading to migration and habitat compression \n(Section\u00a03.4; McCormick and Levin, 2017; Limburg et\u00a0al., 2020), the \neffects of acidification appear more complex.Some studies reported \nthat acidification dominates behavioural effects (Schmidt et\u00a0al., 2017), \nalthough outcomes vary with experimental design and duration \nof exposure (low confidence, low agreement) (Maximino and de \nBrito, 2010; Munday et\u00a0 al., 2016; Laubenstein et\u00a0 al., 2018; Munday \net\u00a0 al., 2019; Sundin et\u00a0 al., 2019; Clark et\u00a0 al., 2020; Munday et\u00a0 al., \n2020; Williamson et\u00a0 al., 2021).Behaviour represents an integrated \nphenomenon that can be influenced both directly and indirectly \nby multiple drivers.\n\npage_label: 414\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nNet calcification and abundance of mussels and other \nfoundational species, including oysters, are expected to decline due to \nocean acidification (very high confidence) (Kwiatkowski et\u00a0al., 2016; \nSunday et\u00a0al., 2016; McCoy et\u00a0al., 2018; Meng et\u00a0al., 2018), causing \nthe reorganisation of communities (high confidence) (Kroeker et\u00a0al., \n2013b; Linares et\u00a0al., 2015; Brown et\u00a0al., 2016; Sunday et\u00a0al., 2016; \nAgostini et\u00a0al., 2018; Teixid\u00f3 et\u00a0al., 2018).Experiments indicate that \nacidification can interact with warming and hypoxia to increase the\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the potential effects of acidification, hypoxia, and thermal stress on the growth, respiration, and survival of North Atlantic bivalves?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide specific information on the effects of acidification, hypoxia, and thermal stress on the growth, respiration, and survival of North Atlantic bivalves."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 443\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n443Oceans and Coastal Ecosystems and Their Services Chapter 3\nBox\u00a03.2 | Marine Birds and Mammals\nMarine birds (seabirds and shorebirds) and mammals include charismatic species and species that are economically, culturally and \necologically important (Sydeman et\u00a0al., 2015; Albouy et\u00a0al., 2020; Pimiento et\u00a0al., 2020). Their long generation times and slow population \ngrowth suggests limited evolutionary resilience to rapid climate change (Section\u00a03.3.4; Sydeman et\u00a0al., 2015; Miller et\u00a0al., 2018). According \nto the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020), the greatest current hazards to \nthese groups include human use of biological resources and areas, invasive species and pollution (see Figure\u00a0Box\u00a03.2.1; Dias et\u00a0al., 2019; \nLusseau et\u00a0al., 2021). Impacts of climate change and severe weather are ranked among the five most-important hazards influencing \n131 and 45 bird and mammal species, respectively (see Figure\u00a0Box\u00a03.2.1 for selection of species), including 24 bird and 7 mammal \nspecies that are currently listed as endangered, critically endangered or threatened. Furthermore, according to these IUCN assessments, \nclimate change and severe weather are expected to impact an additional 122 and 18 marine bird and mammal species over the next \n50\u2013100\u00a0years, respectively (see Figure\u00a0Box\u00a03.2.1; Dias et\u00a0al., 2019).\n0Hazard assessment for marine birds and mammals\n(a) Number of marine bird species\nResidential\nand\ncommercial\ndevelopmentAgriculture\nand\naquacultureEnergy\nproduction\nand miningTransportation \nand service\ncorridorsBiological\nresource\nuseHuman\nintrusions\nand\ndisturbanceNatural\nsystem\nmodificationsInvasive\nand other\nproblematic\nspecies, genes\nand diseasesPollution Geological\neventsClimate\nchange\nand\nsevere\nweatherOther\noptions050100150200250300350\n120\n100\n80\n60\n40\n20(b) Number of marine mammal speciesAdditional species expected to be exposed to these threats over the next 50\u2013100 years Species currently impacted by different hazards\nFigure\u00a0Box\u00a03.2.1 | \u00a0Hazard assessment for marine birds and mammals. Number of (a) marine birds and (b) mammals currently impacted by different hazards \n(blue), and numbers of additional species expected to be exposed to these threats over the next 50\u2013100\u00a0years (red), as assessed in the International Union for Conservation \nof Nature Red List (IUCN, 2020). Seabird species include species in the key orders Sphenisciformes, Pelecaniformes, Suliformes, Anseriformes, Procellariiformes and \nCharadriiformes categorised as inhabitants of marine ecosystems (n = 483 species, assessed in the period 2016\u20132019). Marine mammal species include the species \nreviewed by Lusseau et\u00a0al. (2021) (n = 136 species, assessed in the period 2008\u20132019).\nMarine birds and mammals are vulnerable to climate-induced loss of breeding and foraging habitats such as sea ice (Section\u00a03.4.2.12), \nsandy beaches (Section\u00a03.4.2.6), salt marshes (Section\u00a03.4.2.5) and seagrass beds (high confidence) (Section\u00a03.4.2.5; Sydeman et\u00a0al., 2015; \nBindoff et\u00a0al., 2019a; Ropert-Coudert et\u00a0al., 2019; Von Holle et\u00a0al., 2019; Albouy et\u00a0al., 2020; Amano et\u00a0al., 2020; Bestley et\u00a0al., 2020; Grose \net\u00a0al., 2020). With warming, shorebird population abundances decline in the tropics, likely due to heat stress and habitat loss, and increase \nat higher latitudes (Amano et\u00a0al., 2020). Marine mammals dependent on sea ice habitat are particularly vulnerable to warming (medium \nconfidence) (Albouy et\u00a0al., 2020; Bestley et\u00a0al., 2020; Lefort et\u00a0al., 2020), yet vulnerability can differ between populations. Ongoing sea ice\n\npage_label: 445\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n445Oceans and Coastal Ecosystems and Their Services Chapter 3\nIncreased emergence of infectious disease in mammals and birds is expected with ocean warming, due to new transmission pathways \nfrom changing species distributions, higher species densities caused by habitat loss and increased vulnerability due to environmental \nstress on individuals (limited evidence) (Sydeman et\u00a0al., 2015; VanWormer et\u00a0al., 2019; Sanderson and Alexander, 2020).Marine birds and \nmammals are likely to suffer from increased mortalities due to increasing frequencies of HABs, and of extreme weather, at sea, on sea ice, \nand in terrestrial breeding habitats (Broadwater et\u00a0al., 2018; Gibble and Hoover, 2018; Ropert-Coudert et\u00a0al., 2019; Grose et\u00a0al., 2020).Also, \nclimate-change driven distributional shifts have strengthened interactions with other anthropogenic impacts, through, for example, \nincreasing risks of ship strikes and bycatch (medium confidence) (e.g., Hauser et\u00a0al., 2018; Kr\u00fcger et\u00a0al., 2018; Record et\u00a0al., 2019; Santora \net\u00a0al., 2020).Box 3.2 (continued)\nthe risk of abrupt ecosystem shifts (high confidence) (Figure\u00a0 3.19a; \nCross-Chapter\u00a0Box\u00a0EXTREMES in Chapter\u00a02; van der Bolt et\u00a0al., 2018; \nGarrabou et\u00a0al., 2021; Wernberg, 2021).Ecosystems can recover from abrupt shifts (e.g., Babcock et\u00a0al., 2019; \nChristie et\u00a0al., 2019; Medrano et\u00a0al., 2020).However, where climate \nchange is a dominant driver, ecosystem collapses increasingly cause \npermanent transitions (high confidence), although the extents of \nsuch transitions depend on the emission scenario (Trisos et\u00a0al., 2020; \nGarrabou et\u00a0al., 2021; Klein et\u00a0al., 2021; Pratchett et\u00a0al., 2021; Wernberg, \n2021).Over the coming decades, MHWs are projected to very likely \nbecome more frequent under all emission scenarios (Section\u00a03.2; WGI \nAR6 Chapter\u00a0 9; Fox-Kemper et\u00a0 al., 2021), with intensities and rates \ntoo high for recovery of degraded foundational species, habitats or \nbiodiversity (medium confidence) (Babcock et\u00a0 al., 2019; Garrabou \net\u00a0al., 2021; Klein et\u00a0al., 2021; Serrano et\u00a0al., 2021; Wernberg, 2021).Emission pathways that result in temperature overshoot above 1.5oC \nwill increase the risks of abrupt and irreversible shifts in coral reefs and \nother vulnerable ecosystems (Section\u00a03.4.4).3.4.3.3.4 Time of emergence: species exposure to altered \nenvironments\nSince SROCC, more studies have assessed the time of emergence for \nclimate-induced drivers (Section\u00a0 3.2.3) and the ecosystem attributes \nthrough which the impacts manifest.However, as in\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the greatest current hazards to marine birds and mammals according to the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020)?\nAnswer: "}, {"role": "assistant", "content": "The greatest current hazards to marine birds and mammals, according to the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020), include human use of biological resources and areas, invasive species, and pollution. Climate change and severe weather are also ranked among the five most important hazards influencing these groups."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: foundational species, habitats or \nbiodiversity (medium confidence) (Babcock et\u00a0 al., 2019; Garrabou \net\u00a0al., 2021; Klein et\u00a0al., 2021; Serrano et\u00a0al., 2021; Wernberg, 2021).Emission pathways that result in temperature overshoot above 1.5oC \nwill increase the risks of abrupt and irreversible shifts in coral reefs and \nother vulnerable ecosystems (Section\u00a03.4.4).3.4.3.3.4 Time of emergence: species exposure to altered \nenvironments\nSince SROCC, more studies have assessed the time of emergence for \nclimate-induced drivers (Section\u00a0 3.2.3) and the ecosystem attributes \nthrough which the impacts manifest.However, as in previous assessments \n(Table\u00a0 3.22), the time of emergence for a given driver or ecosystem \nattribute depends on the reference period, the definition of the signal \nemergence threshold and the spatio-temporal scales considered (see \nBox\u00a05.1 in SROCC; Kirtman et\u00a0al., 2013; Bindoff et\u00a0al., 2019a).Anthropogenically driven changes in chlorophyll-a concentrations \nacross an ensemble of 30 ESMs are expected to exceed natural variability \nunder RCP8.5 by 2100 in ~65\u201380% of the global oceans, when the \nnatural variability is calculated using the ensemble\u2019s standard deviation \n(Schlunegger et\u00a0al., 2020); however, if two standard deviations are used, \nthen significant trends in chlorophyll-a concentration are expected \nunder RCP8.5 across ~31% of the global oceans by 2100 (Dutkiewicz \net\u00a0 al., 2019).\nQuery: What are the greatest current hazards to marine birds and mammals according to the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020)?\nOriginal Answer: The greatest current hazards to marine birds and mammals, according to the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020), include human use of biological resources and areas, invasive species, and pollution. Climate change and severe weather are also ranked among the five most important hazards influencing these groups.\nNew Answer: "}, {"role": "assistant", "content": "The most significant current threats to marine birds and mammals, as per the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020), are human exploitation of biological resources and areas, invasive species, and pollution. Climate change and severe weather also feature in the top five hazards impacting these groups."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 503\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n503Oceans and Coastal Ecosystems and Their Services Chapter 3\nClaudet, J., et\u00a0al., 2020a: A Roadmap for using the UN decade of ocean science \nfor sustainable development in support of science, policy, and action.One \nEarth, 2(1), 34\u201342, doi:10.1016/j.oneear.2019.10.012.Claudet, J., C. Loiseau, M. Sostres and M. Zupan, 2020b: Underprotected marine \nprotected areas in a global biodiversity hotspot.One Earth, 2(4), 380\u2013384, \ndoi:10.1016/j.oneear.2020.03.008.Clay, P .M., et\u00a0al., 2020: Ocean and coastal indicators: understanding and coping \nwith climate change at the land-sea interface.Clim.Change, 163(4), 1773\u2013\n1793, doi:10.1007/s10584-020-02940-x.Clements, J.C. and H.L.Hunt, 2015: Marine animal behaviour in a high CO 2 \nocean.Mar.Ecol.Prog.Ser., 536, 259\u2013279, doi:10.3354/meps11426.Cockerell, B., et\u00a0al., 2020: Representation does not necessarily reduce threats \nto biodiversity: Australia\u2019s Commonwealth marine protected area system, \n2012\u20132018.Biol.Conserv., 252, 108813, doi:10.1016/j.biocon.2020.108813.Cohen, M.C.L., et\u00a0al., 2020: Impacts of Holocene and modern sea-level changes \non estuarine mangroves from northeastern Brazil.Earth Surf.Process.Landforms, 45(2), 375\u2013392, doi:10.1002/esp.4737.Cohen, P .J., et\u00a0al., 2019: Securing a Just space for small-scale fisheries in the \nblue economy.Front.Mar.Sci., 6, 171, doi:10.3389/fmars.2019.00171.Cohen, R.E., et\u00a0 al., 2018: Marine host-pathogen dynamics: influences of \nglobal climate change.Oceanography, 31(2), 182\u2013193, doi:10.5670/\noceanog.2018.201.Cohen-Shacham, E., et\u00a0al., 2019: Core principles for successfully implementing \nand upscaling nature-based solutions.Environ.Sci.Policy, 98, 20\u201329, \ndoi:10.1016/j.envsci.2019.04.014.Coldren, G.A., J.A.Langley, I.C.Feller and S.K.Chapman, 2019: Warming \naccelerates mangrove expansion and surface elevation gain in a subtropical \nwetland.J.Ecol., 107(1), 79\u201390, doi:10.1111/1365-2745.13049.Cole, V.J., et\u00a0 al., 2016: Effects of multiple climate change stressors: ocean \nacidification interacts with warming, hyposalinity, and low food supply on \nthe larvae of the brooding flat oyster Ostrea angasi.Mar.Biol., 163(5), 125, \ndoi:10.1007/s00227-016-2880-4.Coleman, M. A. and H.D.Goold, 2019: Harnessing synthetic biology for kelp \nforest conservation.J.Phycol., 55(4), 745\u2013751, doi:10.1111/jpy.12888.Coleman, M. A., A.J.P .Minne, S. Vranken and T. Wernberg, 2020a: Genetic \ntropicalisation following a marine heatwave.Sci.Rep., 10(1), 12726, \ndoi:10.1038/s41598-020-69665-w.\nColeman, M. A., et\u00a0 al., 2020b: Restore or redefine: future trajectories for \nrestoration.Front.Mar.Sci., 7, 237, doi:10.3389/fmars.2020.00237.Collins, M., et\u00a0al., 2019a: Extremes, Abrupt Changes and Managing Risks.In: \nIPCC Special Report on the Ocean and Cryosphere in a Changing Climate.\n\npage_label: 522\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n522Chapter 3 Oceans and Coastal Ecosystems and Their Services\nLam, V.W.Y ., et\u00a0 al., 2020: Climate change, tropical fisheries and prospects \nfor sustainable development.Nat.Rev.Earth Environ., 1(9), 440\u2013454, \ndoi:10.1038/s43017-020-0071-9.Lam, V.W.Y ., W.W.L.Cheung and U.R.Sumaila, 2016: Marine capture fisheries in \nthe Arctic: winners or losers under climate change and ocean acidification?Fish Fish., 17(2), 335\u2013357, doi:10.1111/faf.12106.Lamborg, C.H., et\u00a0 al., 2014: A global ocean inventory of anthropogenic \nmercury based on water column measurements.Nature, 512(7512), 65\u201368, \ndoi:10.1038/nature13563.Lamim, V.B.and L. Proc\u00f3pio, 2021: Influence of acidification and warming \nof seawater on biofouling by bacteria grown over API 5L steel.Indian J.Microbiol., 61(2), 151\u2013159, doi:10.1007/s12088-021-00925-7.Lamont, M.M., D. Johnson and R.R.Carthy, 2020: The incubation environment \nof nests deposited by a genetically distinct group of loggerhead sea turtles \nin Northwest Florida.Glob.Ecol.Conserv., 23, e01070, doi:10.1016/j.gecco.2020.e01070.Landrum, L. and M.M.Holland, 2020: Extremes become routine in an emerging \nnew Arctic.Nat.Clim.Change, 10, 1108\u20131115, doi:10.1038/s41558-020-\n0892-z.Langbehn, T.J. and \u00d8. Varpe, 2017: Sea-ice loss boosts visual search: fish \nforaging and changing pelagic interactions in polar oceans.Glob.Change \nBiol., 23(12), 5318\u20135330, doi:10.1111/gcb.13797.Lange, I.D.and C.T.Perry, 2019: Bleaching impacts on carbonate production in \nthe Chagos Archipelago: influence of functional coral groups on carbonate \nbudget trajectories.Coral Reefs, 38(4), 619\u2013624, doi:10.1007/s00338-019-\n01784-x.Langston, A.K., O. Dur\u00e1n Vinent, E.R.Herbert and M.L.Kirwan, 2020: Modeling \nlong-term salt marsh response to sea level rise in the sediment-deficient \nPlum Island Estuary, MA.Limnol.Oceanogr.,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of Chapter 3 in the report on climate change and the oceans?\nAnswer: "}, {"role": "assistant", "content": "The title of Chapter 3 in the report on climate change and the oceans is \"Oceans and Coastal Ecosystems and Their Services\"."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 5318\u20135330, doi:10.1111/gcb.13797.Lange, I.D.and C.T.Perry, 2019: Bleaching impacts on carbonate production in \nthe Chagos Archipelago: influence of functional coral groups on carbonate \nbudget trajectories.Coral Reefs, 38(4), 619\u2013624, doi:10.1007/s00338-019-\n01784-x.Langston, A.K., O. Dur\u00e1n Vinent, E.R.Herbert and M.L.Kirwan, 2020: Modeling \nlong-term salt marsh response to sea level rise in the sediment-deficient \nPlum Island Estuary, MA.Limnol.Oceanogr., 65(9), 2142\u20132157, doi:10.1002/\nlno.11444.Lannuzel, D., et\u00a0al., 2020: The future of Arctic sea-ice biogeochemistry and ice-\nassociated ecosystems.Nat.Clim.Change, 10(11), 983\u2013992, doi:10.1038/\ns41558-020-00940-4.Larsen, J.N., et al., 2014: Polar regions.In: Climate Change 2014: Impacts, \nAdaptation, and Vulnerability.Part B: Regional Aspects.Contribution of \nWorking Group II to the Fifth Assessment Report of the Intergovernmental \nPanel of Climate Change.[Barros, V. R., C. B.Field, D. J. Dokken, M. D. \nMastrandrea, K. J. Mach, T. E. Bilir, M. Chatterjee, K. L. Ebi, Y .O. Estrada, R. C. \nGenova, B. Girma, E. S. Kissel, A. N. Levy, S. MacCracken, P .R. Mastrandrea \nand L. L. White (eds.)].Cambridge University Press, Cambridge, UK and New \nYork, NY , USA, pp.1567\u20131612.Laruelle, G.G., et\u00a0al., 2017: Global high-resolution monthly pCO 2 climatology for \nthe coastal ocean derived from neural network interpolation.\nQuery: What is the title of Chapter 3 in the report on climate change and the oceans?\nOriginal Answer: The title of Chapter 3 in the report on climate change and the oceans is \"Oceans and Coastal Ecosystems and Their Services\".\nNew Answer: "}, {"role": "assistant", "content": "The title of Chapter 3 in the report on climate change and the oceans is \"Oceans and Coastal Ecosystems and Their Services\"."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 502\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBal, E. Goetze and K.T.C.A.Peijnenburg, 2021: Oceanic \ndispersal barriers in a holoplanktonic gastropod.J. Evol.Biol., 34(1), 224\u2013\n240, doi:10.1111/jeb.13735.Chow, J., 2018: Mangrove management for climate change adaptation and \nsustainable development in coastal zones.J.Sustain.For., 37(2), 139\u2013156, \ndoi:10.1080/10549811.2017.1339615.Chowdhury, M.S.N., et\u00a0 al., 2019: Oyster breakwater reefs promote adjacent \nmudflat stability and salt marsh growth in a monsoon dominated subtropical \ncoast.Sci.Rep., 9(1), 8549, doi:10.1038/s41598-019-44925-6.Christensen, J.H., et al., 2007: Regional climate projections.In: Climate Change \n2007: The Physical Science Basis.Contribution of Working Group I to the \nFourth Assessment Report of the Intergovernmental Panel on Climate \nChange.[Solomon, S., D. Qin, M. Manning, Z. Chen, M. Marquis, K. B. Averyt, \nM. Tignor and H. L. Miller (eds.)].Cambridge University Press, Cambridge, UK \nand New York, NY , USA, pp.847\u2013940.ISBN 978-0521880091.Christensen, V., et\u00a0al., 2014: A century of fish biomass decline in the ocean.Mar.Ecol.Prog.Ser., 512, 155\u2013166, doi:10.3354/meps10946.Christian, J.R., 2014: Timing of the departure of ocean biogeochemical cycles \nfrom the preindustrial state.Plos One, 9(11), e109820, doi:10.1371/journal.pone.0109820.Christie, H., et\u00a0al., 2019: Shifts between sugar kelp and turf algae in Norway: \nregime shifts or fluctuations between different opportunistic seaweed \nspecies?Front.Mar.Sci., 6, 72, doi:10.3389/fmars.2019.00072.Christodoulou, A., P .Christidis and H. Demirel, 2019: Sea-level rise in ports: a \nwider focus on impacts.Marit.Econ.Logist., 21(4), 482\u2013496, doi:10.1057/\ns41278-018-0114-z.Chu, J.W.F .and V. Tunnicliffe, 2015: Oxygen limitations on marine animal \ndistributions and the collapse of epibenthic community structure during \nshoaling hypoxia.Glob.Change Biol., 21(8), 2989\u20133004, doi:10.1111/\ngcb.12898.Chung, W.-S., et\u00a0 al., 2014: Ocean acidification slows retinal function in a \ndamselfish through interference with GABA A receptors.J. Exp.Biol., 217(3), \n323\u2013326, doi:10.1242/jeb.092478.Church, J.A.and N.J. White, 2011: Sea-level rise from the late 19th to the early \n21st\u00a0 century.Surv.Geophys., 32(4-5), 585\u2013602, doi:10.1007/s10712-011-\n9119-1.Chust, G., et\u00a0al., 2014a: Biomass changes and trophic amplification of plankton \nin a warmer ocean.Glob.Change Biol., 20(7), 2124\u20132139, doi:10.1111/\ngcb.12562.Chust, G., et\u00a0 al., 2014b: Are Calanus spp.shifting poleward in the North \nAtlantic?A habitat modelling approach.ICES J. Mar.Sci., 71(2), 241\u2013253, \ndoi:10.1093/icesjms/fst147.Chust, G., et\u00a0al., 2019: Earlier migration and distribution changes of albacore \nin the Northeast Atlantic.Fish.Oceanogr., 28(5), 505\u2013516, doi:10.1111/\nfog.12427.\n\npage_label: 431\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n(2021) reports that >80% of sampled sea snail, Limacina helicina, a key \nspecies in pelagic food webs, displayed signs of shell dissolution in the \nAmundsen Gulf.However, bacteria, phytoplankton, zooplankton and \nbenthic communities are found to be detrimentally impacted, resilient \nor even positively influenced by ocean acidification in observational\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title and author of the paper that discusses the oceanic dispersal barriers in a holoplanktonic gastropod?\nAnswer: "}, {"role": "assistant", "content": "The title of the paper that discusses the oceanic dispersal barriers in a holoplanktonic gastropod is \"Oceanic Dispersal Barriers in a Holoplanktonic Gastropod.\" The authors of this paper are E. Bal, E. Goetze, and K.T.C.A.Peijnenburg. The paper was published in 2021."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 412\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nHowever, experimental evidence suggests that coral responses to \nocean acidification are species specific (medium confidence) (Fabricius \net\u00a0al., 2011; DeCarlo et\u00a0al., 2018; Comeau et\u00a0al., 2019).Evidence from \nSummary assessment of observed hazards to coastal ecosystems and seas\nClimate-induced drivers\nWarm water coral reefs\nRocky shores\nKelp systems\nMangroves\nSaltmarshes\nSeagrases\nSandy beaches\nSemi-enclosed seas\nShelf seas\nEBUS*\nArctic region\nAntarctic regionSystem WarmingMarine\nheat-\nwavesOcean\nacidificationSea-\nlevel Storms OxygenSea\niceSummary\nriskPrimary non-climate drivers\nMarine\npollution\nFisheries/\nharvestin g\nNutrient en-\nhancementHabitat\ndegradation\nNon-\nindigenous\nspeciesAssessment\u2019s\ncorresponding\nsection in\nthe report\nEstuaries, lagoons3.4.2.1\n3.4.2.2\n3.4.2.3\n3.4.2.5\n3.4.2.6\n3.4.2.7\n3.4.2.8\n3.4.2.9\n3.4.2.103.4.2.4Ecological\nadaptive\ncapacity\nLow\nLow\nModerate to hig h\nLow to moderate\nModerate\nLow to moderate\nModerate\nLow\nLow to moderate\nModerate\nLowLow\nLow/\n/\n/\n/\n/\n/\n/\n/\n/\n//\nna\nna\nna\nna\nna\nna\nna\nna\nnanana\nna\nna\nna\nnana\nna\nnanana\nna\nnananana\n* Eastern Boundary\nUpwelling Systems= no data or not assessednaStrength of impact\nHigh to\nvery highMedium Low to\nvery lowConfidence level\n= not applicable/ Mixed\ndirectionHigh Medium Low High Medium Low\nFigure\u00a03.12 | \u00a0Summary assessment of observed hazards to coastal ecosystems and seas as assessed in Section\u00a03.4.2.\n\npage_label: 528\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nMonaco, C.J., et\u00a0al., 2021: Natural and anthropogenic climate variability shape \nassemblages of range-extending coral-reef fishes.J.Biogeogr., 48(5), 1063\u2013\n1075, doi:10.1111/jbi.14058.Monaco, C.J., et\u00a0al., 2020: Dietary generalism accelerates arrival and persistence \nof coral-reef fishes in their novel ranges under climate change.Glob.Change \nBiol., 26(10), 5564\u20135573, doi:10.1111/gcb.15221.Monios, J. and G. Wilmsmeier, 2020: Deep adaptation to climate change in the \nmaritime transport sector \u2013 a new paradigm for maritime economics?Marit.Policy Manag., 47(7), 853\u2013872, doi:10.1080/03088839.2020.1752947.Monnereau, I., et\u00a0 al., 2017: The impact of methodological choices on the \noutcome of national-level climate change vulnerability assessments: \nan example from the global fisheries sector.Fish Fish., 18(4), 717\u2013731, \ndoi:10.1111/faf.12199.Monsinjon, J., et\u00a0 al., 2019: Effects of temperature and demography on the \nphenology of loggerhead sea turtles in Brazil.Mar.Ecol.Prog.Ser., 623, \n209\u2013219, doi:10.3354/meps12988.Mont\u00e1nchez, I. and V.R.Kaberdin, 2020: Vibrio harveyi: A brief survey of \ngeneral characteristics and recent epidemiological traits associated \nwith climate change.Mar.Environ.Res., 154, 104850, doi:10.1016/j.marenvres.2019.104850.Montero-Serra, I., M. Edwards and M.J. Genner, 2015: Warming shelf seas drive \nthe subtropicalization of European pelagic fish communities.Glob.Change \nBiol., 21(1), 144\u2013153, doi:10.1111/gcb.12747.Montero-Serra, I., et\u00a0 al., 2019: Marine protected areas enhance structural \ncomplexity but do not buffer the consequences of ocean warming \nfor an overexploited precious coral.J. Appl.Ecol., 56(5), 1063\u20131074, \ndoi:10.1111/1365-2664.13321.Montgomery, D.W., et\u00a0al., 2019: Rising CO 2 enhances hypoxia tolerance in a \nmarine fish.Sci.Rep., 9(1), 15152, doi:10.1038/s41598-019-51572-4.Monti, F ., et\u00a0al., 2018: The price of success: integrative long-term study reveals \necotourism impacts on a flagship species at a UNESCO site.Anim.Conserv., \n21(6), 448\u2013458, doi:10.1111/acv.12407.Moore, C.M., et\u00a0al., 2013: Processes and patterns of oceanic nutrient limitation.Nat.Geosci., 6(9), 701\u2013710, doi:10.1038/ngeo1765.Moore, J.K., et\u00a0al., 2018a: Sustained climate warming drives declining marine \nbiological productivity.Science, 359(6380), 1139\u20131143, doi:10.1126/\nscience.aao6379.Moore, K.M., et\u00a0al., 2020a: Harmful algal blooms: identifying effective adaptive \nactions used in fishery-dependent communities in response to a protracted \nevent.Front.Mar.Sci., 6, 803, doi:10.3389/fmars.2019.00803.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context, which study found that ocean acidification does not impair the behavior of coral reef fishes?\nAnswer: "}, {"role": "assistant", "content": "The provided context does not include information about a study that found ocean acidification does not impair the behavior of coral reef fishes."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 428\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n428Chapter 3 Oceans and Coastal Ecosystems and Their Services\net\u00a0al., 2018; Maharaj et\u00a0al., 2018; Ma et\u00a0al., 2019; Meyer and Kr\u00f6ncke, \n2019; Bargahi et\u00a0 al., 2020; Bedford et\u00a0 al., 2020; Friedland et\u00a0 al., \n2020b; M\u00e9rillet et\u00a0 al., 2020).Eutrophication and seasonal bottom-\nwater hypoxia in some shelf seas have been linked to warming (high \nconfidence) (Wei et\u00a0al., 2019; Del Giudice et\u00a0al., 2020) and increased \nriverine nutrient loading (high confidence) (Wei et\u00a0al., 2019; Del Giudice \net\u00a0al., 2020).Since SROCC, some severe HABs have been attributed to \nextreme events, such as MHWs (Section\u00a014.4.2; Roberts et\u00a0al., 2019; \nTrainer et\u00a0al., 2019); however, a recent worldwide assessment of HABs \nattributed the increase in observed HABs to intensified monitoring \nassociated with increased aquaculture production (high confidence) \n(Hallegraeff et\u00a0al., 2021).Since SROCC, changes in the community structure and diversity of \nplankton, macrofauna and infauna have been detected in some shelf \nseas, although attribution has been regionally specific (e.g., bottom-\nwater warming or hypoxia) (Meyer and Kr\u00f6ncke, 2019; Rabalais and \nBaustian, 2020).Detection of the picoplankton Synechococcus spp.in \nthe North Sea is potentially linked to a summer decrease in copepod \nstocks and declining food-web efficiency (low confidence) (Schmidt \net\u00a0al., 2020).The seasonally distinct phytoplankton assemblages in the \nNorth Sea have begun to appear concurrently and homogenise (Nohe \net\u00a0al., 2020).Changes in abundance, species composition and size of \nzooplankton have been detected in some shelf seas (Yellow Sea, North \nSea, Celtic Sea and Tasman Sea), including a decline in stocks of larger \ncopepods, increased abundances of gelatinous and meroplankton, and \na shift to smaller species due to warming, increased river discharge, \ncirculation change and/or extreme events (high confidence) (Wang \net\u00a0al., 2018a; Bedford et\u00a0al., 2020; Evans et\u00a0al., 2020; Shi et\u00a0al., 2020; \nEdwards et\u00a0al., 2021).Ocean warming has shifted distributions of fish (Free et\u00a0 al., 2019; \nFranco et\u00a0 al., 2020; Pinsky et\u00a0 al., 2020b; Fredston et\u00a0 al., 2021) and \nmarine mammal species (Salvadeo et\u00a0al., 2010; Garc\u00eda-Aguilar et\u00a0al., \n2018; Davis et\u00a0al., 2020) poleward (high confidence) or deeper (low \nto medium confidence) (Section\u00a03.4.3.1; Nye et\u00a0al., 2009; Pinsky et\u00a0al., \n2013; Pinsky et\u00a0al., 2020b).Warming has also tropicalised the pelagic \nand demersal fish assemblages of mid- and high-latitude shelves \n(high confidence) (Montero-Serra et\u00a0 al., 2015; Liang et\u00a0 al., 2018; \nMaharaj et\u00a0al., 2018; Ma et\u00a0al., 2019; Friedland et\u00a0al., 2020a; Kakehi \net\u00a0al., 2021; Punz\u00f3n et\u00a0al., 2021).Fisheries catch composition in many \nshelf-sea ecosystems has become increasingly dominated by warm-\nwater species since the 1970s (high confidence) (Cheung et\u00a0al., 2013; \nLeit\u00e3o et\u00a0al., 2018; Maharaj et\u00a0al., 2018; McLean et\u00a0al., 2019).Warming \nhas taxonomically diversified fish communities along a latitudinal \ngradient in the North Sea but has homogenised functional diversity \n(McLean et\u00a0al., 2019).However, in some regions, changing predator \nor prey distributions, temperature-dependent hypoxia, population \nchanges, evolutionary adaptation and other biotic or abiotic processes, \nincluding species\u2019 exploitation, confound responses to climate-induced \ndrivers, which must therefore be interpreted with caution (Frank et\u00a0al., \n2018).\n\npage_label: 526\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n526Chapter 3 Oceans and Coastal Ecosystems and Their Services\nMarangon, E., S.U.Goldenberg and I. Nagelkerken, 2020: Ocean warming \nincreases availability of crustacean prey via riskier behavior.Behav.Ecol., \n31(2), 287\u2013291, doi:10.1093/beheco/arz196.Mara\u00f1\u00f3n, E., M.P .Lorenzo, P .Cerme\u00f1o and B. Mouri\u00f1o-Carballido, 2018: \nNutrient limitation suppresses the temperature dependence of phytoplankton \nmetabolic rates.ISME J., 12(7), 1836\u20131845, doi:10.1038/s41396-018-0105-1.Marb\u00e0, N., et\u00a0al., 2015a: Impact of seagrass loss and subsequent revegetation \non carbon sequestration and stocks.J.Ecol., 103(2), 296\u2013302, \ndoi:10.1111/1365-2745.12370.Marb\u00e0, N., et\u00a0al., 2015b: Footprints of climate change on Mediterranean Sea \nbiota.Front.Mar.Sci., 2, 56, doi:10.3389/fmars.2015.00056.Marchini, A., et\u00a0 al., 2019: Intertidal mediterranean coralline algae habitat is \nexpecting a shift toward a reduced growth and a simplified associated fauna \nunder climate change.Front.Mar.Sci., 6, 106, doi:10.3389/fmars.2019.00106.Mardones, M.L., P .B.Fenberg, S. Thatje and C. Hauton, 2021: Variation in \nthermal tolerance response associated with geographic location during early \ndevelopment of the neogastropod Ocenebra erinaceus (Linnaeus, 1758).J. \nExp.Mar.Biol.Ecol., 542-543, 151590, doi:10.1016/j.jembe.2021.151590.Mariani, G., et\u00a0al., 2020: Let more big fish sink: Fisheries prevent blue carbon \nsequestration\u2014half in unprofitable areas.Sci.Adv., 6(44), eabb4848, \ndoi:10.1126/sciadv.abb4848.Marine Conservation Institute, 2021: The Marine Protection Atlas.Marine \nConservation Institute, Accessed 28th December 2021, https://mpatlas.org.Marshall, K.N., et\u00a0al., 2017: Risks of ocean acidification in the California Current \nfood web and fisheries: ecosystem model projections.Glob.Change Biol., \n23(4), 1525\u20131539, doi:10.1111/gcb.13594.Marshall,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020)?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020)."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: G., et\u00a0al., 2020: Let more big fish sink: Fisheries prevent blue carbon \nsequestration\u2014half in unprofitable areas.Sci.Adv., 6(44), eabb4848, \ndoi:10.1126/sciadv.abb4848.Marine Conservation Institute, 2021: The Marine Protection Atlas.Marine \nConservation Institute, Accessed 28th December 2021, https://mpatlas.org.Marshall, K.N., et\u00a0al., 2017: Risks of ocean acidification in the California Current \nfood web and fisheries: ecosystem model projections.Glob.Change Biol., \n23(4), 1525\u20131539, doi:10.1111/gcb.13594.Marshall, N., et\u00a0 al., 2019: Reef grief: investigating the relationship between \nplace meanings and place change on the Great Barrier Reef, Australia.Sustain.Sci., 14(3), 579\u2013587, doi:10.1007/s11625-019-00666-z.Martin, A.H., H.C. Pearson, G.K. Saba and E.M. Olsen, 2021: Integral functions of \nmarine vertebrates in the ocean carbon cycle and climate change mitigation.One Earth, 4(5), 680\u2013693, doi:10.1016/j.oneear.2021.04.019.Martin, C.L., S. Momtaz, T. Gaston and N.A.Moltschaniwskyj, 2020: Estuarine \ncultural ecosystem services valued by local people in New South Wales, \nAustralia, and attributes important for continued supply.Ocean Coast.Manag., 190, 105160, doi:10.1016/j.ocecoaman.2020.105160.Martin, K.L.M., E.A.Pierce, V.V.Quach and M. Studer, 2019: Population trends of \nbeach-spawning California grunion Leuresthes tenuis monitored by citizen \nscientists.ICES J. Mar.Sci., 77(6), 2226\u20132233, doi:10.1093/icesjms/fsz086.Mart\u00edn-Garc\u00eda, L., et\u00a0al., 2014: Predicting the potential habitat of the harmful \ncyanobacteria Lyngbya majuscula in the Canary Islands (Spain).\nQuery: What is the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020)?\nOriginal Answer: The context does not provide information on the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020).\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide information on the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020)."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 454\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n454Chapter 3 Oceans and Coastal Ecosystems and Their Services\nBox\u00a03.3 | Deep-Sea Ecosystems\nDeep-sea ecosystems include all waters below the 200-m isobath as well as the underlying benthos, and they provide habitats for highly \ndiversified and specialised biota, which play a key role in the cycling of carbon and other nutrients (see Figure\u00a0Box\u00a03.3.1; Thurber et\u00a0al., \n2014; Middelburg, 2018; Snelgrove et\u00a0al., 2018).The deep sea covers >63% of Earth\u2019s surface (Costello and Cheung, 2010) and is exposed \nto climate-driven changes in abyssal, intermediate and surface waters that influence sinking fluxes of particulate organic matter (high \nconfidence) (see Figure\u00a0Box\u00a03.3.1; Sections\u00a03.1, 3.2.1, 3.2.2, 3.4.3.4; WGII AR5 Section\u00a030.5.7; SROCC Sections\u00a05.2.3, 5.2.4; Hoegh-Guldberg \net\u00a0al., 2014; Bindoff et\u00a0al., 2019a).These ecosystems are also influenced by non-climate drivers, especially fisheries, oil and gas extraction \n(Thurber et\u00a0al., 2014; Cordes et\u00a0al., 2016; Zhang et\u00a0al., 2019a); cable laying (United Nations, 2021); and mineral resource exploration (Hein \net\u00a0al., 2021); with proposed large-scale deep-sea mining a potential future source of impacts (Danovaro, 2018; Levin et\u00a0al., 2020).Ocean warming alters biological processes in deep-sea ecosystems in ways that affect deep-sea habitat, biodiversity and material \nprocessing.Enhancement of microbial respiration by warming attenuates sinking POC, which has been associated with the globally \nprojected declines in total seafloor biomass of \u22129.8 and \u221213.0% by 2081\u20132100 relative to 1995\u20132014 under SSP1-2.6 and SSP5-8.5, \nrespectively (limited evidence) (Section\u00a0 3.4.3.4).Additionally, climate-change-driven oxygen loss (Section\u00a0 3.2.3.2; Luna et\u00a0 al., 2012; \nBelley et\u00a0al., 2016) and geographic shifts in predator distributions (Section\u00a03.4.3.1) are anticipated to affect deep-sea biodiversity (limited \nevidence, high agreement) (Smith et\u00a0al., 2012; Morato et\u00a0al., 2020).Complex responses of some bathyal crustacean assemblages to \nenvironmental change suggest an increase in phylogenetic diversity but limited decreases in abundances with temperature (Ashford \net\u00a0al., 2019).Acute mortality of some reef-forming cold-water corals to laboratory-simulated warming (Lunden et\u00a0al., 2014) suggests \nthat both long-term warming and the increase of MHWs in intermediate and deep waters (Elzahaby and Schaeffer, 2019) could pose \nsignificant risk to associated ecosystems (high confidence).Thermal tolerance thresholds (lethal and sub-lethal) of scleractinians in \nlaboratory settings depend on their geographic position and capacity for thermal adaptation, as well as other factors including food, \noxygen and pH (medium to high confidence) (Naumann et\u00a0al., 2013; Hennige et\u00a0al., 2014; Lunden et\u00a0al., 2014; Naumann et\u00a0al., 2014; \nGeorgian et\u00a0al., 2016; Gori et\u00a0al., 2016; Maier et\u00a0al., 2016; B\u00fcscher et\u00a0al., 2017).The extension and intensification of deep-water acidification (Section\u00a03.2.3.1) has been identified as a further key risk to deep-water coral \necosystems (medium confidence) (Bindoff et\u00a0al., 2019a).Literature since SROCC supports this assessment (Morato et\u00a0al., 2020; Puerta \net\u00a0al., 2020), although scleractinians and gorgonians are found in regions undersaturated with respect to aragonite (Thresher et\u00a0al., 2011; \nFillinger and Richter, 2013; Baco et\u00a0al., 2017).Laboratory experiments on reef-forming scleractinians show variable results, with regional \nacclimation potential and population-genetic adaptations (Georgian et\u00a0al., 2016; Kurman et\u00a0al., 2017).\n\npage_label: 518\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nJohnson, D., M. Adelaide Ferreira and E. Kenchington, 2018: Climate change \nis likely to severely limit the effectiveness of deep-sea ABMTs in the North \nAtlantic.Mar.Policy, 87, 111\u2013122, doi:10.1016/j.marpol.2017.09.034.Johnson, D., et\u00a0al., 2019: The Global Ocean Biodiversity Initiative: promoting \nscientific support for global ocean governance.Aquat.Conserv.Mar.Freshw.Ecosyst., 29(S2), 162\u2013169, doi:10.1002/aqc.3024.Johnson, K.M.and G.E.Hofmann, 2020: Combined stress of ocean acidification \nand warming influence survival and drives differential gene expression \npatterns in the Antarctic pteropod, Limacina helicina antarctica.Conserv.Physiol., 8(1), coaa013, doi:10.1093/conphys/coaa013.Johnson, K.S., F .P .Chavez and G.E.Friederich, 1999: Continental-shelf sediment \nas a primary source of iron for coastal phytoplankton.Nature, 398(6729), \n697\u2013700, doi:10.1038/19511.Johnson, M.D., S. Comeau, C.A.Lantz and J.E.Smith, 2017b: Complex and \ninteractive effects of ocean acidification and temperature on epilithic and \nendolithic coral-reef turf algal assemblages.Coral Reefs, 36(4), 1059\u20131070, \ndoi:10.1007/s00338-017-1597-2.Jones, B. and B.C.O\u2019Neill, 2016: Spatially explicit global population scenarios \nconsistent with the Shared Socioeconomic Pathways.Environ.Res.Lett., \n11(8), 084003, doi:10.1088/1748-9326/11/8/084003.Jones, H.P ., et\u00a0al., 2018a: Restoration and repair of Earth\u2019s damaged ecosystems.Proc.R. Soc.B., 285(1873), 20172577, doi:10.1098/rspb.2017.2577.Jones, H.P ., et\u00a0 al., 2020: Global hotspots for coastal ecosystem-based \nadaptation.PLoS ONE, 15(5), e0233005, doi:10.1371/journal.pone.0233005.Jones, L.A., et\u00a0al., 2019a: Coupling of palaeontological and neontological reef \ncoral data improves forecasts of biodiversity responses under global climatic \nchange.R.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context on climate change and the oceans, which study focuses on the distribution of deep-sea sponge aggregations in an area of changing oceanic conditions?\nAnswer: "}, {"role": "assistant", "content": "The provided context does not mention a specific study that focuses on the distribution of deep-sea sponge aggregations in an area of changing oceanic conditions."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: H.P ., et\u00a0al., 2018a: Restoration and repair of Earth\u2019s damaged ecosystems.Proc.R. Soc.B., 285(1873), 20172577, doi:10.1098/rspb.2017.2577.Jones, H.P ., et\u00a0 al., 2020: Global hotspots for coastal ecosystem-based \nadaptation.PLoS ONE, 15(5), e0233005, doi:10.1371/journal.pone.0233005.Jones, L.A., et\u00a0al., 2019a: Coupling of palaeontological and neontological reef \ncoral data improves forecasts of biodiversity responses under global climatic \nchange.R. Soc.Open Sci., 6(4), 182111, doi:10.1098/rsos.182111.Jones, M.C.and W.W.L.Cheung, 2015: Multi-model ensemble projections of \nclimate change effects on global marine biodiversity.ICES J. Mar.Sci., 72(3), \n741\u2013752, doi:10.1093/icesjms/fsu172.Jones, M.C.and W.W.L.Cheung, 2018: Using fuzzy logic to determine the \nvulnerability of marine species to climate change.Glob.Change Biol., 24(2), \ne719\u2013e731, doi:10.1111/gcb.13869.Jones, M.C., et\u00a0 al., 2019b: Rapid inundation of southern Florida coastline \ndespite low relative sea-level rise rates during the late-Holocene.Nat.Commun., 10(1), 3231, doi:10.1038/s41467-019-11138-4.Jones, T., et\u00a0 al., 2018b: Massive mortality of a planktivorous seabird in \nresponse to a marine heatwave.Geophys.Res.Lett., 45(7), 3193\u20133202, \ndoi:10.1002/2017GL076164.\nQuery: Question: According to the provided context on climate change and the oceans, which study focuses on the distribution of deep-sea sponge aggregations in an area of changing oceanic conditions?\nOriginal Answer: The provided context does not mention a specific study that focuses on the distribution of deep-sea sponge aggregations in an area of changing oceanic conditions.\nNew Answer: "}, {"role": "assistant", "content": "The context provided does not specify a study that concentrates on the distribution of deep-sea sponge aggregations in areas of changing oceanic conditions."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 430\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n430Chapter 3 Oceans and Coastal Ecosystems and Their Services\net\u00a0 al., 2020b; Fiechter et\u00a0 al., 2021), are confounded by local-scale \noceanographic processes (Siedlecki et\u00a0al., 2021) and by lateral input of \nanthropogenic land-based nutrients (Kessouri et\u00a0al., 2021), suggesting \nthat such projections should be accorded low confidence.More generally, changes in upwelling intensity are observed to affect \norganismal metabolism, population productivity and recruitment, and food-web structure (medium confidence) (van der Sleen et\u00a0 al., \n2018; Brodeur et\u00a0al., 2019; Ramajo et\u00a0al., 2020).But low confidence \nin projected trends in upwelling make it difficult to extrapolate these \nresults to understand potential changes in the ecology of EBUS.Projected changes in fish biomass within EBUS (Carozza et\u00a0al., 2019) \nare therefore accorded low confidence.Finally, although MHWs are \nan important emerging hazard in the global ocean, with intensity, Table\u00a03.13 | \u00a0Summary of previous IPCC assessments of eastern boundary upwelling systems (EBUS)\nObservations Projections\nAR5 (Hoegh-Guldberg et\u00a0al., 2014; Lluch-Cota et\u00a0al., 2014)\n\u2018[EBUS] are vulnerable to changes that influence the intensity of currents, upwelling and \nmixing (and hence changes in sea surface temperature, wind strength and direction), as well \nas O 2 content, carbonate chemistry, nutrient content and the supply of organic carbon to \ndeep offshore locations (high confidence).\u2019\nClimate-change-induced intensification of ocean upwelling in some EBUS, as observed in \npast decades, may lead to regional cooling, rather than warming, of surface waters and \ncause enhanced productivity (medium confidence), but also enhanced hypoxia, acidification \nand associated biomass reduction in fish and invertebrate stocks.Owing to contradictory \nobservations, there is currently uncertainty about the future trends of major upwelling \nsystems and how their drivers will shape ecosystem characteristics ( low confidence).\u2018Declining O 2 and shoaling of the aragonite saturation horizon through ocean acidification \nincrease the risk of upwelling water being low in pH and O 2, with impacts on coastal \necosystems and fisheries [...].These risks and uncertainties are likely to involve significant \nchallenges for fisheries and associated livelihoods along the west coasts of South America, \nAfrica and North America (low to medium confidence).\u2019\n\u2018There is robust evidence and medium agreement that the California Current has \nexperienced [...] an increase of the overall magnitude of upwelling events from 1967 to \n2010 (high confidence).This is consistent with changes expected under climate change \nyet remains complicated by the influence of decadal-scale variability (low confidence).\u2019 \nDeclining oxygen concentrations and shoaling of the hypoxic boundary layer likely \u2018reduced \nthe available habitat for key benthic communities as well as fish and other mobile species.Together with the shoaling of the saturation horizon, these changes have increased the \nincidence of low O 2 and low pH water flowing onto the continental shelf (high confidence; \n40 to 120 m), causing problems for industries such as the shellfish aquaculture industry.\u2019\nDespite its apparent sensitivity to environmental variability, there is limited evidence of \necological changes in the Benguela Current EBUS due to climate change.\u2018Like other ocean sub-regions, [EBUS] are projected to warm under climate change, with \nincreased stratification and intensified winds as westerly winds shift poleward (likely).However, cooling has also been predicted for some [EBUS], resulting from the intensification \nof wind-driven upwelling.\u2019\n\u2018There is medium agreement, despite limited evidence, that upwelling intensity and \nassociated variables (e.g., temperature, nutrient and O 2 concentrations) from the Benguela \nsystem will change as a result of climate change.\u2019\nAny projected increase in upwelling intensity has potential disadvantages.\n\npage_label: 430\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n\u2018Elevated primary \nproductivity may lead to decreasing trophic transfer efficiency, thus increasing the amount \nof organic carbon exported to the seabed, where it is virtually certain to increase microbial \nrespiration and hence increase low O 2 stress.\u2019\nSROCC (Bindoff et\u00a0al., 2019a; IPCC, 2019c; IPCC, 2019d)\n\u2018Increasing ocean acidification and oxygen loss are negatively impacting two of the four \nmajor upwelling systems: the California Current and Humboldt Current (high confidence).Ocean acidification and decrease in oxygen level in the California Current upwelling system \nhave altered ecosystem structure, with direct negative impacts on biomass production and \nspecies composition (medium confidence).\u2019\n\u2018Three out of the four major Eastern Boundary Upwelling Systems (EBUS) have shown \nlarge-scale wind intensification in the past 60\u00a0years ( high confidence).However, the \ninteraction of coastal warming and local winds may have affected upwelling strength, with \nthe direction of changes [varying] between and within EBUS (low confidence).Increasing \ntrends in ocean acidification in the California Current EBUS and deoxygenation in California \nCurrent and Humboldt Current EBUS are observed in the last few decades (high confidence), \nalthough there is low confidence to distinguish anthropogenic forcing from internal climate \nvariability.The expanding California EBUS OMZ [oxygen minimum zone] has altered \necosystem structure and fisheries catches (medium confidence).\u2019\n\u2018Overall, EBUS have been changing with intensification of winds that drives the upwelling, \nleading to changes in water temperature and other ocean biogeochemistry ( medium \nconfidence).\u2019\n\u2018The direction and magnitude of observed changes vary among and within EBUS, with \nuncertainties regarding the driving mechanisms behind this variability.Moreover, the high \nnatural variability of EBUS and their insufficient representation by global ESMs [Earth \nsystem models] gives low confidence that these observed changes can be attributed to \nanthropogenic causes.\u2019\u2018Anthropogenic changes in EBUS will emerge primarily in the second half of the 21st\u00a0century \n(medium confidence).EBUS will be impacted by climate change in different ways, \nwith strong regional variability with consequences for fisheries, recreation and climate \nregulation (medium confidence).The Pacific EBUS are projected to have calcium carbonate \nundersaturation in surface waters within a few decades RCP8.5 (high confidence); combined \nwith warming and decreasing oxygen levels, this will increase the impacts on shellfish \nlarvae, benthic invertebrates, and demersal fishes (high confidence) and related fisheries and \naquaculture (medium confidence).\u2019\n\u2018The inherent natural variability of EBUS, together with uncertainties in present and future \ntrends in the intensity and seasonality of upwelling, coastal warming and stratification, \nprimary production and biogeochemistry of source waters poses large challenges in \nprojecting the response of EBUS to climate change and to the adaptation of governance of \nbiodiversity conservation and living marine resources in EBUS (high confidence).\u2019\n\u2018Given the high sensitivity of the coupled human\u2013natural EBUS to oceanographic changes,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the potential impact of coastal eutrophication on a major oceanic upwelling system?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide specific information on the potential impact of coastal eutrophication on a major oceanic upwelling system."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: confidence); combined \nwith warming and decreasing oxygen levels, this will increase the impacts on shellfish \nlarvae, benthic invertebrates, and demersal fishes (high confidence) and related fisheries and \naquaculture (medium confidence).\u2019\n\u2018The inherent natural variability of EBUS, together with uncertainties in present and future \ntrends in the intensity and seasonality of upwelling, coastal warming and stratification, \nprimary production and biogeochemistry of source waters poses large challenges in \nprojecting the response of EBUS to climate change and to the adaptation of governance of \nbiodiversity conservation and living marine resources in EBUS (high confidence).\u2019\n\u2018Given the high sensitivity of the coupled human\u2013natural EBUS to oceanographic changes, \nthe future sustainable delivery of key ecosystem services from EBUS is at risk under climate \nchange; those that are most at risk in the 21st\u00a0century include fisheries ( high confidence), \naquaculture (medium confidence), coastal tourism (low confidence) and climate regulation \n(low confidence).\u2019\n\u2018For vulnerable human communities with a strong dependence on EBUS services and \nlow adaptive capacity, such as those along the Canary Current system, unmitigated \nclimate-change effects on EBUS (complicated by other non-climatic stresses such as social \nunrest) have a high risk of altering their development pathways (high confidence).\u2019\nQuery: What is the potential impact of coastal eutrophication on a major oceanic upwelling system?\nOriginal Answer: The context does not provide specific information on the potential impact of coastal eutrophication on a major oceanic upwelling system.\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide specific information on the potential impact of coastal eutrophication on a major oceanic upwelling system."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 407\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThe interplay between the abruptness, intensity, duration, magnitude \nand reoccurrence of extreme events may alter or prevent evolutionary \nresponses (e.g., adaptation) to climate change and the potential for \nacclimation to extreme conditions such as MHWs (Cheung and Fr\u00f6licher, \n2020; Coleman et\u00a0al., 2020a; Gurgel et\u00a0al., 2020; Gruber et\u00a0al., 2021).Some studies have documented higher phenotypic plasticity and \ntolerance to ocean warming and acidification in marine invertebrates \n(Dam, 2013; Kelly et\u00a0 al., 2013; Pespeni et\u00a0 al., 2013; Gait\u00e1n-Espitia \net\u00a0al., 2017a; Vargas et\u00a0al., 2017; Li et\u00a0al., 2018a), seaweeds (Noisette \net\u00a0 al., 2013; Padilla-Gami\u00f1o et\u00a0 al., 2016; Machado Monteiro et\u00a0 al., \n2019) and fish (medium confidence) (Sandoval-Castillo et\u00a0 al., 2020; \nEnbody et\u00a0 al., 2021) living in coastal zones characterised by strong \ntemporal fluctuations in temperature, pH, pCO 2, light and nutrients.For these populations, strong directional selection with intense and \nhighly fluctuating conditions may have favoured local adaptation \nand increased tolerance to environmental stress (low confidence, low \nevidence) (Hong and Shurin, 2015; Gait\u00e1n-Espitia et\u00a0al., 2017b; Li et\u00a0al., \n2018a).Other mechanisms acting within and across generations can influence \nselection and inter-population tolerances to environmental and \nclimate-induced drivers.For instance, transgenerational effects and/or \ndevelopmental acclimation, both \u2018carry-over effects\u2019 (where the early-\nlife environment affects the expression of traits in later life stages or \ngenerations), can influence within- and cross-generational changes \nin the tolerances of marine organisms (medium confidence) to ocean \nwarming (Balogh and Byrne, 2020) and acidification (Parker et\u00a0al., 2012).Over longer time scales, increasing tolerance to these drivers may be \nmediated by mechanisms such as transgenerational plasticity (Murray \net\u00a0al., 2014), leading to locally adapted genotypes as seen in bivalves \n(Thomsen et\u00a0al., 2017), annelids (Rodr\u00edguez-Romero et\u00a0al., 2016; Thibault \net\u00a0al., 2020), corals (Putnam et\u00a0al., 2020) and coralline algae (Cornwall \net\u00a0 al., 2020).However, transgenerational plasticity is species specific \n(Byrne et\u00a0al., 2020; Thibault et\u00a0al., 2020) and, depending on the rate and \nmagnitude of environmental change, it may either be insufficient for \nevolutionary rescue (Morgan et\u00a0al., 2020) or could induce maladaptive \nresponses (i.e., reduced fitness) in marine organisms exposed to multiple \ndrivers (medium confidence, low evidence) (Figure\u00a0 3.11; Griffith and \nGobler, 2017; Parker et\u00a0al., 2017; Byrne et\u00a0al., 2020).Acclimation to environmental pressures and climate change via \nphenotypic plasticity (Section\u00a0 3.3.3; Collins et\u00a0 al., 2020) enables \nspecies to undergo niche shifts such that their present-day climatic \nniche is altered to incorporate new or shifted conditions (Fox et\u00a0al., \n2019).Although plasticity provides an adaptive mechanism, it is \nunlikely to provide a long-term solution for species undergoing \nsustained directional environmental change (e.g., global warming) \n(medium confidence) (Fox et\u00a0 al., 2019; Gait\u00e1n-Espitia and Hobday, \n2021).Beyond the limits for plastic responses (Figure\u00a0 3.9; DeWitt \net\u00a0al., 1998; Valladares et\u00a0al., 2007), genetic adjustments are required \nto persist in a changing world (Figure\u00a0 3.11; Fox et\u00a0 al., 2019).The \nability of species and populations to undergo these adjustments (i.e., \nadaptive evolution) depends on extrinsic factors including the rate \nand magnitude of environmental change (important determinants \nof the strength and form of selection; Hoffmann and Sgr\u00f2, 2011;\n\npage_label: 441\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n\u2018The projected intensity of species \nturnover is lower under low-emission scenarios (high confidence).\u2019\n\u2018Projections from multiple fish species distribution models show hotspots of decrease in species richness in the Indo-Pacific \nregion, and semi-enclosed seas such as the Red Sea and Persian Gulf (medium evidence, high agreement).In addition, \ngeographic barriers, such as land, [bounding the] poleward species range edge in semi-enclosed seas or low-oxygen water \nin deeper waters are projected to limit range shifts, resulting in a larger relative decrease in species richness (medium \nconfidence).\u2019\n\u2018The large variation in sensitivity between different zooplankton taxa to future conditions of warming and ocean acidification \nsuggests elevated risk on community structure and inter-specific interactions of zooplankton in the 21st\u00a0century (medium \nconfidence).\u2019\nMarine organism redistributions projected under RCP4.5 and RCP8.5 \ninclude extirpations and range contractions in the tropics, strongly \ndecreasing tropical biodiversity, and range expansions at higher \nlatitudes, associated with increased diversity and homogenisation \nof marine communities (Figure\u00a0 3.18b).Under continuing climate \nchange, the projected loss of biodiversity may ultimately threaten \nmarine ecosystem stability (medium confidence) (Albouy et\u00a0al., 2020; \nNagelkerken et\u00a0 al., 2020; Henson et\u00a0 al., 2021), altering both the \nfunctioning and structure of marine ecosystems and thus affecting \nservice provisioning (medium confidence) (Section\u00a03.5; Ibarbalz et\u00a0al., \n2019; Righetti et\u00a0al., 2019).However, biodiversity observations remain sparse, and statistical and \nmodelling tools can provide conflicting diversity information (e.g., \nRighetti et\u00a0 al., 2019; Dutkiewicz et\u00a0 al., 2020) because correlative \napproaches assume that the modern-day relationship between \nmarine species distribution and environmental conditions remains \nthe same into the future, whereas mechanistic models permit \nmarine species to respond dynamically to changing environmental \nforcing.Moreover, existing global projections of future biodiversity \ndisproportionately focus on the effects sea surface temperature \n(Thomas et\u00a0 al., 2012), typically overlooking other factors such \nas ocean acidification, deoxygenation and nutrient availability \n(Section\u00a03.2.3), and often failing to account for natural adaptation \n(e.g., Section\u00a03.3.4; see Box\u00a03.1; Barton et\u00a0al., 2016; Henson et\u00a0al., \n2021).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the impact of global climate change on genetic diversity within populations and species?\nAnswer: "}, {"role": "assistant", "content": "Global climate change can significantly impact genetic diversity within populations and species. The abruptness, intensity, duration, magnitude, and reoccurrence of extreme events may alter or prevent evolutionary responses such as adaptation and acclimation to extreme conditions. Some marine organisms have shown higher phenotypic plasticity and tolerance to ocean warming and acidification, especially those living in coastal zones with strong temporal fluctuations in environmental conditions. However, this plasticity may not provide a long-term solution for species undergoing sustained directional environmental change, such as global warming. Beyond the limits for plastic responses, genetic adjustments are required for species to persist in a changing world. The ability of species and populations to undergo these adjustments, or adaptive evolution, depends on extrinsic factors including the rate and magnitude of environmental change. \n\nFurthermore, climate change can lead to species redistributions, including extirpations and range contractions in the tropics, and range expansions at higher latitudes. This can result in decreased biodiversity in tropical regions and increased diversity and homogenisation of marine communities at higher latitudes. The projected loss of biodiversity may ultimately threaten marine ecosystem stability, altering both the functioning and structure of marine ecosystems and thus affecting service provisioning. However, the impact of climate change on genetic diversity can vary greatly depending on the species and specific environmental conditions."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 526\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nMawyer, A. and J.K. Jacka, 2018: Sovereignty, conservation and island \necological futures.Environ.Conserv., 45(3), 238\u2013251, doi:10.1017/\nS037689291800019X.Maximino, C. and T.M.a. de Brito, 2010: Measuring anxiety in zebrafish: a critical \nreview.Behav.Brain Res., 214(2), 157\u2013171, doi:10.1016/j.bbr.2010.05.031.Maxwell, S.L., et\u00a0al., 2020a: Area-based conservation in the twenty-first century.Nature, 586(7828), 217\u2013227, doi:10.1038/s41586-020-2773-z.Maxwell, S.M., K.M.Gjerde, M.G.Conners and L.B.Crowder, 2020b: Mobile \nprotected areas for biodiversity on the high seas.Science, 367(6475), 252\u2013\n254, doi:10.1126/science.aaz9327.Mazaris, A.D., A.S. Kallimanis, S.P .Sgardelis and J.D.Pantis, 2008: Do long-term \nchanges in sea surface temperature at the breeding areas affect the breeding \ndates and reproduction performance of Mediterranean loggerhead turtles?Implications for climate change.J. Exp.Mar.Biol.Ecol., 367(2), 219\u2013226, \ndoi:10.1016/j.jembe.2008.09.025.Mazurais, D., et\u00a0al., 2020: Long-term exposure to near-future ocean acidification \ndoes not affect the expression of neurogenesis- and synaptic transmission-\nrelated genes in the olfactory bulb of European sea bass (Dicentrarchus \nlabrax).J. Comp.Physiol.B, 190(2), 161\u2013167, doi:10.1007/s00360-019-\n01256-2.McArley, T.J., A.J.R.Hickey and N.A.Herbert, 2020: Acute high temperature \nexposure impairs hypoxia tolerance in an intertidal fish.PLoS ONE, 15(4), \ne0231091, doi:10.1371/journal.pone.0231091.McCabe, R.M., et\u00a0 al., 2016: An unprecedented coastwide toxic algal bloom \nlinked to anomalous ocean conditions.Geophys.Res.Lett., 43(19), 10,366\u2013\n310,376, doi:10.1002/2016GL070023.McCarthy, A.H., L.S.Peck, K. A. Hughes and D.C. Aldridge, 2019: Antarctica: \nthe final frontier for marine biological invasions.Glob.Change Biol., 25(7), \n2221\u20132241, doi:10.1111/gcb.14600.McClure, E.C., et\u00a0 al., 2020: Higher fish biomass inside than outside marine \nprotected areas despite typhoon impacts in a complex reefscape.Biol.Conserv., 241, 108354, doi:10.1016/j.biocon.2019.108354.McCormick, L.R.and L.A. Levin, 2017: Physiological and ecological implications \nof ocean deoxygenation for vision in marine organisms.Philos.Trans.Royal Soc.A Math.Phys.Eng.Sci., 375(2102), 20160322, doi:10.1098/\nrsta.2016.0322.McCoy, S.J., et\u00a0 al., 2018: A mineralogical record of ocean change: decadal \nand centennial patterns in the California mussel.Glob.Change Biol., 24(6), \n2554\u20132562, doi:10.1111/gcb.14013.\n\npage_label: 531\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nRoberts, 2017: The structuring role of marine life in open \nocean habitat: importance to international policy.Front.Mar.Sci., 4, 268, \ndoi:10.3389/fmars.2017.00268.O\u2019Neill, B.C., et\u00a0 al., 2016: The Scenario Model Intercomparison Project \n(ScenarioMIP) for CMIP6.Geosci.Model Dev., 9(9), 3461\u20133482, doi:10.5194/\ngmd-9-3461-2016.O\u2019Hara, C.C., M. Frazier and B.S.Halpern, 2021: At-risk marine biodiversity faces \nextensive, expanding, and intensifying human impacts.Science, 372(6537), \n84\u201387, doi:10.1126/science.abe6731.O\u2019Keeffe, J.M., et\u00a0 al., 2020: Stakeholder awareness of climate adaptation in \nthe commercial seaport sector: a case study from Ireland.Mar.Policy, 111, \n102404, doi:10.1016/j.marpol.2016.04.044.OBIS, 2020: Ocean Biodiversity Information System.Intergovernmental \nOceanographic Commission of UNESCO, Accessed 28th December 2021, \nhttps://obis.org/?query=kelp.Obura, D.O., et\u00a0 al., 2021: Integrate biodiversity targets from local to global \nlevels.Science, 373(6556), 746\u2013748, doi:10.1126/science.abh2234.Oca\u00f1a, F .A., D. Pech, N. Sim\u00f5es and I. Hern\u00e1ndez-\u00c1vila, 2019: Spatial \nassessment of the vulnerability of benthic communities to multiple stressors in the Yucatan Continental Shelf, Gulf of Mexico.Ocean Coast.Manag., 181, \n104900, doi:10.1016/j.ocecoaman.2019.104900.Ocean Panel, 2020: Transformations for a Sustainable Ocean Economy: A \nVision for Protection, Production and Prosperity.The High Level Panel for a \nSustainable Ocean Economy, Accessed 28th December 2021, https://www.oceanpanel.org/ocean-action/files/transformations-sustainable-ocean-\neconomy-eng.pdf .(1-19 pp).Ochoa-G\u00f3mez, J.G., et\u00a0al., 2019: Mangrove wetland productivity and carbon \nstocks in an arid zone of the Gulf of California (La Paz Bay, Mexico).For.Ecol.Manag., 442, 135\u2013147, doi:10.1016/j.foreco.2019.03.059.Ogier, E., et\u00a0al., 2020: Responding to climate change: participatory evaluation of \nadaptation options for key marine fisheries in Australia\u2019s South East.Front.Mar.Sci., 7, 97, doi:10.3389/fmars.2020.00097.Ohayon, S., I. Granot and J. Belmaker, 2021: A meta-analysis reveals edge effects \nwithin marine protected areas.Nat.Ecol.Evol., 5, 1301\u20131308, doi:10.1038/\ns41559-021-01502-3.Ojea, E.,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the article in the context information that discusses the effectiveness of marine protected areas?\nAnswer: "}, {"role": "assistant", "content": "The title of the article that discusses the effectiveness of marine protected areas is \"Higher fish biomass inside than outside marine protected areas despite typhoon impacts in a complex reefscape.\""}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: 442, 135\u2013147, doi:10.1016/j.foreco.2019.03.059.Ogier, E., et\u00a0al., 2020: Responding to climate change: participatory evaluation of \nadaptation options for key marine fisheries in Australia\u2019s South East.Front.Mar.Sci., 7, 97, doi:10.3389/fmars.2020.00097.Ohayon, S., I. Granot and J. Belmaker, 2021: A meta-analysis reveals edge effects \nwithin marine protected areas.Nat.Ecol.Evol., 5, 1301\u20131308, doi:10.1038/\ns41559-021-01502-3.Ojea, E., S.E.Lester and D. Salgueiro-Otero, 2020: Adaptation of fishing \ncommunities to climate-driven shifts in target species.One Earth, 2(6), 544\u2013\n556, doi:10.1016/j.oneear.2020.05.012.Ojwang, L., et\u00a0 al., 2017: Assessment of coastal governance for climate \nchange adaptation in Kenya.Earth\u2019s Future, 5(11), 1119\u20131132, \ndoi:10.1002/2017EF000595.Okafor-Yarwood, I., et\u00a0 al., 2020: The blue economy\u2013cultural livelihood\u2013\necosystem conservation triangle: the African experience.Front.Mar.Sci., 7, \n586, doi:10.3389/fmars.2020.00586.Oleson, K.L.L., et\u00a0al., 2018: Charting progress towards system-scale ecosystem \nservice valuation in islands.Environ.Conserv., 45(3), 212\u2013226, doi:10.1017/\nS0376892918000140.\nQuery: What is the title of the article in the context information that discusses the effectiveness of marine protected areas?\nOriginal Answer: The title of the article that discusses the effectiveness of marine protected areas is \"Higher fish biomass inside than outside marine protected areas despite typhoon impacts in a complex reefscape.\"\nNew Answer: "}, {"role": "assistant", "content": "The title of the article discussing the effectiveness of marine protected areas is \"A meta-analysis reveals edge effects within marine protected areas.\""}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 533\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nPetzold, J., et\u00a0al., 2020: Indigenous knowledge on climate change adaptation: \na global evidence map of academic literature.Environ.Res.Lett., 15(11), \n113007, doi:10.1088/1748-9326/abb330.Petzold, J. and A.K.Magnan, 2019: Climate change: thinking small islands \nbeyond Small Island Developing States (SIDS).Clim.Change, 152(1), 145\u2013\n165, doi:10.1007/s10584-018-2363-3.Petzold, J. and B.M.W.Ratter, 2015: Climate change adaptation under a social \ncapital approach \u2013 an analytical framework for small islands.Ocean Coast.Manag., 112, 36\u201343, doi:10.1016/j.ocecoaman.2015.05.003.Pfister, C.A., M. A. Altabet and B.L.Weigel, 2019: Kelp beds and their local \neffects on seawater chemistry, productivity, and microbial communities.Ecology, 100(10), e02798, doi:10.1002/ecy.2798.Pfister, C.A., et\u00a0al., 2016: Historical baselines and the future of shell calcification \nfor a foundation species in a changing ocean.Proc.R. Soc.B, 283(1832), \n20160392, doi:10.1098/rspb.2016.0392.Pham, T.T.T., 2020: Tourism in marine protected areas: Can it be considered as \nan alternative livelihood for local communities?Mar.Policy, 115, 103891, \ndoi:10.1016/j.marpol.2020.103891.Phan, L.K., J. van Thiel de Vries and M.J.F .Stive, 2015: Coastal mangrove \nsqueeze in the Mekong Delta.J.Coast.Res., 31(2), 233\u2013243, doi:10.2112/\nJCOASTRES-D-14-00049.1.Phinney, S.D., J.A.Wortman and D. Bibus, 2009: Oolichan grease: a unique \nmarine lipid and dietary staple of the North Pacific coast.Lipids, 44(1), 47\u2013\n51, doi:10.1007/s11745-008-3243-9.Phlips, E.J., S. Badylak, N.G.Nelson and K.E.Havens, 2020: Hurricanes, El Ni\u00f1o \nand harmful algal blooms in two sub-tropical Florida estuaries: direct and \nindirect impacts.Sci.Rep., 10(1), 1910, doi:10.1038/s41598-020-58771-4.Phrampus, B.J.and M.J. Hornbach, 2012: Recent changes to the Gulf Stream \ncausing widespread gas hydrate destabilization.Nature, 490(7421), 527\u2013\n530, doi:10.1038/nature11528.Phrampus, B.J., M.J. Hornbach, C.D.Ruppel and P .E.Hart, 2014: Widespread gas \nhydrate instability on the upper U.S. Beaufort margin.J. Geophys.Res.Solid \nEarth, 119(12), 8594\u20138609, doi:10.1002/2014JB011290.\n\npage_label: 486\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThe legitimacy of different adaptation strategies depends on local and Indigenous Peoples\u2019 acceptance, which is based on cultural values \n(Adger et\u00a0al., 2017); financial gain cannot compensate for loss of IK or LK \n(Wilson et\u00a0al., 2020b).Palau\u2019s recent goal of shifting seafood consumption \naway from reef fishes (Remengesau Jr., 2019) as well as limiting and \nclosely monitoring the expansion of ecotourism was prompted by the \ncultural importance of protecting these reefs and associated traditional \nfisheries for local consumption, a recognition of the importance of tourism \nand the hazard of climate change (Wabnitz et\u00a0al., 2018a).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the academic literature that presents a global evidence map of indigenous knowledge on climate change adaptation?\nAnswer: "}, {"role": "assistant", "content": "The title of the academic literature that presents a global evidence map of indigenous knowledge on climate change adaptation is \"Indigenous knowledge on climate change adaptation: a global evidence map of academic literature.\""}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 514\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nHauser, D.D.W., et\u00a0 al., 2017: Decadal shifts in autumn migration timing by \nPacific Arctic beluga whales are related to delayed annual sea ice formation.Glob.Change Biol., 23(6), 2206\u20132217, doi:10.1111/gcb.13564.Hauser, D.D.W., K.L.Laidre and H.L.Stern, 2018: Vulnerability of Arctic marine \nmammals to vessel traffic in the increasingly ice-free Northwest Passage \nand Northern Sea Route.Proc.Natl.Acad.Sci.U.S.A., 115(29), 7617\u20137622, \ndoi:10.1073/pnas.1803543115.Havens, K.E., et\u00a0al., 2019: Dynamics of cyanobacteria blooms are linked to the \nhydrology of shallow Florida lakes and provide insight into possible impacts \nof climate change.Hydrobiologia, 829(1), 43\u201359, doi:10.1007/s10750-017-\n3425-7.Hawkins, E. and R. Sutton, 2012: Time of emergence of climate signals.Geophys.Res.Lett., 39(1), L1702, doi:10.1029/2011GL050087.Hay, C.C., E. Morrow, R.E.Kopp and J.X.Mitrovica, 2015: Probabilistic \nreanalysis of twentieth-century sea-level rise.Nature, 517(7535), 481\u2013484, \ndoi:10.1038/nature14093.Hayashida, H., R.J. Matear and P .G.Strutton, 2020: Background nutrient \nconcentration determines phytoplankton bloom response to marine \nheatwaves.Glob.Change Biol., 26(9), 4800\u20134811, doi:10.1111/gcb.15255.Hazen, E.L., et\u00a0al., 2018: A dynamic ocean management tool to reduce bycatch \nand support sustainable fisheries.Sci.Adv., 4(5), eaar3001, doi:10.1126/\nsciadv.aar3001.He, Q. and B.R.Silliman, 2019: Climate change, human impacts, and coastal \necosystems in the Anthropocene.Curr.Biol., 29(19), R1021\u2013R1035, \ndoi:10.1016/j.cub.2019.08.042.Hebbeln, D., R. d. C. Portilho-Ramos, C. Wienberg and J. Titschack, 2019: The \nfate of cold-water corals in a changing world: a geological perspective.Front.Mar.Sci., 6, 119, doi:10.3389/fmars.2019.00119.Hebbeln, D., et\u00a0al., 2020: Cold-water coral reefs thriving under hypoxia.Coral \nReefs, 39(4), 853\u2013859, doi:10.1007/s00338-020-01934-6.Heckwolf, M.J., et\u00a0 al., 2021: From ecosystems to socio-economic benefits: a \nsystematic review of coastal ecosystem services in the Baltic Sea.Sci.Total \nEnviron., 755, 142565, doi:10.1016/j.scitotenv.2020.142565.Heffernan, O., 2019: Seabed mining is coming\u2014bringing mineral riches and \nfears of epic extinctions.Nature, 571(7766), 465\u2013468, doi:10.1038/d41586-\n019-02242-y.\n\npage_label: 500\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nLewis, 2001: Ourigan: wealth of the northwest coast.Or.Hist.Q., 102(2), 127\u2013157.Byrd, G.V., W.J.Sydeman, H.M. Renner and S. Minobe, 2008: Responses of \npiscivorous seabirds at the Pribilof Islands to ocean climate.Deep Sea \nRes.Part II Top.Stud.Oceanogr., 55(16\u201317), 1856\u20131867, doi:10.1016/j.dsr2.2008.04.015.Byrne, M., S.A. Foo, P .M.Ross and H.M. Putnam, 2020: Limitations of cross- \nand multigenerational plasticity for marine invertebrates faced with global \nclimate change.Glob.Change Biol., 26(1), 80\u2013102, doi:10.1111/gcb.14882.Byrne, M., et\u00a0al., 2013: Vulnerability of the calcifying larval stage of the Antarctic \nsea urchin Sterechinus neumayeri to near-future ocean acidification and \nwarming.Glob.Change Biol., 19(7), 2264\u20132275, doi:10.1111/gcb.12190.Cabral, H., V. Fonseca, T. Sousa and M. Costa Leal, 2019: Synergistic effects of \nclimate change and marine pollution: an overlooked interaction in coastal \nand estuarine areas.Int.J. Environ.Res.Public Health, 16(15), 2737, \ndoi:10.3390/ijerph16152737.Cabr\u00e9, A., I. Marinov, R. Bernardello and D. Bianchi, 2015: Oxygen minimum \nzones in the tropical Pacific across CMIP5 models: mean state differences and \nclimate change trends.Biogeosciences, 12(18), 5429\u20135454, doi:10.5194/bg-\n12-5429-2015.Cabrerizo, M.J., et\u00a0 al., 2021: Temperature fluctuation attenuates the effects \nof warming in estuarine microbial plankton communities.Front.Mar.Sci., \n8(351), 656282, doi:10.3389/fmars.2021.656282.Cael, B.B., K. Bisson and M.J.Follows, 2017: How have recent temperature \nchanges affected the efficiency of ocean biological carbon export?Limnol.Oceanogr.Lett., 2(4), 113\u2013118, doi:10.1002/lol2.10042.Cahoon, D.R., K.L.McKee and J.T.Morris, 2021: How plants influence resilience \nof salt marsh and mangrove wetlands to sea-level rise.Estuaries Coasts, 44, \n883\u2013898, doi:10.1007/s12237-020-00834-w.\nCai, W.-J., et\u00a0 al., 2021: Natural and anthropogenic drivers of acidification in \nlarge estuaries.Annu.Rev.Mar.Sci., 13(1), 23\u201355, doi:10.1146/annurev-\nmarine-010419-011004.Cai, W.-J., et\u00a0al., 2011: Acidification of subsurface coastal waters enhanced by \neutrophication.Nat.Geosci., 4(11), 766\u2013770,\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: How plants influence resilience \nof salt marsh and mangrove wetlands to sea-level rise.Estuaries Coasts, 44, \n883\u2013898, doi:10.1007/s12237-020-00834-w.\nCai, W.-J., et\u00a0 al., 2021: Natural and anthropogenic drivers of acidification in \nlarge estuaries.Annu.Rev.Mar.Sci., 13(1), 23\u201355, doi:10.1146/annurev-\nmarine-010419-011004.Cai, W.-J., et\u00a0al., 2011: Acidification of subsurface coastal waters enhanced by \neutrophication.Nat.Geosci., 4(11), 766\u2013770, doi:10.1038/ngeo1297.Cai, W.-J., et\u00a0al., 2020: Controls on surface water carbonate chemistry along \nNorth American ocean margins.Nat.Commun., 11(1), 2691, doi:10.1038/\ns41467-020-16530-z.Calder\u00f3n-Li\u00e9vanos, S., et\u00a0al., 2019: Survival and respiration of green abalone \n(Haliotis fulgens) facing very short-term marine environmental extremes.Mar.Freshw.Behav.Physiol., 52(1), 1\u201315, doi:10.1080/10236244.2019.16\n07734.Calosi, P ., et\u00a0al., 2017: Regional adaptation defines sensitivity to future ocean \nacidification.Nat.Commun., 8(1), 13994, doi:10.1038/ncomms13994.Cambers, G. and S.P .\nQuery: What is the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics?\nOriginal Answer: The context does not provide information on the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics.\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide information on the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 522\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nLawrence, J., et\u00a0al., 2018: National guidance for adapting to coastal hazards \nand sea-level rise: anticipating change, when and how to change pathway.Environ.Sci.Policy, 82, 100\u2013107, doi:10.1016/j.envsci.2018.01.012.Layton, C., et\u00a0al., 2020: Kelp forest restoration in Australia.Front.Mar.Sci., 7, \n74, doi:10.3389/fmars.2020.00074.Le Bris, A., et\u00a0al., 2018: Climate vulnerability and resilience in the most valuable \nNorth American fishery.Proc.Natl.Acad.Sci.U.S.A., 115(8), 1831\u20131836, \ndoi:10.1073/pnas.1711122115.Le Bris, N. and L.A. Levin, 2020: Climate change cumulative impacts on deep-\nsea ecosystems.In: Natural Capital and Exploitation of the Deep Ocean.Oxford University Press, Oxford.ISBN 978-0198841654.Le Corre, N., P .Pepin, G. Han and Z. Ma, 2021: Potential impact of climate \nchange on northern shrimp habitats and connectivity on the Newfoundland \nand Labrador continental shelves.Fish.Oceanogr., 30(3), 331\u2013347, \ndoi:10.1111/fog.12524.Le Cozannet, G., et\u00a0 al., 2019: Quantifying uncertainties of sandy shoreline \nchange projections as sea level rises.Sci.Rep., 9, 42, doi:10.1038/s41598-\n018-37017-4.Le Cozannet, G., et\u00a0al., 2017: Sea level change and coastal climate services: the \nway forward.J. Mar.Sci.Eng., 5(4), 49, doi:10.3390/jmse5040049.Le Noha\u00efc, M., et\u00a0al., 2017: Marine heatwave causes unprecedented regional \nmass bleaching of thermally resistant corals in northwestern Australia.Sci.Rep., 7(1), 14999, doi:10.1038/s41598-017-14794-y.Le Qu\u00e9r\u00e9, C., et\u00a0al., 2016: Role of zooplankton dynamics for Southern Ocean \nphytoplankton biomass and global biogeochemical cycles.Biogeosciences, \n13(14), 4111\u20134133, doi:10.5194/bg-13-4111-2016.Leadbetter, A., J. Silke and C. Cusack, 2018: Creating a Weekly Harmful Algal \nBloom Bulletin.Best Practice Description Document.Institute, M., Galway, \nIreland, http://hdl.handle.net/10793/1344.Accessed 2018-04-10 .(59 pp).Leal, M.C.and R. Calado, 2015: Marine natural products: biodiscovery, \nbiodiversity, and bioproduction.In: Bioactive Natural Products: Chemistry \nand Biology [Brahmachari, G.(ed.)].Wiley Blackwell, Weinheim, Germany, pp.473\u2013490.ISBN 978-3527684403.Leary, D., 2019: Agreeing to disagree on what we have or have not agreed on: \nthe current state of play of the BBNJ negotiations on the status of marine\n\npage_label: 505\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n505Oceans and Coastal Ecosystems and Their Services Chapter 3\nDas, I., et\u00a0 al., 2020: Effects of climate change and management policies on \nmarine fisheries productivity in the north-east coast of India.Sci.Total \nEnviron., 724, 138082, doi:10.1016/j.scitotenv.2020.138082.Dasgupta, S., et\u00a0al., 2019: Quantifying the protective capacity of mangroves \nfrom storm surges in coastal Bangladesh.PLoS ONE, 14(3), e0214079, \ndoi:10.1371/journal.pone.0214079.Dave, D. and W. Routray, 2018: Current scenario of Canadian fishery and \ncorresponding underutilized species and fishery byproducts: a potential \nsource of omega-3 fatty acids.J.Clean.Prod., 180, 617\u2013641, doi:10.1016/j.jclepro.2018.01.091.David, C.G.and T. Schlurmann, 2020: Hydrodynamic drivers and morphological \nresponses on small coral islands\u2014the Thoondu Spit on Fuvahmulah, the \nMaldives.Front.Mar.Sci., 7(885), 538675, doi:10.3389/fmars.2020.538675.Davidson, K., et\u00a0al., 2021: HABreports: online early warning of harmful algal \nand biotoxin risk for the scottish shellfish and finfish aquaculture industries.Front.Mar.Sci., 8(350), 631732, doi:10.3389/fmars.2021.631732.Davies, T.W., J.P .Duffy, J. Bennie and K.J.Gaston, 2014: The nature, extent, and \necological implications of marine light pollution.Front.Ecol.Environ., 12(6), \n347\u2013355, doi:10.1890/130281.Davis, B.J.K., et\u00a0 al., 2019: Vibrio parahaemolyticus in the Chesapeake Bay: \noperational in situ prediction and forecast models can benefit from inclusion \nof lagged water quality measurements.Appl.Environ.Microbiol., 85(17), \ne1007\u20131019, doi:10.1128/AEM.01007-19.Davis, G.E., et\u00a0 al., 2020: Exploring movement patterns and changing \ndistributions of baleen whales in the western North Atlantic using a decade \nof passive acoustic data.Glob.Change Biol., 26(9), 4812\u20134840, doi:10.1111/\ngcb.15191.Dawson, J., et\u00a0al., 2020: Infusing Inuit and local knowledge into the Low Impact \nShipping Corridors: an adaptation to increased shipping activity and climate \nchange in Arctic Canada.Environ.Sci.Policy, 105, 19\u201336, doi:10.1016/j.envsci.2019.11.013.Dawson, J., E.J.Stewart, M. E. Johnston and C.J.Lemieux, 2016: Identifying \nand evaluating adaptation strategies for cruise tourism in Arctic Canada.J.Sustain.Tour., 24(10), 1425\u20131441, doi:10.1080/09669582.2015.1125358.Day, J.W.and J.M.Rybczyk, 2019: Chapter\u00a036\u2014global change impacts on the \nfuture of coastal systems: perverse interactions among climate change, \necosystem degradation, energy scarcity, and population.In: Coasts and \nEstuaries [Wolanski, E., J.W.Day, M. Elliott and\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title and publication year of the report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on a report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: J., E.J.Stewart, M. E. Johnston and C.J.Lemieux, 2016: Identifying \nand evaluating adaptation strategies for cruise tourism in Arctic Canada.J.Sustain.Tour., 24(10), 1425\u20131441, doi:10.1080/09669582.2015.1125358.Day, J.W.and J.M.Rybczyk, 2019: Chapter\u00a036\u2014global change impacts on the \nfuture of coastal systems: perverse interactions among climate change, \necosystem degradation, energy scarcity, and population.In: Coasts and \nEstuaries [Wolanski, E., J.W.Day, M. Elliott and R.Ramachandran(eds.)].Elsevier, pp.621\u2013639.ISBN 978-0128140031.\nde la Hoz, C.F ., E. Ramos, A. Puente and J.A.Juanes, 2019: Climate change \ninduced range shifts in seaweeds distributions in Europe.Mar.Environ.Res., \n148, 1\u201311, doi:10.1016/j.marenvres.2019.04.012.\nQuery: What is the title and publication year of the report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries?\nOriginal Answer: The context does not provide information on a report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries.\nNew Answer: "}, {"role": "assistant", "content": "The context does not provide information on a report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 499\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBrun, P ., et\u00a0al., 2019: Climate change has altered zooplankton-fuelled carbon \nexport in the North Atlantic.Nat.Ecol.Evol., 3(3), 416\u2013423, doi:10.1038/\ns41559-018-0780-3.Bruno, J.F ., et\u00a0al., 2018: Climate change threatens the world's marine protected \nareas.Nat.Clim.Change, 8(6), 499\u2013503, doi:10.1038/s41558-018-0149-2.Bruno, J.F ., I.M.C\u00f4t\u00e9 and L.T.Toth, 2019: Climate change, coral loss, and the \ncurious case of the parrotfish paradigm: why don't marine protected areas \nimprove reef resilience?Annu.Rev.Mar.Sci., 11(1), 307\u2013334, doi:10.1146/\nannurev-marine-010318-095300.Bryan-Brown, D.N., et\u00a0al., 2020: Global trends in mangrove forest fragmentation.Sci.Rep., 10(1), 7117, doi:10.1038/s41598-020-63880-1.Bryndum-Buchholz, A., et\u00a0 al., 2019: Twenty-first-century climate change \nimpacts on marine animal biomass and ecosystem structure across ocean \nbasins.Glob.Change Biol., 25(2), 459\u2013472, doi:10.1111/gcb.14512.Bryndum-Buchholz, A., D.P .Tittensor and H.K.Lotze, 2021: The status of \nclimate change adaptation in fisheries management: policy, legislation and \nimplementation.Fish Fish., 22(6), 1248\u20131273, doi:10.1111/faf.12586.Bucci, A. F ., A.C. Thomas and I. Cetini\u0107, 2020: Interannual variability in \nthe thermal habitat of Alexandrium catenella in the Bay of Fundy and \nthe implications of climate change.Front.Mar.Sci., 7(1060), 587990, \ndoi:10.3389/fmars.2020.587990.Buchanan, J.R., et\u00a0al., 2016a: Living on the edge: vulnerability of coral-dependent \nfishes in the Gulf.Mar.Pollut.Bull., 105(2), 480\u2013488, doi:10.1016/j.marpolbul.2015.11.033.Buchanan, M.K., R.E.Kopp, M. Oppenheimer and C. Tebaldi, 2016b: Allowances \nfor evolving coastal flood risk under uncertain local sea-level rise.Clim.Change, 137(3), 347\u2013362, doi:10.1007/s10584-016-1664-7.Buckley, L.B.and R.B.Huey, 2016: How extreme temperatures impact organisms \nand the evolution of their thermal tolerance.Integr.Comp.Biol., 56(1), 98\u2013\n109, doi:10.1093/icb/icw004.Buerger, P ., et\u00a0 al., 2020: Heat-evolved microalgal symbionts increase coral \nbleaching tolerance.Sci.Adv., 6(20), eaba2498, doi:10.1126/sciadv.aba2498.Buffington, K.J., A.C. Goodman, C.M.Freeman and K.M.Thorne, 2020: Testing the \ninteractive effects of flooding and salinity on tidal marsh plant productivity.Aquat.Bot., 164, 103231, doi:10.1016/j.aquabot.2020.103231.\n\npage_label: 382\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nMultiple \nlines of evidence suggest that climate-change responses are very \nlikely to amplify up marine food webs over large regions of the ocean.Modest projected declines in global phytoplankton biomass translate \ninto larger declines of total animal biomass (by 2080\u20132099 relative \nto 1995\u20132014) ranging from (mean\u00a0\u00b1\u00a0 very likely range) \u22125.7\u00a0\u00b1\u00a04.1% \nto \u221215.5\u00a0\u00b1\u00a08.5% under SSP1-2.6 and SSP5-8.5, respectively (medium \nconfidence).Projected declines in upper-ocean nutrient concentrations, \nlikely associated with increases in stratification, will reduce carbon \nexport flux to the mesopelagic and deep-sea ecosystems (medium \nconfidence).This will lead to a decline in the biomass of abyssal meio- \nand macrofauna (by 2081\u20132100 relative to 1995\u20132014) by \u22129.8% and \n\u221213.0% under SSP1-2.6 and SSP5-8.5, respectively (limited evidence).By 2100, 18.8\u00a0\u00b1\u00a019.0% to 38.9\u00a0\u00b1\u00a09.4% of the ocean will very likely \nundergo a change of more than 20 d (advances and delays) in the \nstart of the phytoplankton growth period under SSP1-2.6 and SSP5-\n8.5, respectively (low confidence).This altered timing increases the risk \nof temporal mismatches between plankton blooms and fish spawning \nseasons (medium to high confidence) and increases the risk of fish-\nrecruitment failure for species with restricted spawning locations, \nespecially in mid-to-high latitudes of the Northern Hemisphere (low \nconfidence).Projected range shifts among marine species (medium \nconfidence) suggest extirpations and strongly decreasing tropical \nbiodiversity.At higher latitudes, range expansions will drive increased \nhomogenisation of biodiversity.The projected loss of biodiversity \nultimately threatens marine ecosystem resilience (medium to high \nconfidence), with subsequent effects on service provisioning (medium \nto high confidence).{3.2.2.3, 3.4.2.10, 3.4.3.1\u20133.4.3.5, 3.5, WGI AR6 \nSection\u00a02.3.4.2.3}\nRisks from sea level rise for coastal ecosystems and people \nare very likely to increase tenfold well before 2100 without \nadaptation and mitigation action as agreed by Parties to the Paris \nAgreement (very high confidence).Sea level rise under emission \nscenarios that do not limit warming to 1.5\u00b0C will increase the risk of \ncoastal erosion and submergence of coastal land (high confidence), \nloss of coastal habitat and ecosystems (high confidence) and worsen \nsalinisation of groundwater (high confidence), compromising coastal \necosystems and livelihoods (high confidence).Under SSP1-2.6, \nmost coral reefs (very high confidence), mangroves (likely, medium \nconfidence) and salt marshes (likely, medium confidence) will be \nunable to keep up with sea level rise by 2050, with ecological impacts \nescalating rapidly beyond 2050, especially for scenarios coupling high \nemissions with aggressive coastal development (very high confidence).Resultant decreases in natural shoreline protection will place \nincreasing numbers of people at risk (very high\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context, which study found an increase in ocean carbon export in the Sargasso Sea linked to climate variability?\nAnswer: "}, {"role": "assistant", "content": "The provided context does not mention a specific study that found an increase in ocean carbon export in the Sargasso Sea linked to climate variability."}]} +{"messages": [{"role": "user", "content": "You are an expert Q&A system that stricly operates in two modeswhen refining existing answers:\n1. **Rewrite** an original answer using the new context.\n2. **Repeat** the original answer if the new context isn't useful.\nNever reference the original answer or context directly in your answer.\nWhen in doubt, just repeat the original answer.New Context: will increase the risk of \ncoastal erosion and submergence of coastal land (high confidence), \nloss of coastal habitat and ecosystems (high confidence) and worsen \nsalinisation of groundwater (high confidence), compromising coastal \necosystems and livelihoods (high confidence).Under SSP1-2.6, \nmost coral reefs (very high confidence), mangroves (likely, medium \nconfidence) and salt marshes (likely, medium confidence) will be \nunable to keep up with sea level rise by 2050, with ecological impacts \nescalating rapidly beyond 2050, especially for scenarios coupling high \nemissions with aggressive coastal development (very high confidence).Resultant decreases in natural shoreline protection will place \nincreasing numbers of people at risk (very high confidence).The ability \nto adapt to current coastal impacts, cope with future coastal risks and \nprevent further acceleration of sea level rise beyond 2050 depends on \nimmediate implementation of mitigation and adaptation actions (very \nhigh confidence).{3.4.2.1, 3.4.2.4, 3.4.2.5, 3.4.2.6, 3.5.5.3, Cross-\nChapter Box\u00a0SLR in Chapter\u00a03}\nQuery: Question: According to the provided context, which study found an increase in ocean carbon export in the Sargasso Sea linked to climate variability?\nOriginal Answer: The provided context does not mention a specific study that found an increase in ocean carbon export in the Sargasso Sea linked to climate variability.\nNew Answer: "}, {"role": "assistant", "content": "The provided context does not mention a specific study that found an increase in ocean carbon export in the Sargasso Sea linked to climate variability."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 503\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nChange, 165(3), 66, doi:10.1007/s10584-021-03097-x.\n\npage_label: 507\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nChange, 1(3), 165\u2013169, \ndoi:10.1038/nclimate1122.\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What is the title of the article mentioned in the context information?\nAnswer: "}, {"role": "assistant", "content": "The context information does not provide the title of the article."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 444\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n444Chapter 3 Oceans and Coastal Ecosystems and Their Services\nloss is decreasing some polar bear populations while others remain stable, likely related to past harvesting history, regional differences in \nsea ice phenology and ecosystem productivity (Hamilton and Derocher, 2019; Moln\u00e1r et\u00a0al., 2020). Nevertheless, even under an intermediate \nemission scenario RCP4.5, increasing ice-free periods will likely reduce both recruitment and adult survival across most polar bear \npopulations over the next four decades, threatening their existence (medium confidence) (see Figure\u00a0Box\u00a03.2.2; Moln\u00e1r et\u00a0al., 2020).\nClimate change is affecting marine food-web dynamics (high confidence) (Sections\u00a03.4.2, 3.4.3), and the vulnerability and adaptive \ncapacity of marine birds and mammals to such changes is linked to the species\u2019 breeding and feeding ecology. Higher-vulnerability \nspecies include central-place foragers (confined to, for example, breeding colonies fixed in space), diet and habitat specialists, and species \nwith restricted distributions such as marine mammal populations in SES (medium confidence) (McMahon et\u00a0al., 2019; Ropert-Coudert \net\u00a0al., 2019; Albouy et\u00a0al., 2020; Grose et\u00a0al., 2020; Sydeman et\u00a0al., 2021). Surface-feeding and piscivorous marine birds appear to be more \nvulnerable to food-web changes than diving seabirds and planktivorous seabirds (medium confidence) (Sydeman et\u00a0al., 2021). During \nthe 2014\u20132015 Pacific heatwave, around 1\u00a0million piscivorous common murres died along a 1500 km coastal stretch in the Pacific USA \ndue to reduced prey availability (Jones et\u00a0al., 2018b; Piatt et\u00a0al., 2020). Marine birds are vulnerable to phenological shifts in food-web \ndynamics, as they have limited phenotypic plasticity of reproductive timing, with potentially little scope for evolutionary adaptation \n(medium confidence) (Keogan et\u00a0al., 2018), although changes in reproduction timing are observed in several species (Section\u00a03.4.4.1; \nSydeman et\u00a0al., 2015; Descamps et\u00a0al., 2019; Sauve et\u00a0al., 2019). There is limited evidence of marine mammals\u2019 capacity to adapt to \nshifting phenologies, but observed responses include changes in the onset of migrations, moulting and breeding (Section\u00a03.4.4.1; Ramp \net\u00a0al., 2015; Hauser et\u00a0al., 2017; Beltran et\u00a0al., 2019; Bowen et\u00a0al., 2020; Szesciorka et\u00a0al., 2020).\nModelled risk timelines for demographic impacts on circumpolar polar bear subpopulations\nand associated confidence assessments, due to extended fasting periods with loss of sea ice\n(a) RCP4.5 (b) RCP8.5\nChukchi SeaWestern Hudson Bay\nSouthern Hudson bay\nDavis Strait\nFoxe Basin\nBaffin Bay\nSouthern Beaufort Sea\nLaptev Sea\nKara Sea\nBarents Sea\nEast Greenland Sea\nNorthern Beaufort Sea\nQueen Elizabeth Islands\n1980 2000 2020 2040 2060 2080 1980 2000 2020 2040 2060 2080\nRisk of demographic effects:\nCub recruitment\nAdult male survival\nAdult female survival\nVery likely Likely Possible Inevitable\nFigure\u00a0 Box\u00a0 3.2.2 | \u00a0 Modelled risk timelines for demographic impacts on circumpolar polar bear subpopulations, and associated confidence \nassessments, due to extended fasting periods with loss of sea ice.\u00a0Years of first impact on cub recruitment (yellow), adult male survival (blue) and adult female \nsurvival (red) are shown for the (left) RCP4.5 and (right) RCP8.5. (Data from Moln\u00e1r et\u00a0al., 2020).Box 3.2 (continued)\n\npage_label: 432\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThere is high agreement and robust evidence \nthat phytoplankton species will change because of sea ice retreat and related changes in \ntemperature and radiation, and this is very likely to benefit fisheries productivity [in the \nArctic spring bloom system].\u2019\n\u2018\u2018Unique and threatened systems\u2019 (RFC1), [including Arctic and coral reefs], display a \ntransition from high to very high risk of transition at temperatures between 1.5\u00b0C and 2\u00b0C \nof global warming, as opposed to at 2.6\u00b0C of global warming in AR5 (high confidence).\u2019\nSROCC (Bindoff et\u00a0al., 2019a)\nClimate-induced changes in seasonal sea ice extent and thickness as well as ocean \nstratification are altering marine primary production ( high confidence), with impacts on \necosystems (medium confidence).Changes in the timing, duration and magnitude of primary production have occurred in both \npolar oceans, with marked regional or local variability (high confidence).In both polar regions, climate-induced changes in ocean and sea ice conditions have \nexpanded the range of temperate species and contracted the range of polar fish and \nice-associated species (high confidence).Ocean acidification will affect several key Arctic species (medium confidence).Future climate-induced changes in the polar oceans, sea ice, snow and permafrost will \ndrive habitat and biome shifts, with associated changes in the ranges and abundance of \necologically important species (medium confidence).Projected range expansion of sub-Arctic marine species will increase pressure for high-Arctic \nspecies (medium confidence), with regionally variable impacts.Both polar oceans will be increasingly affected by CO 2 uptake, causing corrosive conditions \nfor calcium carbonate shell-producing organisms (high confidence), with associated impacts \non marine organisms and ecosystems (medium confidence).The projected effects of climate-induced stressors on polar marine ecosystems present risks \nfor commercial and subsistence fisheries, with implications for regional economies, cultures \nand the global supply of fish, shellfish, and Antarctic krill (high confidence).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the potential impacts of increasing ice-free periods on polar bear populations according to the report?\nAnswer: "}, {"role": "assistant", "content": "Increasing ice-free periods are likely to reduce both recruitment and adult survival across most polar bear populations over the next four decades. This could potentially threaten their existence. The impacts are related to extended fasting periods due to the loss of sea ice. The first impacts are expected on cub recruitment, followed by adult male survival and then adult female survival."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 398\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n398Chapter 3 Oceans and Coastal Ecosystems and Their Services\nProjected trends across open-ocean systems\n(a)\n(b)\n(c)\n(d)\nFigure\u00a03.6 | \u00a0Projected trends across open-ocean systems. Projected annual and global (a)\u00a0average warming, (b)\u00a0acidification, (c)\u00a0changes in dissolved oxygen concentrations \nand (d)\u00a0changes in nitrate (NO 3) concentrations for four open-ocean systems, including the epipelagic (0\u2013200 m depth), mesopelagic (200\u20131000 m), bathypelagic (>1000 m) \ndomains and deep benthic waters (>200 m). All projections are based on Coupled Model Intercomparison Project\u00a06 models and for three Shared Socioeconomic Pathways (SSPs): \nSSP1-2.6, SSP2-4.5 and SSP5-8.5 (Kwiatkowski et\u00a0al., 2020). Anomalies in the near-term (2020\u20132041), mid-term (2041\u20132060) and long-term (2081\u20132100) are all relative to \n1985\u20132014. Error bars represent very likely ranges.\n\npage_label: 397\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nThese declines in nitrate concentration are \ngreater than simulated by the CMIP5 models in their RCP analogues, \na likely consequence of enhanced surface warming and stratification \nin CMIP6 models (Figure\u00a03.5; Kwiatkowski et\u00a0al., 2020).It is concluded that the surface ocean will encounter reduced nitrate concentrations \nin the 21st\u00a0century (medium confidence).3.2.4 Global Synthesis on Multiple Climate-induced \nDrivers\nIn the 21st\u00a0 century, ocean and coastal ecosystems are projected to \nface conditions unprecedented over past centuries to millennia (high \nconfidence) (Section\u00a03.2; WGI AR6 Chapters\u00a04, 9; Fox-Kemper et\u00a0al., \n2021; Lee et\u00a0al., 2021), with increased temperatures (virtually certain) \nand frequency and severity of MHWs (very high confidence), stronger \nupper-ocean stratification (high confidence), continued rise in GMSL \nthroughout the 21st\u00a0century (high confidence) and increased frequency \nof extreme sea levels (high confidence), further acidification (virtually \ncertain), oxygen decline (high confidence) and decreased surface \nnitrate inventories (medium confidence).The rates and magnitudes of these changes largely depend on the extent \nof future emissions (very high confidence), with surface ocean warming \nand acidification (very likely range) at +3.47\u00b0C\u00a0\u00b1\u00a01.28\u00b0C and \u22120.44\u00a0pH \nunits \u00b1\u00a00.008 pH units in 2080\u20132099 (relative to 1870\u20131899) for SSP5-\n8.5 compared with +1.42\u00b0C\u00a0\u00b1\u00a00.53\u00b0C and \u22120.16\u00a0pH units\u00a0\u00b1\u00a00.003 pH \nunits for SSP1-2.6 (Figure\u00a03.5; Kwiatkowski et\u00a0al., 2020).3.2.4.1 Compound Changes in the 21st\u00a0century\nEarth system models project distinct regional evolutions of the \ndifferent CIDs over the 21st\u00a0century (very high confidence) (Figures\u00a03.5, \n3.6, 3.7; Kwiatkowski et\u00a0al., 2020).Tropical and subtropical oceans are \ncharacterised by projected warming and acidification, accompanied by \ndeclining nitrate concentrations in equatorial upwelling regions.The \nNorth Atlantic is characterised by a high exposure to acidification and \ndeclining nitrate concentrations.The North Pacific is characterised by \nhigh sensitivity to compound changes, with high rates of warming, \nacidification, deoxygenation and nutrient depletion.In contrast, the \ndevelopment of compound hazards is limited in the Southern Ocean, \nwhere rates of warming and nutrient depletion are lower.The Arctic \nOcean is characterised by the highest rates of acidification and \nwarming, strong nutrient depletion, and it will likely become practically \nsea ice free in the September mean for the first time before the year \n2050 in all SSP scenarios (high confidence) (Figures\u00a0 3.5, 3.6, 3.7; \nSections\u00a03.2.2, 3.2.3).In general, the projected changes in climate-induced drivers are less \nin absolute terms in the deep-sea (mesopelagic and bathypelagic \ndomains and deep-sea habitats) than in the surface ocean and in \nshallow-water habitats (e.g., kelp ecosystems, warm-water corals) \n(very high confidence) (Figures\u00a03.6, 3.7; Mora et\u00a0al., 2013; Sweetman \net\u00a0al., 2017).The mesopelagic domain will be nevertheless exposed to \nhigh rates of deoxygenation (Figure\u00a03.6) and high climate velocities \n(Figure\u00a03.4; Section\u00a03.2.2.1), as well as impacted by the shoaling of \naragonite or calcite saturation horizon (Section\u00a0 3.2.3.2).Significant \ndifferences in projected trends between the SSPs show that mitigation \nstrategies will limit exposure of deep-sea ecosystems to potential \nwarming, acidification and deoxygenation during the 21st\u00a0 century \n(very high confidence) (Figure\u00a03.6; Kwiatkowski et\u00a0al., 2020).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: What are the projected trends across open-ocean systems in terms of average warming, acidification, changes in dissolved oxygen concentrations, and changes in nitrate concentrations?\nAnswer: "}, {"role": "assistant", "content": "The projected trends across open-ocean systems indicate average warming, acidification, changes in dissolved oxygen concentrations, and changes in nitrate concentrations. These projections are based on the Coupled Model Intercomparison Project 6 models and for three Shared Socioeconomic Pathways (SSPs): SSP1-2.6, SSP2-4.5 and SSP5-8.5. The anomalies in the near-term (2020\u20132041), mid-term (2041\u20132060) and long-term (2081\u20132100) are all relative to 1985\u20132014. The surface ocean is expected to encounter reduced nitrate concentrations in the 21st century. The rates and magnitudes of these changes largely depend on the extent of future emissions. For example, surface ocean warming and acidification are projected at +3.47\u00b0C \u00b1 1.28\u00b0C and \u22120.44 pH units \u00b1 0.008 pH units in 2080\u20132099 (relative to 1870\u20131899) for SSP5-8.5 compared with +1.42\u00b0C \u00b1 0.53\u00b0C and \u22120.16 pH units \u00b1 0.003 pH units for SSP1-2.6."}]} +{"messages": [{"role": "system", "content": "You are an expert Q&A system that is trusted around the world.\nAlways answer the query using the provided context information, and not prior knowledge.\nSome rules to follow:\n1. Never directly reference the given context in your answer.\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines."}, {"role": "user", "content": "Context information is below.\n---------------------\npage_label: 396\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\nBased on new \nregional assessments (Queste et\u00a0 al., 2018; Bronselaer et\u00a0 al., 2020; \nCummins and Ross, 2020; Stramma et\u00a0al., 2020), WGI AR6 assesses \nthat ocean deoxygenation has occurred in most regions of the open \nocean since the mid-20th\u00a0century (high confidence), but it is modified \nby climate variability on interannual and inter-decadal time scales\n\npage_label: 399\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\n\n3\n399Oceans and Coastal Ecosystems and Their Services Chapter 3\n3.2.4.2 Time of Emergence\nAnthropogenic changes in climate-induced drivers assessed here \nexhibit vastly distinct times of emergence, which is the time scale \nover which an anthropogenic signal related to climate change is \nstatistically detected to emerge from the background noise of natural climate for a specific region (Christensen et\u00a0 al., 2007; Hawkins and \nSutton, 2012). SROCC concluded that for ocean properties, the time \nof emergence ranges from under a decade (e.g., surface ocean pH) to \nover a century (e.g., net primary production; see Section\u00a03.4.3.3.4 for \ntime of emergence of biological properties; Bindoff et\u00a0al., 2019a).\nProjected trends across coastal-ocean ecosystems\n(a)\n(b)\n(c)\n(d)\n(e)\nFigure\u00a03.7 | \u00a0Projected trends across coastal-ocean ecosystems. Projected (a)\u00a0warming, (b)\u00a0acidification, (c)\u00a0changes in dissolved oxygen concentrations, (d)\u00a0changes in \nnitrate (NO 3) concentrations and (e)\u00a0changes in summer sea ice cover fraction (September and north of 66\u00b0N for the Northern Polar Oceans, and March and south of 66\u00b0S for the \nSouthern Polar Ocean) for five coastal-ocean ecosystems. All projected trends are for the surface ocean, except oxygen concentration changes that are computed for the subsurface \nocean (100\u2013600 m depth) for the upwelling ecosystems and the polar seas. All projections are based on Coupled Model Intercomparison Project 6 (CMIP6) models and for three \nShared Socioeconomic Pathways (SSPs): SSP1-2.6, SSP2-4.5 and SSP5-8.5 (Kwiatkowski et\u00a0al., 2020). Anomalies in the near term (2020\u20132041), mid term (2041\u20132060) and long term \n(2081\u20132100) are all relative to 1985\u20132014. Error bars represent very likely ranges. Coastal seas are defined on a 1\u00b0\u00a0\u00d7\u00a01\u00b0 grid when bathymetry is less than 200 m deep. Distribution \nof warm-water corals is from UNEP-WCMC et\u00a0al. (2018). Distribution of kelp ecosystems is from OBIS (2020). Upwelling areas are defined according to Rykaczewski et\u00a0al. (2015).\n---------------------\nGiven the context information and not prior knowledge, answer the query.\nQuery: Question: According to the provided context, which study assessed the time of emergence of anthropogenic deoxygenation and warming?\nAnswer: "}, {"role": "assistant", "content": "The context does not provide information on a specific study that assessed the time of emergence of anthropogenic deoxygenation and warming."}]} \ No newline at end of file diff --git a/docs/examples/finetuning/openai_fine_tuning.ipynb b/docs/examples/finetuning/openai_fine_tuning.ipynb new file mode 100644 index 0000000000000..07e70f43957c0 --- /dev/null +++ b/docs/examples/finetuning/openai_fine_tuning.ipynb @@ -0,0 +1,874 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Fine Tuning GPT-3.5-Turbo\n", + "\n", + "In this notebook, we walk through an example of fine-tuning gpt-3.5-turbo.\n", + "\n", + "Specifically, we attempt to distill GPT-4's knowledge, by generating training data with GPT-4 to then fine-tune GPT-3.5.\n", + "\n", + "All training data is generated using two different sections of our index data, creating both a training and evalution set.\n", + "\n", + "We then finetune with our `OpenAIFinetuneEngine` wrapper abstraction.\n", + "\n", + "Evaluation is done using the `ragas` library, which we will detail later on." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# !pip install llama-index pypdf sentence-transformers ragas" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import openai" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "os.environ[\"OPENAI_API_KEY\"] = \"sk-...\"\n", + "openai.api_key = os.environ[\"OPENAI_API_KEY\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Data Setup\n", + "\n", + "Here, we first down load the PDF that we will use to generate training data." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " % Total % Received % Xferd Average Speed Time Time Time Current\n", + " Dload Upload Total Spent Left Speed\n", + "100 20.7M 100 20.7M 0 0 397k 0 0:00:53 0:00:53 --:--:-- 417k84k 0 0:00:55 0:00:24 0:00:31 406k 0 395k 0 0:00:53 0:00:48 0:00:05 403k0 396k 0 0:00:53 0:00:53 --:--:-- 406k\n" + ] + } + ], + "source": [ + "!curl https://www.ipcc.ch/report/ar6/wg2/downloads/report/IPCC_AR6_WGII_Chapter03.pdf --output IPCC_AR6_WGII_Chapter03.pdf" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The next step is generating a training and eval dataset.\n", + "\n", + "We will generate 40 questions on different sections of the PDF we downloaded.\n", + "\n", + "We can use GPT-3.5 on the eval questions to get our baseline performance.\n", + "\n", + "Then, we will use GPT-4 on the train questions to generate our training data. The training data will be collected with out `OpenAIFineTuningHandler`.\n", + "\n", + "This step is entirely optional if you don't want to spend the time/tokens -- the eval and training questions are also provided in this folder, as well as the training data!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Train Generation" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import SimpleDirectoryReader, ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "from llama_index.evaluation import DatasetGenerator\n", + "\n", + "documents = SimpleDirectoryReader(\n", + " input_files=[\"IPCC_AR6_WGII_Chapter03.pdf\"]\n", + ").load_data()\n", + "\n", + "# Shuffle the documents\n", + "import random\n", + "\n", + "random.seed(42)\n", + "random.shuffle(documents)\n", + "\n", + "gpt_35_context = ServiceContext.from_defaults(\n", + " llm=OpenAI(model=\"gpt-3.5-turbo\", temperature=0.3)\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "question_gen_query = (\n", + " \"You are a Teacher/ Professor. Your task is to setup \"\n", + " \"a quiz/examination. Using the provided context from a \"\n", + " \"report on climate change and the oceans, formulate \"\n", + " \"a single question that captures an important fact from the \"\n", + " \"context. Restrict the question to the context information provided.\"\n", + ")\n", + "\n", + "dataset_generator = DatasetGenerator.from_documents(\n", + " documents[:50],\n", + " question_gen_query=question_gen_query,\n", + " service_context=gpt_35_context,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generated 40 questions\n" + ] + } + ], + "source": [ + "# NOTE: this may take some time. Go grab a coffee!\n", + "questions = dataset_generator.generate_questions_from_nodes(num=40)\n", + "print(\"Generated \", len(questions), \" questions\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"train_questions.txt\", \"w\") as f:\n", + " for question in questions:\n", + " f.write(question + \"\\n\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Eval Generation\n", + "\n", + "Now, lets generate questions on a completely different set of documents, in order to create our eval dataset." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "dataset_generator = DatasetGenerator.from_documents(\n", + " documents[\n", + " 50:\n", + " ], # since we generated ~1 question for 40 documents, we can skip the first 40\n", + " question_gen_query=question_gen_query,\n", + " service_context=gpt_35_context,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generated 40 questions\n" + ] + } + ], + "source": [ + "# NOTE: this may take some time. Go grab a coffee!\n", + "questions = dataset_generator.generate_questions_from_nodes(num=40)\n", + "print(\"Generated \", len(questions), \" questions\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"eval_questions.txt\", \"w\") as f:\n", + " for question in questions:\n", + " f.write(question + \"\\n\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Initial Eval with GPT-3.5-Turbo Query Engine\n", + "\n", + "For this eval, we will be using the [`ragas` evaluation library](https://github.com/explodinggradients/ragas).\n", + "\n", + "Ragas has a ton of evaluation metrics for RAG pipelines, and you can read about them [here](https://github.com/explodinggradients/ragas/blob/main/docs/metrics.md).\n", + "\n", + "For this notebook, we will be using the following two metrics\n", + "\n", + "- `answer_relevancy` - This measures how relevant is the generated answer to the prompt. If the generated answer is incomplete or contains redundant information the score will be low. This is quantified by working out the chance of an LLM generating the given question using the generated answer. Values range (0,1), higher the better.\n", + "- `faithfulness` - This measures the factual consistency of the generated answer against the given context. This is done using a multi step paradigm that includes creation of statements from the generated answer followed by verifying each of these statements against the context. The answer is scaled to (0,1) range. Higher the better." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "questions = []\n", + "with open(\"eval_questions.txt\", \"r\") as f:\n", + " for line in f:\n", + " questions.append(line.strip())" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import VectorStoreIndex\n", + "\n", + "# limit the context window to 2048 tokens so that refine is used\n", + "gpt_35_context = ServiceContext.from_defaults(\n", + " llm=OpenAI(model=\"gpt-3.5-turbo\", temperature=0.3), context_window=2048\n", + ")\n", + "\n", + "index = VectorStoreIndex.from_documents(documents, service_context=gpt_35_context)\n", + "\n", + "query_engine = index.as_query_engine(similarity_top_k=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "contexts = []\n", + "answers = []\n", + "\n", + "for question in questions:\n", + " response = query_engine.query(question)\n", + " contexts.append([x.node.get_content() for x in response.source_nodes])\n", + " answers.append(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "evaluating with [answer_relevancy]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [01:02<00:00, 20.69s/it]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "evaluating with [faithfulness]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [03:52<00:00, 77.37s/it]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'ragas_score': 0.8356, 'answer_relevancy': 0.9725, 'faithfulness': 0.7325}\n" + ] + } + ], + "source": [ + "from datasets import Dataset\n", + "from ragas import evaluate\n", + "from ragas.metrics import answer_relevancy, faithfulness\n", + "\n", + "ds = Dataset.from_dict(\n", + " {\n", + " \"question\": questions,\n", + " \"answer\": answers,\n", + " \"contexts\": contexts,\n", + " }\n", + ")\n", + "\n", + "result = evaluate(ds, [answer_relevancy, faithfulness])\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## GPT-4 to Collect Training Data\n", + "\n", + "Here, we use GPT-4 and the `OpenAIFineTuningHandler` to collect data that we want to train on." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "from llama_index.callbacks import OpenAIFineTuningHandler\n", + "from llama_index.callbacks import CallbackManager\n", + "\n", + "finetuning_handler = OpenAIFineTuningHandler()\n", + "callback_manager = CallbackManager([finetuning_handler])\n", + "\n", + "gpt_4_context = ServiceContext.from_defaults(\n", + " llm=OpenAI(model=\"gpt-4\", temperature=0.3),\n", + " context_window=2048, # limit the context window artifically to test refine process\n", + " callback_manager=callback_manager,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "questions = []\n", + "with open(\"train_questions.txt\", \"r\") as f:\n", + " for line in f:\n", + " questions.append(line.strip())" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import VectorStoreIndex\n", + "\n", + "index = VectorStoreIndex.from_documents(documents, service_context=gpt_4_context)\n", + "\n", + "query_engine = index.as_query_engine(similarity_top_k=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "for question in questions:\n", + " response = query_engine.query(question)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create `OpenAIFinetuneEngine`\n", + "\n", + "We create an `OpenAIFinetuneEngine`: the finetune engine will take care of launching a finetuning job, and returning an LLM model that you can directly plugin to the rest of LlamaIndex workflows.\n", + "\n", + "We use the default constructor, but we can also directly pass in our finetuning_handler into this engine with the `from_finetuning_handler` class method.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.finetuning import OpenAIFinetuneEngine\n", + "\n", + "finetune_engine = OpenAIFinetuneEngine(\n", + " \"gpt-3.5-turbo\",\n", + " \"finetuning_events.jsonl\",\n", + " # start_job_id=\"\" # if you have an existing job, can specify id here\n", + ")\n", + "\n", + "# finetune_engine = OpenAIFinetuneEngine.from_finetuning_handler(\n", + "# finetuning_handler,\n", + "# \"gpt-3.5-turbo\",\n", + "# \"tmp.jsonl\"\n", + "# )" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Num examples: 61\n", + "First example:\n", + "{'role': 'system', 'content': \"You are an expert Q&A system that is trusted around the world.\\nAlways answer the query using the provided context information, and not prior knowledge.\\nSome rules to follow:\\n1. Never directly reference the given context in your answer.\\n2. Avoid statements like 'Based on the context, ...' or 'The context information ...' or anything along those lines.\"}\n", + "{'role': 'user', 'content': 'Context information is below.\\n---------------------\\npage_label: 410\\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\\n\\nIt is challenging to apply this experimental approach to communities or ecosystems (see Figure \\nBox\\xa03.1.1).To date, most research on community or ecosystem response to climate-induced drivers has been in large-volume (>10,000 l) \\nmesocosms (Riebesell and Gattuso, 2014), or at natural analogues such as CO 2 seeps, in which only one driver (ocean acidification) is \\naltered (see (4) in Figure Box\\xa03.1.1).Only very recently have two drivers been incorporated into climate-change manipulation studies \\nexamining responses of primary producers to secondary consumers (see (5) in Figure Box\\xa03.1.1a; Nagelkerken et\\xa0al., 2020).Therefore, \\n‘natural experiments’ from the geological past (Reddin et\\xa0al., 2020) provide insights into how food webs and their constituents respond to \\ncomplex change involving multiple drivers.Contemporary observations are occasionally long enough (>50\\xa0years) to capture community \\nresponses to complex climate change.For example, Brun et\\xa0al.(2019) reported a shift in zooplankton community structure in the North \\nAtlantic (1960–2014), with major biogeochemical ramifications.Conducting sufficiently long manipulation experiments to study the effect of adaptation on organisms is equally difficult (see Figure \\nBox\\xa03.1.1b), with much research restricted to multi-year studies of the microevolution of fast-growing (more than one division per day) \\nphytoplankton species responding to single drivers (Lohbeck et\\xa0al., 2012; Schaum et\\xa0al., 2016).In a few experimental evolution studies \\n(see (7) in Figure Box\\xa03.1.1a; Brennan et\\xa0al., 2017), multiple drivers have been used, but none have used communities or ecosystems (see \\nFigure Box\\xa03.1.1b).Nevertheless, the fossil record provides limited evidence of adaptations to less rapid (relative to present day) climate \\nchange (Jackson et\\xa0al., 2018).Despite the need to explore ecological or biogeochemical responses to projected future ocean conditions, \\nlogistical challenges require that assessments of climate-change impacts at scales larger than mesocosms use large-scale, long-term in \\nsitu observational studies (as documented in Section\\xa03.4).\\n\\npage_label: 409\\nfile_name: IPCC_AR6_WGII_Chapter03.pdf\\n\\n3\\n409Oceans and Coastal Ecosystems and Their Services Chapter 3\\nunderlies inhibited thermal adaptation under nitrogen-limited \\nconditions (low confidence) (Aranguren-Gassis et\\xa0 al., 2019).When \\nselection is strong due to unfavourable environmental conditions, \\nmicrobial populations can encounter functional and evolutionary \\ntrade-offs evidenced by reducing growth rates while increasing \\ntolerance and metabolism of reactive oxygen species (Lindberg and \\nCollins, 2020).Other trade-offs can be observed in offspring quality \\nand number (Lindberg and Collins, 2020).These findings contribute \\ntowards a mechanistic framework describing the range of evolutionary \\nstrategies in response to multiple drivers (Collins et\\xa0al., 2020), but other \\nhazards, such as extreme events (e.g., MHWs), still need to be included \\nbecause their characteristics may alter the potential for adaptation of \\nspecies and populations to climate change (Gruber et\\xa0al., 2021).3.3.5 Ecological Response to Multiple Drivers\\nAssessing ecological responses to multiple climate-induced drivers \\nrequires a combination of approaches, including laboratory- and \\nfield-based experiments, field observations (e.g., natural gradients, \\nclimate analogues), study of paleo-analogues and the development \\nof mechanistic and empirical models (Clapham, 2019; Gissi et\\xa0 al., \\n2021).Experimental studies of food-web responses are often limited \\nto an individual driver, although recent manipulations have used a \\nmatrix of >1000-l mesocosms to explore ecological responses to both \\nwarming and acidification (see Box\\xa0 3.1; Nagelkerken et\\xa0 al., 2020).Hence, complementary approaches are needed to indirectly explore \\nthe mechanisms underlying ecosystem responses to global climate \\nchange (Parmesan et\\xa0al., 2013).Observations from time series longer \\nthan modes of natural variability (i.e., decades) are essential for \\nrevealing and attributing ecological responses to climate change (e.g., \\nSection\\xa03.4; Barton et\\xa0al., 2015b; Brun et\\xa0al., 2019).Also, paleorecords \\nprovide insights into the influence of multiple drivers on marine \\nbiota (Cross-Chapter Box\\xa0 PALEO in Chapter\\xa0 1; Reddin et\\xa0 al., 2020).Specifically, associations between vulnerabilities and traits of marine \\nectotherms in laboratory experiments correspond with organismal \\nresponses to ancient hyperthermal events (medium confidence) \\n(Reddin et\\xa0 al., 2020).This corroboration suggests that responses to \\nmultiple drivers inferred from the fossil record can help provide insights \\ninto the future status of functional groups, and hence food webs, under \\nrapid climate change.Multi-species and integrated end-to-end ecosystem models are \\npowerful tools to explore and project outcomes to the often-interacting \\ncumulative effects of climate change and other anthropogenic drivers \\n(Section\\xa03.1; Kaplan and Marshall, 2016; Koenigstein et\\xa0al., 2016; Peck \\nand Pinnegar, 2018; Tittensor et\\xa0 al., 2018; Gissi et\\xa0 al., 2021).These \\nmodels can integrate some aspects of the knowledge accrued from \\nmanipulation experiments, paleo- and contemporary observations, help \\ntest the relative importance of specific drivers and driver combinations, \\nand identify synergistic or antagonistic responses (Koenigstein et\\xa0al., \\n2016; Payne et\\xa0al., 2016; Skogen et\\xa0al., 2018; Tittensor et\\xa0al., 2018).As these models are associated with wide-ranging uncertainties \\n(SM3.2.2; Payne et\\xa0 al., 2016; Trolle et\\xa0 al., 2019; Heneghan et\\xa0 al., \\n2021), they cannot be expected to accurately project the trajectories \\nof complex marine ecosystems under climate change; hence, they are \\nmost useful for assessing overall trends and in particular for providing a plausible envelope of trajectories across a range of assumptions \\n(Fulton et\\xa0al., 2018; Peck et\\xa0al., 2018; Tittensor et\\xa0al., 2018).\\n---------------------\\nGiven the context information and not prior knowledge, answer the query.\\nQuery: What are some approaches used to assess ecological responses to multiple climate-induced drivers in the context of climate change and the oceans?\\nAnswer: '}\n", + "{'role': 'assistant', 'content': 'Several approaches are used to assess ecological responses to multiple climate-induced drivers. These include laboratory- and field-based experiments, field observations such as natural gradients and climate analogues, the study of paleo-analogues, and the development of mechanistic and empirical models. Experimental studies often focus on individual drivers, but recent manipulations have used large-volume mesocosms to explore ecological responses to both warming and acidification. Observations from time series longer than modes of natural variability are essential for revealing and attributing ecological responses to climate change. Paleorecords also provide insights into the influence of multiple drivers on marine biota. Multi-species and integrated end-to-end ecosystem models are powerful tools to explore and project outcomes to the often-interacting cumulative effects of climate change and other anthropogenic drivers. These models can integrate some aspects of the knowledge accrued from manipulation experiments, paleo- and contemporary observations, help test the relative importance of specific drivers and driver combinations, and identify synergistic or antagonistic responses.'}\n", + "No errors found\n", + "Num examples missing system message: 21\n", + "Num examples missing user message: 0\n", + "\n", + "#### Distribution of num_messages_per_example:\n", + "min / max: 2, 3\n", + "mean / median: 2.6557377049180326, 3.0\n", + "p5 / p95: 2.0, 3.0\n", + "\n", + "#### Distribution of num_total_tokens_per_example:\n", + "min / max: 229, 2011\n", + "mean / median: 1274.27868852459, 1385.0\n", + "p5 / p95: 533.0, 1848.0\n", + "\n", + "#### Distribution of num_assistant_tokens_per_example:\n", + "min / max: 11, 334\n", + "mean / median: 72.36065573770492, 37.0\n", + "p5 / p95: 23.0, 193.0\n", + "\n", + "0 examples may be over the 4096 token limit, they will be truncated during fine-tuning\n", + "Dataset has ~77731 tokens that will be charged for during training\n", + "By default, you'll train for 3 epochs on this dataset\n", + "By default, you'll be charged for ~233193 tokens\n", + "As of Augest 22, 2023, fine-tuning gpt-3.5-turbo is $0.008 / 1K Tokens.\n", + "This means your total cost for training will be $0.621848 per epoch.\n", + "Waiting for file to be ready...\n" + ] + } + ], + "source": [ + "finetune_engine.finetune()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + " JSON: {\n", + " \"object\": \"fine_tuning.job\",\n", + " \"id\": \"ftjob-u9T7BF5zRxVX4n5b9Jtbb5cR\",\n", + " \"model\": \"gpt-3.5-turbo-0613\",\n", + " \"created_at\": 1693254044,\n", + " \"finished_at\": null,\n", + " \"fine_tuned_model\": null,\n", + " \"organization_id\": \"org-1ZDAvajC6v2ZtAP9hLEIsXRz\",\n", + " \"result_files\": [],\n", + " \"status\": \"running\",\n", + " \"validation_file\": null,\n", + " \"training_file\": \"file-j1fwmqIAoqZXWZQ8EqwHucXs\",\n", + " \"hyperparameters\": {\n", + " \"n_epochs\": 3\n", + " },\n", + " \"trained_tokens\": null\n", + "}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "finetune_engine.get_current_job()" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "ft_llm = finetune_engine.get_finetuned_model(temperature=0.3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Evaluation\n", + "\n", + "After some time, your model will be done training!\n", + "\n", + "The next step is running our fine-tuned model on our eval dataset again to measure any performance increase." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "from llama_index.callbacks import OpenAIFineTuningHandler\n", + "from llama_index.callbacks import CallbackManager\n", + "\n", + "\n", + "# Option 1: pass in ft_llm directly into ServiceContext\n", + "ft_context = ServiceContext.from_defaults(\n", + " llm=ft_llm,\n", + " context_window=2048, # limit the context window artifically to test refine process\n", + ")\n", + "\n", + "# # Option 2: you can also specify the model name manually\n", + "# ft_model_name = \"ft:gpt-3.5-turbo-0613:...\"\n", + "# ft_context = ServiceContext.from_defaults(\n", + "# llm=OpenAI(model=ft_model_name, temperature=0.3),\n", + "# context_window=2048, # limit the context window artifically to test refine process\n", + "# )" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "questions = []\n", + "with open(\"eval_questions.txt\", \"r\") as f:\n", + " for line in f:\n", + " questions.append(line.strip())" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import VectorStoreIndex\n", + "\n", + "index = VectorStoreIndex.from_documents(documents, service_context=ft_context)\n", + "\n", + "query_engine = index.as_query_engine(similarity_top_k=2)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "contexts = []\n", + "answers = []\n", + "\n", + "for question in questions:\n", + " response = query_engine.query(question)\n", + " contexts.append([x.node.get_content() for x in response.source_nodes])\n", + " answers.append(str(response))" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "evaluating with [answer_relevancy]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:49<00:00, 16.34s/it]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "evaluating with [faithfulness]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [04:04<00:00, 81.44s/it]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'ragas_score': 0.8680, 'answer_relevancy': 0.9607, 'faithfulness': 0.7917}\n" + ] + } + ], + "source": [ + "from datasets import Dataset\n", + "from ragas import evaluate\n", + "from ragas.metrics import answer_relevancy, faithfulness\n", + "\n", + "ds = Dataset.from_dict(\n", + " {\n", + " \"question\": questions,\n", + " \"answer\": answers,\n", + " \"contexts\": contexts,\n", + " }\n", + ")\n", + "\n", + "result = evaluate(ds, [answer_relevancy, faithfulness])\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exploring Differences\n", + "\n", + "Let's quickly compare the differences in responses, to demonstrate that fine tuning did indeed change something." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import VectorStoreIndex\n", + "\n", + "index = VectorStoreIndex.from_documents(documents)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "questions = []\n", + "with open(\"eval_questions.txt\", \"r\") as f:\n", + " for line in f:\n", + " questions.append(line.strip())" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is a key barrier globally for ocean health, governance, and adaptation to climate change, according to the report?\n" + ] + } + ], + "source": [ + "print(questions[12])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Original" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.response.notebook_utils import display_response\n", + "from llama_index import ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "\n", + "\n", + "gpt_35_context = ServiceContext.from_defaults(\n", + " llm=OpenAI(model=\"gpt-3.5-turbo\", temperature=0.3),\n", + " context_window=2048, # limit the context window artifically to test refine process\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "**`Final Response:`** A key barrier globally for ocean health, governance, and adaptation to climate change, according to the report, is the availability of technology, knowledge, and financial support, as well as existing governance structures." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "query_engine = index.as_query_engine(service_context=gpt_35_context)\n", + "\n", + "response = query_engine.query(questions[12])\n", + "\n", + "display_response(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Fine-Tuned" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index import ServiceContext\n", + "from llama_index.llms import OpenAI\n", + "\n", + "\n", + "ft_context = ServiceContext.from_defaults(\n", + " llm=ft_llm,\n", + " context_window=2048, # limit the context window artifically to test refine process\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "**`Final Response:`** The report identifies a broad range of barriers and limits for adaptation to climate change in ecosystems and human systems. These include the availability of technology, knowledge, and financial support, as well as existing governance structures. Existing ocean-governance structures are already facing multi-dimensional, scale-related challenges because of climate change." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "query_engine = index.as_query_engine(service_context=ft_context)\n", + "\n", + "response = query_engine.query(questions[12])\n", + "\n", + "display_response(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As we can see, the fine-tuned model provides a more thorough response! This lines up with the increased faithfullness score from ragas, since the answer is more representative of the retrieved context." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conclusion\n", + "\n", + "So, in conclusion, finetuning with only ~61 questions actually helped improve our eval scores!\n", + "\n", + "**answer_relevancy: 0.9725 -> 0.9607**\n", + "\n", + "The answer relevancy dips slightly but it's very small.\n", + "\n", + "**faithfulness: 0.7325 -> 0.7917**\n", + "\n", + "The faithfulness appears to have been improved! This mains the anwers given better fuffil the original question that was asked." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "llama_index_v2", + "language": "python", + "name": "llama_index_v2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/docs/examples/finetuning/train_questions.txt b/docs/examples/finetuning/train_questions.txt new file mode 100644 index 0000000000000..fbfeb352c7f34 --- /dev/null +++ b/docs/examples/finetuning/train_questions.txt @@ -0,0 +1,40 @@ +What are some approaches used to assess ecological responses to multiple climate-induced drivers in the context of climate change and the oceans? +What is the projected decline in marine animal biomass with warming by 2080-2099 relative to 1995-2014, according to ecosystem models? +What is the projected change in phytoplankton phenology by 2100 under Shared Socioeconomic Pathway (SSP)1-2.6 and SSP5-8.5? +What are the two Shared Socioeconomic Pathways (SSPs) under which the ensemble projections of global changes in phytoplankton phenology were conducted? +What is the title of the paper mentioned in the context that discusses the impact of anthropogenic ocean acidification on calcifying organisms? +What is the title and DOI of the article discussing the physiological plasticity and local adaptation to elevated pCO2 in calcareous algae? +Question: According to the provided context, what is the potential impact of ocean acidification and elevated temperature on a New Zealand snapper population? +What are some of the global initiatives and frameworks that aim to integrate the ocean into climate policy and achieve marine sustainability? +What are the three types of interactions between SDG14 Life Below Water and social, economic, and governance SDGs, as identified in the report? +What is the title of the paper mentioned in the context that discusses the interaction between hydrocarbon seepage, chemosynthetic communities, and bottom water redox at cold seeps? +What is the title and DOI of the study that examines the negative effects of ocean acidification during warming conditions in a developing Antarctic fish? +What is the title and publication year of the report on climate change and the oceans mentioned in the context? +What are the key risks to ecosystems in Eastern Boundary Upwelling Systems (EBUS) due to projected changes in upwelling-favourable winds? +What are some observed impacts of climate change on polar marine ecosystems, including changes in species distributions and abundances, and the influence of warmer oceans and reduced sea ice? +What percentage of sampled sea snail, Limacina helicina, in the Amundsen Gulf displayed signs of shell dissolution according to the report? +What is the title of the book that discusses the ecology of sandy shores? +What is the title of the article that discusses the positive effects of elevated temperature and CO2 on the growth and survival of larval Australasian snapper? +What is the title of the report on climate change and the oceans? +What are some of the impacts of anthropogenic climate change on ocean and coastal ecosystems, according to the provided context? +What are the impacts of marine heatwaves on species and ecosystems, according to the provided context? +What is the title of the paper that discusses the shift in trophic composition and winners and losers in fish communities due to tropicalization and kelp loss? +Question: According to the provided context, which study investigated the impact of ocean acidification on herring larvae survival? +What are the potential effects of acidification, hypoxia, and thermal stress on the growth, respiration, and survival of North Atlantic bivalves? +What are the greatest current hazards to marine birds and mammals according to the Red List Species Assessments of the International Union for Conservation of Nature (IUCN, 2020)? +What is the title of Chapter 3 in the report on climate change and the oceans? +What is the title and author of the paper that discusses the oceanic dispersal barriers in a holoplanktonic gastropod? +Question: According to the provided context, which study found that ocean acidification does not impair the behavior of coral reef fishes? +What is the relationship between ocean warming and the habitat of marine life according to the study by Jorda et al. (2020)? +Question: According to the provided context on climate change and the oceans, which study focuses on the distribution of deep-sea sponge aggregations in an area of changing oceanic conditions? +What is the potential impact of coastal eutrophication on a major oceanic upwelling system? +What is the impact of global climate change on genetic diversity within populations and species? +What is the title of the article in the context information that discusses the effectiveness of marine protected areas? +What is the title of the academic literature that presents a global evidence map of indigenous knowledge on climate change adaptation? +What is the impact of climate change on the wintering ground of Japanese anchovy (Engraulis japonicus) according to marine geospatial statistics? +What is the title and publication year of the report on climate change and the oceans that includes a chapter on the impacts, vulnerabilities, and adaptations of Northeast Tropical Pacific marine fisheries? +Question: According to the provided context, which study found an increase in ocean carbon export in the Sargasso Sea linked to climate variability? +What is the title of the article mentioned in the context information? +What are the potential impacts of increasing ice-free periods on polar bear populations according to the report? +What are the projected trends across open-ocean systems in terms of average warming, acidification, changes in dissolved oxygen concentrations, and changes in nitrate concentrations? +Question: According to the provided context, which study assessed the time of emergence of anthropogenic deoxygenation and warming? diff --git a/llama_index/finetuning/__init__.py b/llama_index/finetuning/__init__.py new file mode 100644 index 0000000000000..a6b54faaecc4e --- /dev/null +++ b/llama_index/finetuning/__init__.py @@ -0,0 +1,5 @@ +"""Finetuning modules.""" + +from llama_index.finetuning.openai.base import OpenAIFinetuneEngine + +__all__ = ["OpenAIFinetuneEngine"] diff --git a/llama_index/finetuning/openai/__init__.py b/llama_index/finetuning/openai/__init__.py new file mode 100644 index 0000000000000..c637335013c59 --- /dev/null +++ b/llama_index/finetuning/openai/__init__.py @@ -0,0 +1 @@ +"""Init params.""" diff --git a/llama_index/finetuning/openai/base.py b/llama_index/finetuning/openai/base.py new file mode 100644 index 0000000000000..d12595f42c3e2 --- /dev/null +++ b/llama_index/finetuning/openai/base.py @@ -0,0 +1,116 @@ +"""OpenAI Finetuning.""" + +from llama_index.finetuning.types import BaseFinetuningEngine +from llama_index.callbacks import OpenAIFineTuningHandler +from llama_index.finetuning.openai.validate_json import validate_json +from typing import Any, Optional +import os +import openai +from llama_index.llms import OpenAI +import time +import logging + +from llama_index.llms.base import LLM + +logger = logging.getLogger(__name__) + + +class OpenAIFinetuneEngine(BaseFinetuningEngine): + """OpenAI Finetuning Engine.""" + + def __init__( + self, + base_model: str, + data_path: str, + verbose: bool = False, + start_job_id: Optional[str] = None, + ) -> None: + """Init params.""" + self.base_model = base_model + self.data_path = data_path + self._verbose = verbose + self._start_job: Optional[Any] = None + if start_job_id is not None: + self._start_job = openai.FineTuningJob.retrieve(start_job_id) + + @classmethod + def from_finetuning_handler( + cls, + finetuning_handler: OpenAIFineTuningHandler, + base_model: str, + data_path: str, + **kwargs: Any, + ) -> "OpenAIFinetuneEngine": + """Initialize from finetuning handler. + + Used to finetune an OpenAI model into another + OpenAI model (e.g. gpt-3.5-turbo on top of GPT-4). + + """ + finetuning_handler.save_finetuning_events(data_path) + return cls(base_model=base_model, data_path=data_path, **kwargs) + + def finetune(self) -> None: + """Finetune model.""" + validate_json(self.data_path) + + file_name = os.path.basename(self.data_path) + + # upload file + with open(self.data_path, "rb") as f: + output = openai.File.create( + file=f, + purpose="fine-tune", + user_provided_filename=file_name, + ) + logger.info("File uploaded...") + if self._verbose: + print("File uploaded...") + + # launch training + while True: + try: + job_output = openai.FineTuningJob.create( + training_file=output["id"], model=self.base_model + ) + self._start_job = job_output + break + except openai.error.InvalidRequestError: + print("Waiting for file to be ready...") + time.sleep(60) + info_str = ( + f"Training job {output['id']} launched. " + "You will be emailed when it's complete." + ) + logger.info(info_str) + if self._verbose: + print(info_str) + + def get_current_job(self) -> Any: + """Get current job.""" + # validate that it works + if not self._start_job: + raise ValueError("Must call finetune() first") + + # try getting id, make sure that run succeeded + job_id = self._start_job["id"] + current_job = openai.FineTuningJob.retrieve(job_id) + return current_job + + def get_finetuned_model(self, **model_kwargs: Any) -> LLM: + """Gets finetuned model.""" + current_job = self.get_current_job() + + job_id = current_job["id"] + status = current_job["status"] + model_id = current_job["fine_tuned_model"] + + if model_id is None: + raise ValueError( + f"Job {job_id} does not have a finetuned model id ready yet." + ) + if status != "succeeded": + raise ValueError(f"Job {job_id} has status {status}, cannot get model") + + llm = OpenAI(model=model_id, **model_kwargs) + return llm diff --git a/llama_index/finetuning/openai/validate_json.py b/llama_index/finetuning/openai/validate_json.py new file mode 100644 index 0000000000000..beaff1396d9b9 --- /dev/null +++ b/llama_index/finetuning/openai/validate_json.py @@ -0,0 +1,178 @@ +# Validates training data and estimates token usage +# Copied from https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset +# Usage: +# python validate_json.py + + +# We start by importing the required packages + +import json +import os +import tiktoken +import numpy as np +import sys +from collections import defaultdict +from typing import Dict, List + + +def validate_json(data_path: str) -> None: + # Load dataset + with open(data_path) as f: + dataset = [json.loads(line) for line in f] + + # We can inspect the data quickly by checking the number + # of examples and the first item + + # Initial dataset stats + print("Num examples:", len(dataset)) + print("First example:") + for message in dataset[0]["messages"]: + print(message) + + # Now that we have a sense of the data, we need to go through all the different + # examples and check to make sure the formatting is correct and matches the Chat + # completions message structure + + # Format error checks + format_errors: Dict[str, int] = defaultdict(int) + + for ex in dataset: + if not isinstance(ex, dict): + format_errors["data_type"] += 1 + continue + + messages = ex.get("messages", None) + if not messages: + format_errors["missing_messages_list"] += 1 + continue + + for message in messages: + if "role" not in message or "content" not in message: + format_errors["message_missing_key"] += 1 + + if any(k not in ("role", "content", "name") for k in message): + format_errors["message_unrecognized_key"] += 1 + + if message.get("role", None) not in ("system", "user", "assistant"): + format_errors["unrecognized_role"] += 1 + + content = message.get("content", None) + if not content or not isinstance(content, str): + format_errors["missing_content"] += 1 + + if not any(message.get("role", None) == "assistant" for message in messages): + format_errors["example_missing_assistant_message"] += 1 + + if format_errors: + print("Found errors:") + for k, v in format_errors.items(): + print(f"{k}: {v}") + else: + print("No errors found") + + # Beyond the structure of the message, we also need to ensure that the length does + # not exceed the 4096 token limit. + + # Token counting functions + encoding = tiktoken.get_encoding("cl100k_base") + + # not exact! + # simplified from https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb + def num_tokens_from_messages( + messages: List[dict], tokens_per_message: int = 3, tokens_per_name: int = 1 + ) -> int: + num_tokens = 0 + for message in messages: + num_tokens += tokens_per_message + for key, value in message.items(): + num_tokens += len(encoding.encode(value)) + if key == "name": + num_tokens += tokens_per_name + num_tokens += 3 + return num_tokens + + def num_assistant_tokens_from_messages(messages: List[dict]) -> int: + num_tokens = 0 + for message in messages: + if message["role"] == "assistant": + num_tokens += len(encoding.encode(message["content"])) + return num_tokens + + def print_distribution(values: list, name: str) -> None: + print(f"\n#### Distribution of {name}:") + print(f"min / max: {min(values)}, {max(values)}") + print(f"mean / median: {np.mean(values)}, {np.median(values)}") + print(f"p5 / p95: {np.quantile(values, 0.1)}, {np.quantile(values, 0.9)}") + + # Last, we can look at the results of the different formatting operations before + # proceeding with creating a fine-tuning job: + + # Warnings and tokens counts + n_missing_system = 0 + n_missing_user = 0 + n_messages = [] + convo_lens = [] + assistant_message_lens = [] + + for ex in dataset: + messages = ex["messages"] + if not any(message["role"] == "system" for message in messages): + n_missing_system += 1 + if not any(message["role"] == "user" for message in messages): + n_missing_user += 1 + n_messages.append(len(messages)) + convo_lens.append(num_tokens_from_messages(messages)) + assistant_message_lens.append(num_assistant_tokens_from_messages(messages)) + + print("Num examples missing system message:", n_missing_system) + print("Num examples missing user message:", n_missing_user) + print_distribution(n_messages, "num_messages_per_example") + print_distribution(convo_lens, "num_total_tokens_per_example") + print_distribution(assistant_message_lens, "num_assistant_tokens_per_example") + n_too_long = sum(length > 4096 for length in convo_lens) + print( + f"\n{n_too_long} examples may be over the 4096 token limit, " + "they will be truncated during fine-tuning" + ) + + # Pricing and default n_epochs estimate + MAX_TOKENS_PER_EXAMPLE = 4096 + + MIN_TARGET_EXAMPLES = 100 + MAX_TARGET_EXAMPLES = 25000 + TARGET_EPOCHS = 3 + MIN_EPOCHS = 1 + MAX_EPOCHS = 25 + + n_epochs = TARGET_EPOCHS + n_train_examples = len(dataset) + if n_train_examples * TARGET_EPOCHS < MIN_TARGET_EXAMPLES: + n_epochs = min(MAX_EPOCHS, MIN_TARGET_EXAMPLES // n_train_examples) + elif n_train_examples * TARGET_EPOCHS > MAX_TARGET_EXAMPLES: + n_epochs = max(MIN_EPOCHS, MAX_TARGET_EXAMPLES // n_train_examples) + + n_billing_tokens_in_dataset = sum( + min(MAX_TOKENS_PER_EXAMPLE, length) for length in convo_lens + ) + print( + f"Dataset has ~{n_billing_tokens_in_dataset} tokens that will " + "be charged for during training" + ) + print(f"By default, you'll train for {n_epochs} epochs on this dataset") + print( + "By default, you'll be charged for " + f"~{n_epochs * n_billing_tokens_in_dataset} tokens" + ) + + print("As of Augest 22, 2023, fine-tuning gpt-3.5-turbo is $0.008 / 1K Tokens.") + print( + "This means your total cost for training will be " + f"${n_billing_tokens_in_dataset * 0.008 / 1000} per epoch." + ) + + +if __name__ == "__main__": + data_path = sys.argv[1] + if not os.path.exists(data_path): + raise ValueError(f"Path {data_path} does not exist") + validate_json(data_path) diff --git a/llama_index/finetuning/types.py b/llama_index/finetuning/types.py new file mode 100644 index 0000000000000..63ac3f2cb0870 --- /dev/null +++ b/llama_index/finetuning/types.py @@ -0,0 +1,17 @@ +"""Finetuning Engine.""" + +from abc import ABC, abstractmethod +from llama_index.llms.base import LLM +from typing import Any + + +class BaseFinetuningEngine(ABC): + """Base finetuning engine.""" + + @abstractmethod + def finetune(self) -> None: + """Goes off and does stuff.""" + + @abstractmethod + def get_finetuned_model(self, **model_kwargs: Any) -> LLM: + """Gets finetuned model.""" From 30bba41e3dd2b41830eb201ed1cf0d82c3bc1c61 Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Mon, 28 Aug 2023 16:01:36 -0700 Subject: [PATCH 04/17] [version] bump version to 0.8.12 (#7443) --- CHANGELOG.md | 13 +++++++++++++ llama_index/VERSION | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b1f80a6556ab..8c7779540a8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # ChangeLog +## [0.8.12] - 2023-08-28 + +### New Features + +- add openai finetuning class (#7442) +- Service Context to/from dict (#7395) +- add finetuning guide (#7429) + +### Smaller Features / Nits / Bug Fixes +- Add example how to run FalkorDB docker (#7441) +- Update root.md to use get_response_synthesizer expected type. (#7437) +- Bugfix MonsterAPI Pydantic version v2/v1 support. Doc Update (#7432) + ## [0.8.11.post3] - 2023-08-27 ### New Features diff --git a/llama_index/VERSION b/llama_index/VERSION index f52db17684fbe..7eff8ab952664 100644 --- a/llama_index/VERSION +++ b/llama_index/VERSION @@ -1 +1 @@ -0.8.11.post3 +0.8.12 From ae3e0bb5ca7811e579da39bbfac8c217dc818cfc Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Mon, 28 Aug 2023 16:14:34 -0700 Subject: [PATCH 05/17] Vectara integration (#7440) --- .../community/integrations/managed_indices.md | 62 ++++ docs/examples/managed/vectaraDemo.ipynb | 242 +++++++++++++++ llama_index/data_structs/struct_type.py | 3 + llama_index/indices/managed/__init__.py | 5 + llama_index/indices/managed/base.py | 90 ++++++ .../indices/managed/vectara/__init__.py | 4 + llama_index/indices/managed/vectara/base.py | 288 ++++++++++++++++++ .../indices/managed/vectara/retriever.py | 142 +++++++++ tests/indices/managed/test_vectara.py | 87 ++++++ 9 files changed, 923 insertions(+) create mode 100644 docs/community/integrations/managed_indices.md create mode 100644 docs/examples/managed/vectaraDemo.ipynb create mode 100644 llama_index/indices/managed/__init__.py create mode 100644 llama_index/indices/managed/base.py create mode 100644 llama_index/indices/managed/vectara/__init__.py create mode 100644 llama_index/indices/managed/vectara/base.py create mode 100644 llama_index/indices/managed/vectara/retriever.py create mode 100644 tests/indices/managed/test_vectara.py diff --git a/docs/community/integrations/managed_indices.md b/docs/community/integrations/managed_indices.md new file mode 100644 index 0000000000000..6b418ac328d3b --- /dev/null +++ b/docs/community/integrations/managed_indices.md @@ -0,0 +1,62 @@ +# Using Managed Indices + +LlamaIndex offers multiple integration points with Managed Indices. A managed index is a special type of index that is not managed locally as part of LlamaIndex but instead is managed via an API, such as [Vectara](https://vectara.com). + +## Using a Managed Index + +Similar to any other index within LlamaIndex (tree, keyword table, list), any `ManagedIndex` can be constructed with a collection +of documents. Once constructed, the index can be used for querying. + +If the Index has been previously populated with documents - it can also be used directly for querying. + +`VectaraIndex` is currently the only supported managed index, although we expect more to be available soon. +Below we show how to use it. + +**Vectara Index Construction/Querying** + +Use the [Vectara Console](https://console.vectara.com/login) to create a corpus (aka Index), and add an API key for access. +Then put the customer id, corpus id, and API key in your environment as shown below. + +Then construct the Vectara Index and query it as follows: + +```python +from llama_index import ManagedIndex, SimpleDirectoryReade +from llama_index.managed import VectaraIndex + +# Load documents and build index +vectara_customer_id = os.environ.get("VECTARA_CUSTOMER_ID") +vectara_corpus_id = os.environ.get("VECTARA_CORPUS_ID") +vectara_api_key = os.environ.get("VECTARA_API_KEY") +documents = SimpleDirectoryReader('../paul_graham_essay/data').load_data() +index = VectaraIndex.from_documents(documents, vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key) + +# Query index +query_engine = index.as_query_engine() +response = query_engine.query("What did the author do growing up?") +``` + +Note that if the environment variables `VECTARA_CUSTOMER_ID`, `VECTARA_CORPUS_ID` and `VECTARA_API_KEY` are in the environment already, you do not have to explicitly specifying them in your call and the VectaraIndex class will read them from the enviornment. For example this should be equivalent to the above, if these variables are in the environment already: + +```python +from llama_index import ManagedIndex, SimpleDirectoryReade +from llama_index.managed import VectaraIndex + +# Load documents and build index +documents = SimpleDirectoryReader('../paul_graham_essay/data').load_data() +index = VectaraIndex.from_documents(documents) + +# Query index +query_engine = index.as_query_engine() +response = query_engine.query("What did the author do growing up?") +``` + + + + +```{toctree} +--- +caption: Examples +maxdepth: 1 +--- +../../examples/vector_stores/VectaraDemo.ipynb +``` diff --git a/docs/examples/managed/vectaraDemo.ipynb b/docs/examples/managed/vectaraDemo.ipynb new file mode 100644 index 0000000000000..7f2c34d25f137 --- /dev/null +++ b/docs/examples/managed/vectaraDemo.ipynb @@ -0,0 +1,242 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "db0855d0", + "metadata": {}, + "source": [ + "# Vectara Vector Store\n", + "In this notebook we are going to show how to use [Vectara](https://vectara.com) with LlamaIndex.\n", + "Vectara is the first example of a \"Managed\" Index, a new type of index in Llama-index which is managed via an API." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c2d1c538", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:14.461233Z", + "start_time": "2023-06-08T13:06:14.451565Z" + } + }, + "outputs": [], + "source": [ + "from llama_index import SimpleDirectoryReader\n", + "from llama_index.indices.managed.vectara.base import VectaraIndex\n", + "\n", + "import textwrap" + ] + }, + { + "cell_type": "markdown", + "id": "f7010b1d-d1bb-4f08-9309-a328bb4ea396", + "metadata": {}, + "source": [ + "### Loading documents\n", + "Load the documents stored in the `paul_graham_essay` using the SimpleDirectoryReader" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "c154dd4b", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:19.009847Z", + "start_time": "2023-06-08T13:06:19.001593Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Document ID: e0482e16-d16b-4040-8b2e-926265565b4f\n" + ] + } + ], + "source": [ + "documents = SimpleDirectoryReader(\"../data/paul_graham\").load_data()\n", + "print(\"Document ID:\", documents[0].doc_id)" + ] + }, + { + "cell_type": "markdown", + "id": "c0232fd1", + "metadata": {}, + "source": [ + "### Add the content of the documents into a pre-created Vectara corpus\n", + "Here we assume an empty corpus is created and the details are available as environment variables:\n", + "* VECTARA_CORPUS_ID\n", + "* VECTARA_CUSTOMER_ID\n", + "* VECTARA_API_KEY" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "8dfdb0a2", + "metadata": {}, + "outputs": [], + "source": [ + "index = VectaraIndex.from_documents(documents)" + ] + }, + { + "cell_type": "markdown", + "id": "8ee4473a-094f-4d0a-a825-e1213db07240", + "metadata": {}, + "source": [ + "### Query the Vectara Index\n", + "We can now ask questions using the VectaraIndex retriever." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0a2bcc07", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:29.486725Z", + "start_time": "2023-06-08T13:06:27.565039Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[NodeWithScore(node=TextNode(id_='3a734d36-d034-46f5-8d5b-fb484fcb5cb0', embedding=None,\n", + "metadata={'lang': 'eng', 'offset': '1166', 'len': '26'}, excluded_embed_metadata_keys=[],\n", + "excluded_llm_metadata_keys=[], relationships={},\n", + "hash='7227faf8ddeeb374c812b56d58fe89659f7f3e84b4ee11e88435fc69be819e0b', text=\"You had to type\n", + "programs on punch cards, then stack them in the card reader and press a button to load the program\n", + "into memory and run it. The result would ordinarily be to print something on the spectacularly loud\n", + "printer. I was puzzled by the 1401. I couldn't figure out what to do with it. And in retrospect\n", + "there's not much I could have done with it.\", start_char_idx=None, end_char_idx=None,\n", + "text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}',\n", + "metadata_seperator='\\n'), score=0.5630376),\n", + "NodeWithScore(node=TextNode(id_='d3933207-63d0-4c2b-97b1-08317b83bc18', embedding=None,\n", + "metadata={'lang': 'eng', 'offset': '1166', 'len': '26'}, excluded_embed_metadata_keys=[],\n", + "excluded_llm_metadata_keys=[], relationships={},\n", + "hash='7227faf8ddeeb374c812b56d58fe89659f7f3e84b4ee11e88435fc69be819e0b', text=\"You had to type\n", + "programs on punch cards, then stack them in the card reader and press a button to load the program\n", + "into memory and run it. The result would ordinarily be to print something on the spectacularly loud\n", + "printer. I was puzzled by the 1401. I couldn't figure out what to do with it. And in retrospect\n", + "there's not much I could have done with it.\", start_char_idx=None, end_char_idx=None,\n", + "text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}',\n", + "metadata_seperator='\\n'), score=0.5630376)]\n" + ] + } + ], + "source": [ + "query_engine = index.as_query_engine(similarity_top_k=10)\n", + "response = query_engine.retrieve(\"What is the 1401?\")\n", + "print(textwrap.fill(str(response[:2]), 100))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "5dafac23", + "metadata": {}, + "outputs": [], + "source": [ + "response = query_engine.query(\"What can the 1401 do?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8cf55bf7", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:32.686121Z", + "start_time": "2023-06-08T13:06:32.680098Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The 1401 can load programs into memory and run them. The result of running a program on the 1401\n", + "would ordinarily be to print something on a loud printer.\n" + ] + } + ], + "source": [ + "print(textwrap.fill(str(response), 100))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "68cbd239-880e-41a3-98d8-dbb3fab55431", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:41.307336Z", + "start_time": "2023-06-08T13:06:34.185641Z" + } + }, + "outputs": [], + "source": [ + "response = query_engine.query(\"What did the author do growing up?\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fdf5287f", + "metadata": { + "ExecuteTime": { + "end_time": "2023-06-08T13:06:44.174719Z", + "start_time": "2023-06-08T13:06:44.163087Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The author worked on writing and programming outside of school. Specifically, they wrote short\n", + "stories and engaged in programming activities.\n" + ] + } + ], + "source": [ + "print(textwrap.fill(str(response), 100))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3961b391", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/llama_index/data_structs/struct_type.py b/llama_index/data_structs/struct_type.py index 01f6f7a9afa1a..e5ad8d0a468b5 100644 --- a/llama_index/data_structs/struct_type.py +++ b/llama_index/data_structs/struct_type.py @@ -94,3 +94,6 @@ class IndexStructType(str, Enum): PANDAS = "pandas" DOCUMENT_SUMMARY = "document_summary" + + # Managed + VECTARA = "vectara" diff --git a/llama_index/indices/managed/__init__.py b/llama_index/indices/managed/__init__.py new file mode 100644 index 0000000000000..668c66a243f37 --- /dev/null +++ b/llama_index/indices/managed/__init__.py @@ -0,0 +1,5 @@ +from llama_index.indices.managed.vectara.base import VectaraIndex +from llama_index.indices.managed.vectara.retriever import VectaraRetriever +from llama_index.indices.managed.base import BaseManagedIndex + +__all__ = ["VectaraIndex", "VectaraRetriever", "BaseManagedIndex"] diff --git a/llama_index/indices/managed/base.py b/llama_index/indices/managed/base.py new file mode 100644 index 0000000000000..450002ca1798c --- /dev/null +++ b/llama_index/indices/managed/base.py @@ -0,0 +1,90 @@ +"""Base Managed Service index. + +An index that that is built on top of a managed service. + +""" +from abc import ABC, abstractmethod + +from typing import Any, Dict, Optional, Sequence, Type + +from llama_index.data_structs.data_structs import IndexDict +from llama_index.indices.base import BaseIndex, IndexType +from llama_index.indices.base_retriever import BaseRetriever +from llama_index.indices.service_context import ServiceContext +from llama_index.schema import BaseNode, Document +from llama_index.storage.docstore.types import RefDocInfo +from llama_index.storage.storage_context import StorageContext + + +class BaseManagedIndex(BaseIndex[IndexDict], ABC): + """Managed Index. + The managed service can index documents into a managed service. + How documents are structured into nodes is a detail for the managed service, + and not exposed in this interface (although could be controlled by + configuration parameters) + + Args: + show_progress (bool): Whether to show tqdm progress bars. Defaults to False. + """ + + def __init__( + self, + nodes: Optional[Sequence[BaseNode]] = None, + index_struct: Optional[IndexDict] = None, + show_progress: bool = False, + **kwargs: Any, + ) -> None: + """Initialize params.""" + super().__init__( + nodes=nodes, + index_struct=index_struct, + service_context=None, + storage_context=None, + show_progress=show_progress, + **kwargs, + ) + + @abstractmethod + def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None: + """Insert a set of documents (each a node).""" + + @abstractmethod + def delete_ref_doc( + self, ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any + ) -> None: + """Delete a document and it's nodes by using ref_doc_id.""" + + @abstractmethod + def update_ref_doc(self, document: Document, **update_kwargs: Any) -> None: + """Update a document and it's corresponding nodes.""" + + @abstractmethod + def as_retriever(self, **kwargs: Any) -> BaseRetriever: + """Return a Retriever for this managed index.""" + + def _build_index_from_nodes(self, nodes: Sequence[BaseNode]) -> IndexDict: + """Build the index from nodes.""" + raise NotImplementedError( + "_build_index_from_nodes not implemented for BaseManagedIndex." + ) + + def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None: + """Delete a node.""" + raise NotImplementedError("_delete_node not implemented for BaseManagedIndex.") + + @property + def ref_doc_info(self) -> Dict[str, RefDocInfo]: + """Retrieve a dict mapping of ingested documents and their nodes+metadata.""" + raise NotImplementedError("ref_doc_info not implemented for BaseManagedIndex.") + + @classmethod + def from_documents( + cls: Type[IndexType], + documents: Sequence[Document], + storage_context: Optional[StorageContext] = None, + service_context: Optional[ServiceContext] = None, + show_progress: bool = False, + **kwargs: Any, + ) -> IndexType: + """Build an index from a sequence of documents.""" + raise NotImplementedError("ref_doc_info not implemented for BaseManagedIndex.") diff --git a/llama_index/indices/managed/vectara/__init__.py b/llama_index/indices/managed/vectara/__init__.py new file mode 100644 index 0000000000000..5ab79f9f62057 --- /dev/null +++ b/llama_index/indices/managed/vectara/__init__.py @@ -0,0 +1,4 @@ +from llama_index.indices.managed.vectara.base import VectaraIndex +from llama_index.indices.managed.vectara.retriever import VectaraRetriever + +__all__ = ["VectaraIndex", "VectaraRetriever"] diff --git a/llama_index/indices/managed/vectara/base.py b/llama_index/indices/managed/vectara/base.py new file mode 100644 index 0000000000000..dfaf22c5810c9 --- /dev/null +++ b/llama_index/indices/managed/vectara/base.py @@ -0,0 +1,288 @@ +"""Managed index. + +A managed Index - where the index is accessible via some API that +interfaces a managed service. + +""" + +import os +import logging +import requests +import json + +from typing import Any, Optional, Sequence, Type +from llama_index.indices.managed.base import BaseManagedIndex, IndexType +from llama_index.schema import Document +from llama_index.indices.base_retriever import BaseRetriever +from llama_index.indices.service_context import ServiceContext +from llama_index.data_structs.data_structs import IndexDict, IndexStructType +from llama_index.schema import BaseNode, TextNode, MetadataMode +from llama_index.storage.storage_context import StorageContext + +_logger = logging.getLogger(__name__) + + +class VectaraIndexStruct(IndexDict): + """Vectara Index Struct.""" + + @classmethod + def get_type(cls) -> IndexStructType: + """Get index struct type.""" + return IndexStructType.VECTARA + + +class VectaraIndex(BaseManagedIndex): + """Vectara Index. + + The Vectara index implements a managed index that uses Vectara as the backend. + Vectara performs a lot of the functions in traditional indexes in the backend: + - breaks down a document into chunks (nodes) + - Creates the embedding for each chunk (node) + - Performs the search for the top k most similar nodes to a query + - Optionally can perform summarization of the top k nodes + + Args: + show_progress (bool): Whether to show tqdm progress bars. Defaults to False. + + """ + + def __init__( + self, + show_progress: bool = False, + nodes: Optional[Sequence[BaseNode]] = None, + vectara_customer_id: Optional[str] = None, + vectara_corpus_id: Optional[str] = None, + vectara_api_key: Optional[str] = None, + **kwargs: Any, + ) -> None: + """Initialize the Vectara API.""" + index_struct = VectaraIndexStruct( + index_id=str(vectara_corpus_id), + summary="Vectara Index", + ) + + super().__init__( + show_progress=show_progress, index_struct=index_struct, **kwargs + ) + self._vectara_customer_id = vectara_customer_id or os.environ.get( + "VECTARA_CUSTOMER_ID" + ) + self._vectara_corpus_id = vectara_corpus_id or os.environ.get( + "VECTARA_CORPUS_ID" + ) + self._vectara_api_key = vectara_api_key or os.environ.get("VECTARA_API_KEY") + if ( + self._vectara_customer_id is None + or self._vectara_corpus_id is None + or self._vectara_api_key is None + ): + _logger.warning( + "Can't find Vectara credentials, customer_id or corpus_id in " + "environment." + ) + raise ValueError("Missing Vectara credentials") + else: + _logger.debug(f"Using corpus id {self._vectara_corpus_id}") + + # setup requests session with max 3 retries and 60s timeout + # for calling Vectara API + self._session = requests.Session() # to reuse connections + adapter = requests.adapters.HTTPAdapter(max_retries=3) + self._session.mount("https://", adapter) + self.vectara_api_timeout = 60 + + # if nodes is specified, consider each node as a single document + # and use _add_documents() to add them to the index + if nodes is not None: + self._build_index_from_nodes(nodes) + + def _build_index_from_nodes(self, nodes: Sequence[BaseNode]) -> IndexDict: + docs = [ + Document( + text=node.get_content(metadata_mode=MetadataMode.NONE), + metadata=node.metadata, + ) + for node in nodes + ] + self.add_documents(docs) + return self.index_struct + + def _get_post_headers(self) -> dict: + """Returns headers that should be attached to each post request.""" + return { + "x-api-key": self._vectara_api_key, + "customer-id": self._vectara_customer_id, + "Content-Type": "application/json", + } + + def _delete_doc(self, doc_id: str) -> bool: + """ + Delete a document from the Vectara corpus. + + Args: + url (str): URL of the page to delete. + doc_id (str): ID of the document to delete. + + Returns: + bool: True if deletion was successful, False otherwise. + """ + body = { + "customer_id": self._vectara_customer_id, + "corpus_id": self._vectara_corpus_id, + "document_id": doc_id, + } + response = self._session.post( + "https://api.vectara.io/v1/delete-doc", + data=json.dumps(body), + verify=True, + headers=self._get_post_headers(), + timeout=self.vectara_api_timeout, + ) + + if response.status_code != 200: + _logger.error( + f"Delete request failed for doc_id = {doc_id} with status code " + f"{response.status_code}, reason {response.reason}, text " + f"{response.text}" + ) + return False + return True + + def _index_doc(self, doc: dict) -> str: + request: dict[str, Any] = {} + request["customer_id"] = self._vectara_customer_id + request["corpus_id"] = self._vectara_corpus_id + request["document"] = doc + + response = self._session.post( + headers=self._get_post_headers(), + url="https://api.vectara.io/v1/index", + data=json.dumps(request), + timeout=self.vectara_api_timeout, + verify=True, + ) + + status_code = response.status_code + + result = response.json() + + status_str = result["status"]["code"] if "status" in result else None + if status_code == 409 or status_str and (status_str == "ALREADY_EXISTS"): + return "E_ALREADY_EXISTS" + elif status_str and (status_str == "FORBIDDEN"): + return "E_NO_PERMISSIONS" + else: + return "E_SUCCEEDED" + + def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None: + """Insert a set of documents (each a node).""" + for node in nodes: + metadata = node.metadata.copy() + metadata["framework"] = "llama_index" + doc = { + "document_id": node.id_, + "metadataJson": json.dumps(node.metadata), + "section": [ + {"text": node.get_content(metadata_mode=MetadataMode.NONE)} + ], + } + self._index_doc(doc) + + def add_documents( + self, docs: Sequence[Document], allow_update: bool = True + ) -> None: + nodes = [TextNode(text=doc.text, metadata=doc.metadata) for doc in docs] + self._insert(nodes) + + def insert_file( + self, + file_path: str, + metadata: Optional[dict] = None, + **insert_kwargs: Any, + ) -> Optional[str]: + """Vectara provides a way to add files (binary or text) directly via our API + where pre-processing and chunking occurs internally in an optimal way + This method provides a way to use that API in Llama_index + + # ruff: noqa: E501 + Full API Docs: https://docs.vectara.com/docs/api-reference/indexing-apis/file-upload/file-upload-filetypes + + Args: + file_path: local file path + Files could be text, HTML, PDF, markdown, doc/docx, ppt/pptx, etc. + see API docs for full list + metadata: Optional list of metadata associated with the file + + Returns: + List of ids associated with each of the files indexed + """ + if not os.path.exists(file_path): + _logger.error(f"File {file_path} does not exist") + return None + + metadata = metadata or {} + metadata["framework"] = "llama_index" + files: dict = { + "file": (file_path, open(file_path, "rb")), + "doc_metadata": json.dumps(metadata), + } + headers = self._get_post_headers() + headers.pop("Content-Type") + response = self._session.post( + f"https://api.vectara.io/upload?c={self._vectara_customer_id}&o={self._vectara_corpus_id}&d=True", + files=files, + verify=True, + headers=headers, + timeout=self.vectara_api_timeout, + ) + + if response.status_code == 409: + doc_id = response.json()["document"]["documentId"] + _logger.info( + f"File {file_path} already exists on Vectara " + f"(doc_id={doc_id}), skipping" + ) + return None + elif response.status_code == 200: + doc_id = response.json()["document"]["documentId"] + return doc_id + else: + _logger.info(f"Error indexing file {file_path}: {response.json()}") + return None + + def delete_ref_doc( + self, ref_doc_id: str, delete_from_docstore: bool = False, **delete_kwargs: Any + ) -> None: + """Delete a document and it's nodes by using ref_doc_id.""" + self._delete_doc(ref_doc_id) + + def update_ref_doc(self, document: Document, **update_kwargs: Any) -> None: + """Update a document and it's corresponding nodes.""" + self._delete_doc(document.doc_id) + self.insert(document) + + def as_retriever(self, **kwargs: Any) -> BaseRetriever: + """Return a Retriever for this managed index.""" + from llama_index.indices.managed.vectara.retriever import VectaraRetriever + + return VectaraRetriever(self, **kwargs) + + @classmethod + def from_documents( + cls: Type[IndexType], + documents: Sequence[Document], + storage_context: Optional[StorageContext] = None, + service_context: Optional[ServiceContext] = None, + show_progress: bool = False, + **kwargs: Any, + ) -> IndexType: + """Build a Vectara index from a sequence of documents.""" + nodes = [ + TextNode(text=document.text, metadata=document.metadata) + for document in documents + ] + return cls( + nodes=nodes, + show_progress=show_progress, + **kwargs, + ) diff --git a/llama_index/indices/managed/vectara/retriever.py b/llama_index/indices/managed/vectara/retriever.py new file mode 100644 index 0000000000000..589084a60aa7e --- /dev/null +++ b/llama_index/indices/managed/vectara/retriever.py @@ -0,0 +1,142 @@ +"""Vectara index. +An index that that is built on top of Vectara +""" + +import logging +from typing import Any, List, Optional +import json + +from llama_index.schema import TextNode +from llama_index.indices.base_retriever import BaseRetriever +from llama_index.indices.managed.vectara.base import VectaraIndex +from llama_index.schema import NodeWithScore +from llama_index.constants import DEFAULT_SIMILARITY_TOP_K +from llama_index.indices.query.schema import QueryBundle + + +_logger = logging.getLogger(__name__) + + +class VectaraRetriever(BaseRetriever): + """Vectara Retriever. + Args: + index (VectaraIndex): the Vectara Index + similarity_top_k (int): number of top k results to return. + lambda_val (float): for hybrid search. + 0 = neural search only. + 1 = keyword match only. + In between values are a linear interpolation + n_sentences_before (int): + number of sentences before the matched sentence to return in the node + n_sentences_after (int): + number of sentences after the matched sentence to return in the node + filter: metadata filter (if specified) + """ + + def __init__( + self, + index: VectaraIndex, + similarity_top_k: Optional[int] = DEFAULT_SIMILARITY_TOP_K, + lambda_val: Optional[float] = None, + n_sentences_before: Optional[int] = 2, + n_sentences_after: Optional[int] = 2, + filter: Optional[str] = None, + **kwargs: Any, + ) -> None: + """Initialize params.""" + self._index = index + self._similarity_top_k = similarity_top_k + self._lambda_val = lambda_val + self._n_sentences_before = n_sentences_before + self._n_sentences_after = n_sentences_after + self._filter = filter + + def _get_post_headers(self) -> dict: + """Returns headers that should be attached to each post request.""" + return { + "x-api-key": self._index._vectara_api_key, + "customer-id": self._index._vectara_customer_id, + "Content-Type": "application/json", + } + + def _retrieve( + self, + query_bundle: QueryBundle, + **kwargs: Any, + ) -> List[NodeWithScore]: + """Query Vectara index to get for top k most similar nodes. + + Args: + query: Query Bundle + """ + + similarity_top_k = ( + self._similarity_top_k + if self._similarity_top_k + else DEFAULT_SIMILARITY_TOP_K + ) + n_sentences_before = self._n_sentences_before if self._n_sentences_before else 2 + n_sentences_after = self._n_sentences_after if self._n_sentences_after else 2 + lambda_val = self._lambda_val if self._lambda_val else 0.025 + corpus_key = { + "customer_id": self._index._vectara_customer_id, + "corpus_id": self._index._vectara_corpus_id, + "lexical_interpolation_config": {"lambda": lambda_val}, + } + if self._filter: + corpus_key["metadataFilter"] = self._filter if self._filter else None + + data = json.dumps( + { + "query": [ + { + "query": query_bundle.query_str, + "start": 0, + "num_results": similarity_top_k, + "context_config": { + "sentences_before": n_sentences_before, + "sentences_after": n_sentences_after, + }, + "corpus_key": [corpus_key], + } + ] + } + ) + + response = self._index._session.post( + headers=self._get_post_headers(), + url="https://api.vectara.io/v1/query", + data=data, + timeout=self._index.vectara_api_timeout, + ) + + if response.status_code != 200: + _logger.error( + "Query failed %s", + f"(code {response.status_code}, reason {response.reason}, details " + f"{response.text})", + ) + return [] + + result = response.json() + responses = result["responseSet"][0]["response"] + documents = result["responseSet"][0]["document"] + + metadatas = [] + for x in responses: + md = {m["name"]: m["value"] for m in x["metadata"]} + doc_num = x["documentIndex"] + doc_md = {m["name"]: m["value"] for m in documents[doc_num]["metadata"]} + md.update(doc_md) + metadatas.append(md) + + top_k_nodes = [] + for x, md in zip(responses, metadatas): + doc_inx = x["documentIndex"] + doc_id = documents[doc_inx]["id"] + node = NodeWithScore( + node=TextNode(text=x["text"], id_=doc_id, metadata=md), score=x["score"] + ) + top_k_nodes.append(node) + + return top_k_nodes diff --git a/tests/indices/managed/test_vectara.py b/tests/indices/managed/test_vectara.py new file mode 100644 index 0000000000000..7dfaf045fff99 --- /dev/null +++ b/tests/indices/managed/test_vectara.py @@ -0,0 +1,87 @@ +from typing import List, Tuple + +import pytest + +from llama_index.indices.managed.vectara.base import VectaraIndex +from llama_index.schema import Document + + +def get_docs() -> Tuple[List[Document], List[str]]: + inputs = [ + { + "text": "This is test text for Vectara integration with LlamaIndex", + "metadata": {"test_num": "1"}, + }, + { + "text": "And now for something completely different", + "metadata": {"test_num": "2"}, + }, + { + "text": "when 900 year you will be, look as good you will not", + "metadata": {"test_num": "3"}, + }, + ] + docs: List[Document] = [] + ids = [] + for inp in inputs: + doc = Document( + text=inp["text"], + metadata=inp["metadata"], + ) + docs.append(doc) + ids.append(doc.id_) + return docs, ids + + +def remove_docs(index: VectaraIndex, ids: List) -> None: + for id in ids: + index.delete_ref_doc(id) + + +def test_simple_query() -> None: + docs, ids = get_docs() + try: + index = VectaraIndex.from_documents(docs) + except ValueError: + pytest.skip("Missing Vectara credentials, skipping test") + + assert isinstance(index, VectaraIndex) + qe = index.as_retriever(similarity_top_k=1) + res = qe.retrieve("how will I look?") + assert len(res) == 1 + assert res[0].node.text == docs[2].text + + remove_docs(index, ids) + + +def test_with_filter_query() -> None: + docs, ids = get_docs() + try: + index = VectaraIndex.from_documents(docs) + except ValueError: + pytest.skip("Missing Vectara credentials, skipping test") + + assert isinstance(index, VectaraIndex) + qe = index.as_retriever(similarity_top_k=1, filter="doc.test_num = '1'") + res = qe.retrieve("how will I look?") + assert len(res) == 1 + assert res[0].node.text == docs[0].text + + remove_docs(index, ids) + + +def test_file_upload() -> None: + try: + index = VectaraIndex() + except ValueError: + pytest.skip("Missing Vectara credentials, skipping test") + + file_path = "docs/examples/data/paul_graham/paul_graham_essay.txt" + id = index.insert_file(file_path) + + assert isinstance(index, VectaraIndex) + query_engine = index.as_query_engine(similarity_top_k=3) + res = query_engine.query("What is a Manager Schedule?") + assert "a manager schedule" in str(res).lower() + + remove_docs(index, [id]) From 11ebc0bffde74ffe3aefc206ae254c0ff8e98ec0 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 28 Aug 2023 17:56:04 -0600 Subject: [PATCH 06/17] update ruff config (#7448) --- llama_index/indices/managed/vectara/base.py | 3 ++- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/llama_index/indices/managed/vectara/base.py b/llama_index/indices/managed/vectara/base.py index dfaf22c5810c9..55c33726085e3 100644 --- a/llama_index/indices/managed/vectara/base.py +++ b/llama_index/indices/managed/vectara/base.py @@ -205,7 +205,8 @@ def insert_file( This method provides a way to use that API in Llama_index # ruff: noqa: E501 - Full API Docs: https://docs.vectara.com/docs/api-reference/indexing-apis/file-upload/file-upload-filetypes + Full API Docs: https://docs.vectara.com/docs/api-reference/indexing-apis/ + file-upload/file-upload-filetypes Args: file_path: local file path diff --git a/pyproject.toml b/pyproject.toml index 8e44e5b0c360b..f751c1604a144 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,4 +12,5 @@ exclude = [ ".ruff_cache", "examples", "notebooks", + ".git" ] From 28c64a8fd0e2c781121d08023ee5abbf7df24a2b Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Mon, 28 Aug 2023 18:05:07 -0700 Subject: [PATCH 07/17] patch finetuning notebook (#7449) --- docs/end_to_end_tutorials/finetuning.md | 2 +- docs/examples/finetuning/openai_fine_tuning.ipynb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/end_to_end_tutorials/finetuning.md b/docs/end_to_end_tutorials/finetuning.md index 01765ff70bd56..b04a5fba1443c 100644 --- a/docs/end_to_end_tutorials/finetuning.md +++ b/docs/end_to_end_tutorials/finetuning.md @@ -57,7 +57,7 @@ We then launch a finetuning job, and get back a distilled model. We can evaluate maxdepth: 1 --- GPT-3.5 Fine-tuning Notebook (Colab) -GPT-3.5 Fine-tuning Notebook (in Repo) +GPT-3.5 Fine-tuning Notebook ``` **Old** diff --git a/docs/examples/finetuning/openai_fine_tuning.ipynb b/docs/examples/finetuning/openai_fine_tuning.ipynb index 07e70f43957c0..6fcb0a447d2ca 100644 --- a/docs/examples/finetuning/openai_fine_tuning.ipynb +++ b/docs/examples/finetuning/openai_fine_tuning.ipynb @@ -422,6 +422,15 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "finetuning_handler.save_finetuning_events(\"finetuning_events.jsonl\")" + ] + }, { "cell_type": "code", "execution_count": 22, From 5b4cd7226b8c32c2d257a6b9baf7bc05f0b995b3 Mon Sep 17 00:00:00 2001 From: ColabDog <108557828+ColabDog@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:41:28 +1000 Subject: [PATCH 08/17] add deepeval integration (#7425) --- CHANGELOG.md | 6 + docs/community/integrations/deepeval.md | 146 ++++++++ .../supporting_modules/evaluation/modules.md | 1 + .../supporting_modules/evaluation/root.md | 7 + .../evaluation/usage_pattern.md | 7 + docs/examples/evaluation/Deepeval.ipynb | 315 ++++++++++++++++++ 6 files changed, 482 insertions(+) create mode 100644 docs/community/integrations/deepeval.md create mode 100644 docs/examples/evaluation/Deepeval.ipynb diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c7779540a8c0..93bc0c98ee810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # ChangeLog +## Unreleased + +### New Features +- Integration guide and notebook with DeepEval (#7425) +- Added `VectorIndex` and `VectaraRetriever` as a managed index (#7440) + ## [0.8.12] - 2023-08-28 ### New Features diff --git a/docs/community/integrations/deepeval.md b/docs/community/integrations/deepeval.md new file mode 100644 index 0000000000000..77dce2cb9834e --- /dev/null +++ b/docs/community/integrations/deepeval.md @@ -0,0 +1,146 @@ +# Unit Testing LLMs With DeepEval + +[DeepEval](https://github.com/confident-ai/deepeval) provides unit testing for AI agents and LLM-powered applications. It provides a really simple interface for LlamaIndex developers to write tests and helps developers ensure AI applications run as expected. + +DeepEval provides an opinionated framework to measure responses and is completely open-source. + +### Installation and Setup + +Adding [DeepEval](https://github.com/confident-ai/deepeval) is simple, just install and configure it: + +```sh +pip install -q -q llama-index +pip install -U deepeval +``` + +Once installed , you can get set up and start writing tests. + +```sh +# Optional step: Login to get a nice dashboard for your tests later! +# During this step - make sure to save your project as llama +deepeval login +deepeval test generate test_sample.py +``` + +You can then run tests as such: + +```bash +deepeval test run test_sample.py +``` + +After running this, you will get a beautiful dashboard like so: + +![Sample dashboard](https://raw.githubusercontent.com/confident-ai/deepeval/main/docs/assets/dashboard-screenshot.png) + +## Types of Tests + +DeepEval presents an opinionated framework for the types of tests that are being run. It breaks down LLM outputs into: +- Answer Relevancy - [Read more here](https://docs.confident-ai.com/docs/measuring_llm_performance/answer_relevancy) +- Factual Consistency (to measure the extent of hallucinations) - [Read more here](https://docs.confident-ai.com/docs/measuring_llm_performance/factual_consistency) +- Conceptual Similarity (to know if answers are in line with expectations) - [Read more here](https://docs.confident-ai.com/docs/measuring_llm_performance/conceptual_similarity) +- Toxicness - [Read more here](https://docs.confident-ai.com/docs/measuring_llm_performance/non_toxic) +- Bias (can come up from finetuning) - [Read more here](https://docs.confident-ai.com/docs/measuring_llm_performance/debias) + +You can more about the [DeepEval Framework](https://docs.confident-ai.com/docs/framework) here. + +## Use With Your LlamaIndex + +DeepEval integrates nicely with LlamaIndex's `ResponseEvaluator` class. Below is an example of the factual consistency documentation. + +```python + +from llama_index.response.schema import Response +from typing import List +from llama_index.schema import Document +from deepeval.metrics.factual_consistency import FactualConsistencyMetric + +from llama_index import ( + TreeIndex, + VectorStoreIndex, + SimpleDirectoryReader, + LLMPredictor, + ServiceContext, + Response, +) +from llama_index.llms import OpenAI +from llama_index.evaluation import ResponseEvaluator + +import os +import openai + +api_key = "sk-XXX" +openai.api_key = api_key + +gpt4 = OpenAI(temperature=0, model="gpt-4", api_key=api_key) +service_context_gpt4 = ServiceContext.from_defaults(llm=gpt4) +evaluator_gpt4 = ResponseEvaluator(service_context=service_context_gpt4) + +``` + +#### Getting a lLamaHub Loader + +```python +from llama_index import download_loader + +WikipediaReader = download_loader("WikipediaReader") + +loader = WikipediaReader() +documents = loader.load_data(pages=['Tokyo']) +tree_index = TreeIndex.from_documents(documents=documents) +vector_index = VectorStoreIndex.from_documents( + documents, service_context=service_context_gpt4 +) +``` + +We then build an evaluator based on the `BaseEvaluator` class that requires an `evaluate` method. + +In this example, we show you how to write a factual consistency check. + +```python +class FactualConsistencyResponseEvaluator: + def get_context(self, response: Response) -> List[Document]: + """Get context information from given Response object using source nodes. + + Args: + response (Response): Response object from an index based on the query. + + Returns: + List of Documents of source nodes information as context information. + """ + context = [] + + for context_info in response.source_nodes: + context.append(Document(text=context_info.node.get_content())) + + return context + + def evaluate(self, response: Response) -> str: + """Evaluate factual consistency metrics + """ + answer = str(response) + context = self.get_context(response) + metric = FactualConsistencyMetric() + context = " ".join([d.text for d in context]) + score = metric.measure(output=answer, context=context) + if metric.is_successful(): + return "YES" + else: + return "NO" + +evaluator = FactualConsistencyResponseEvaluator() +``` + +You can then evaluate as such: + +```python +query_engine = tree_index.as_query_engine() +response = query_engine.query("How did Tokyo get its name?") +eval_result = evaluator.evaluate(response) +``` + +### Useful Links + +* [Read About The DeepEval Framework](https://docs.confident-ai.com/docs/framework) +* [Answer Relevancy](https://docs.confident-ai.com/docs/measuring_llm_performance/answer_relevancy) +* [Conceptual Similarity](https://docs.confident-ai.com/docs/measuring_llm_performance/conceptual_similarity) . +* [Bias](https://docs.confident-ai.com/docs/measuring_llm_performance/debias) \ No newline at end of file diff --git a/docs/core_modules/supporting_modules/evaluation/modules.md b/docs/core_modules/supporting_modules/evaluation/modules.md index 5af2663269d74..7fe5150420891 100644 --- a/docs/core_modules/supporting_modules/evaluation/modules.md +++ b/docs/core_modules/supporting_modules/evaluation/modules.md @@ -10,4 +10,5 @@ maxdepth: 1 ../../../examples/evaluation/TestNYC-Evaluation.ipynb ../../../examples/evaluation/TestNYC-Evaluation-Query.ipynb ../../../examples/evaluation/QuestionGeneration.ipynb +../../../examples/evaluation/Deepeval.ipynb ``` \ No newline at end of file diff --git a/docs/core_modules/supporting_modules/evaluation/root.md b/docs/core_modules/supporting_modules/evaluation/root.md index b3b38f2e3664c..a196c68d6f3e5 100644 --- a/docs/core_modules/supporting_modules/evaluation/root.md +++ b/docs/core_modules/supporting_modules/evaluation/root.md @@ -42,6 +42,13 @@ if it matches the query. In addition to evaluating queries, LlamaIndex can also use your data to generate questions to evaluate on. This means that you can automatically generate questions, and then run an evaluation pipeline to test if the LLM can actually answer questions accurately using your data. +## Integrations + +We also integrate with community evaluation tools. + +- [DeepEval](../../../community/integrations/deepeval.md) +- [Ragas](https://github.com/explodinggradients/ragas/blob/main/docs/integrations/llamaindex.ipynb) + ## Usage Pattern For full usage details, see the usage pattern below. diff --git a/docs/core_modules/supporting_modules/evaluation/usage_pattern.md b/docs/core_modules/supporting_modules/evaluation/usage_pattern.md index 035ce412a4e81..3a6836444066c 100644 --- a/docs/core_modules/supporting_modules/evaluation/usage_pattern.md +++ b/docs/core_modules/supporting_modules/evaluation/usage_pattern.md @@ -144,3 +144,10 @@ data_generator = DatasetGenerator.from_documents(documents) eval_questions = data_generator.generate_questions_from_nodes() ``` + +## Integrations + +We also integrate with community evaluation tools. + +- [DeepEval](../../../community/integrations/deepeval.md) +- [Ragas](https://github.com/explodinggradients/ragas/blob/main/docs/integrations/llamaindex.ipynb) diff --git a/docs/examples/evaluation/Deepeval.ipynb b/docs/examples/evaluation/Deepeval.ipynb new file mode 100644 index 0000000000000..e6e42327784e2 --- /dev/null +++ b/docs/examples/evaluation/Deepeval.ipynb @@ -0,0 +1,315 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "pwywywUOqgOV" + }, + "source": [ + "## LlamaIndex + DeepEval Integration\n", + "\n", + "This code tutorial shows how you can easily integrate LlamaIndex with DeepEval. DeepEval makes it easy to unit-test your LLMs.\n", + "\n", + "You can read more about the DeepEval framework here: https://docs.confident-ai.com/docs/framework\n", + "\n", + "Feel free to check out our repository here: https://github.com/confident-ai/deepeval\n", + "\n", + "![Framework](https://docs.confident-ai.com/assets/images/llm-evaluation-framework-example-b02144720026b6d49b1e04d8a99d3d33.png)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "ZfRYToRM4NxG" + }, + "source": [ + "## Set-up and Installation\n", + "\n", + "We recommend setting up and installing via pip!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3SLBSPwHqfJh" + }, + "outputs": [], + "source": [ + "!pip install -q -q llama-index\n", + "!pip install -U -q deepeval" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "Ew1PitGb4V_G" + }, + "source": [ + "This step is optional and only if you want a server-hosted dashboard! (Psst I think you should!)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "-Px9Fr9GRczP" + }, + "outputs": [], + "source": [ + "!deepeval login" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "taqcdkaYYwTs" + }, + "source": [ + "## Testing for factual consistency" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "usj5Dp3Mhztn" + }, + "outputs": [], + "source": [ + "from llama_index.response.schema import Response\n", + "from typing import List\n", + "from llama_index.schema import Document\n", + "from deepeval.metrics.factual_consistency import FactualConsistencyMetric" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "hL0J32q7kI6X" + }, + "source": [ + "# Setting Up The Evaluator\n", + "\n", + "Setting up the evaluator." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9vRW0D_vkdW7" + }, + "outputs": [], + "source": [ + "from llama_index import (\n", + " TreeIndex,\n", + " VectorStoreIndex,\n", + " SimpleDirectoryReader,\n", + " LLMPredictor,\n", + " ServiceContext,\n", + " Response,\n", + ")\n", + "from llama_index.llms import OpenAI\n", + "from llama_index.evaluation import ResponseEvaluator" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "nEpJv40lkhhx" + }, + "outputs": [], + "source": [ + "import os\n", + "import openai\n", + "\n", + "api_key = \"sk-XXX\"\n", + "openai.api_key = api_key" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "jm6qakfZahMd" + }, + "outputs": [], + "source": [ + "gpt4 = OpenAI(temperature=0, model=\"gpt-4\", api_key=api_key)\n", + "service_context_gpt4 = ServiceContext.from_defaults(llm=gpt4)\n", + "evaluator_gpt4 = ResponseEvaluator(service_context=service_context_gpt4)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "1rKB7Hk0lCtP" + }, + "source": [ + "## Getting a LlamaHub Loader" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "nHnMc3QhlBV8" + }, + "outputs": [], + "source": [ + "from llama_index import download_loader\n", + "\n", + "WikipediaReader = download_loader(\"WikipediaReader\")\n", + "\n", + "loader = WikipediaReader()\n", + "documents = loader.load_data(pages=[\"Tokyo\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "fChhgGLJkViR" + }, + "outputs": [], + "source": [ + "tree_index = TreeIndex.from_documents(documents=documents)\n", + "vector_index = VectorStoreIndex.from_documents(\n", + " documents, service_context=service_context_gpt4\n", + ")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "nTFoA4RP2_BJ" + }, + "source": [ + "We then build an evaluator based on the `BaseEvaluator` class that requires an `evaluate` method.\n", + "\n", + "In this example, we show you how to write a factual consistency check." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "HXHou8Yw3guL" + }, + "outputs": [], + "source": [ + "class FactualConsistencyResponseEvaluator:\n", + " def get_context(self, response: Response) -> List[Document]:\n", + " \"\"\"Get context information from given Response object using source nodes.\n", + "\n", + " Args:\n", + " response (Response): Response object from an index based on the query.\n", + "\n", + " Returns:\n", + " List of Documents of source nodes information as context information.\n", + " \"\"\"\n", + " context = []\n", + "\n", + " for context_info in response.source_nodes:\n", + " context.append(Document(text=context_info.node.get_content()))\n", + "\n", + " return context\n", + "\n", + " def evaluate(self, response: Response) -> str:\n", + " \"\"\"Evaluate factual consistency metrics\"\"\"\n", + " answer = str(response)\n", + " context = self.get_context(response)\n", + " metric = FactualConsistencyMetric()\n", + " context = \" \".join([d.text for d in context])\n", + " score = metric.measure(output=answer, context=context)\n", + " if metric.is_successful():\n", + " return \"YES\"\n", + " else:\n", + " return \"NO\"\n", + "\n", + "\n", + "evaluator = FactualConsistencyResponseEvaluator()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "background_save": true + }, + "id": "rWOduygYYuPe", + "outputId": "2140b979-d9ab-407d-83f7-4e875191de02" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.10/dist-packages/transformers/convert_slow_tokenizer.py:470: UserWarning: The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option which is not implemented in the fast tokenizers. In practice this means that the fast version of the tokenizer can produce unknown tokens whereas the sentencepiece version would have converted these unknown tokens into a sequence of byte tokens matching the original piece of text.\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'success': True, 'score': 0.97732705}\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.10/dist-packages/deepeval/metrics/metric.py:42: UserWarning: API key is not set. Please set it by visiting https://app.confident-ai.com\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "query_engine = tree_index.as_query_engine()\n", + "response = query_engine.query(\"How did Tokyo get its name?\")\n", + "eval_result = evaluator.evaluate(response)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "id": "z3-ZPq3a35pI" + }, + "source": [ + "# Other Metrics\n", + "\n", + "We recommend using other metrics to help give more confidence to various prompt iterations, LLM outputs etc. We think ML-assisted approaches are required to give performance for these models.\n", + "\n", + "- Overall Score: https://docs.confident-ai.com/docs/measuring_llm_performance/overall_score\n", + "- Answer Relevancy: https://docs.confident-ai.com/docs/measuring_llm_performance/answer_relevancy\n", + "- Bias: https://docs.confident-ai.com/docs/measuring_llm_performance/debias" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From e5fa3c280f6c4a93301691164f3d3bd4f2dc9574 Mon Sep 17 00:00:00 2001 From: Zihao Jing <1971008968@qq.com> Date: Tue, 29 Aug 2023 11:58:33 +0800 Subject: [PATCH 09/17] Integrate RunGPT For LLMs (#7401) --- CHANGELOG.md | 1 + .../model_modules/llms/modules.md | 9 +- docs/examples/llm/rungpt.ipynb | 216 +++++++++++++ llama_index/llms/rungpt.py | 290 ++++++++++++++++++ tests/llms/test_rungpt.py | 253 +++++++++++++++ 5 files changed, 768 insertions(+), 1 deletion(-) create mode 100644 docs/examples/llm/rungpt.ipynb create mode 100644 llama_index/llms/rungpt.py create mode 100644 tests/llms/test_rungpt.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 93bc0c98ee810..f7a427f6ed6a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### New Features +- Added support for RunGPT LLM (#7401) - Integration guide and notebook with DeepEval (#7425) - Added `VectorIndex` and `VectaraRetriever` as a managed index (#7440) diff --git a/docs/core_modules/model_modules/llms/modules.md b/docs/core_modules/model_modules/llms/modules.md index 74146c6c8e8ca..5f82446fd6fcf 100644 --- a/docs/core_modules/model_modules/llms/modules.md +++ b/docs/core_modules/model_modules/llms/modules.md @@ -107,5 +107,12 @@ maxdepth: 1 maxdepth: 1 --- /examples/llm/monsterapi.ipynb +``` -``` \ No newline at end of file +## RunGPT +```{toctree} +--- +maxdepth: 1 +--- +/examples/llm/rungpt.ipynb +``` diff --git a/docs/examples/llm/rungpt.ipynb b/docs/examples/llm/rungpt.ipynb new file mode 100644 index 0000000000000..359948018f9a4 --- /dev/null +++ b/docs/examples/llm/rungpt.ipynb @@ -0,0 +1,216 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# RunGPT\n", + "RunGPT is an open-source cloud-native large-scale multimodal models (LMMs) serving framework. It is designed to simplify the deployment and management of large language models, on a distributed cluster of GPUs. RunGPT aim to make it a one-stop solution for a centralized and accessible place to gather techniques for optimizing large-scale multimodal models and make them easy to use for everyone. In RunGPT, we have supported a number of LLMs such as LLaMA, Pythia, StableLM, Vicuna, MOSS, and Large Multi-modal Model(LMMs) like MiniGPT-4 and OpenFlamingo additionally." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Setup\n", + "Firstly, you need to install rungpt package in your python environment with `pip install`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "!pip install run-gpt-torch, jina" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After installing successfully, models supported by RunGPT can be deployed with an one-line command. This option will download target language model from open source platform and deploy it as a service at a localhost port, which can be accessed by http or grpc requests. I suppose you not run this command in jupyter book, but in command line instead." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "!rungpt serve decapoda-research/llama-7b-hf --precision fp16 --device_map balanced" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Basic Usage\n", + "#### Call `complete` with a prompt" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.llms.rungpt import RunGptLLM\n", + "\n", + "llm = RunGptLLM()\n", + "promot = \"I don't want to go to work, so what should I do?\"\n", + "response = llm.complete(promot)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I don't want to go to work, so what should I do?\n", + "I have a job interview on Monday. What can I wear that will make me look professional but not too stuffy or boring?\n" + ] + } + ], + "source": [ + "print(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Call `chat` with a list of messages" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.llms.base import ChatMessage, MessageRole\n", + "from llama_index.llms.rungpt import RunGptLLM\n", + "\n", + "messages = [\n", + " ChatMessage(\n", + " role=MessageRole.USER,\n", + " content=\"Hello, my name is zihao, major in artificial intelligence.\",\n", + " ),\n", + " ChatMessage(role=MessageRole.ASSISTANT, content=\"Hello, what can I do for you?\"),\n", + " ChatMessage(\n", + " role=MessageRole.USER, content=\"Could you tell me what is my name and major?\"\n", + " ),\n", + "]\n", + "llm = RunGptLLM()\n", + "response = llm.chat(messages=messages, temperature=0.8, max_tokens=15)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(response)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Streaming" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using `stream_complete` endpoint " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "promot = \"I don't want to go to work, so what should I do?\"\n", + "response = RunGptLLM().stream_complete(promot)\n", + "for item in response:\n", + " print(item.text)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using `stream_chat` endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.llms.rungpt import RunGptLLM\n", + "\n", + "messages = [\n", + " ChatMessage(\n", + " role=MessageRole.USER,\n", + " content=\"Hello, my name is zihao, major in artificial intelligence.\",\n", + " ),\n", + " ChatMessage(role=MessageRole.ASSISTANT, content=\"Hello, what can I do for you?\"),\n", + " ChatMessage(\n", + " role=MessageRole.USER, content=\"Could you tell me what is my name and major?\"\n", + " ),\n", + "]\n", + "response = RunGptLLM.stream_chat(messages=messages)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for item in response:\n", + " print(item.message)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/llama_index/llms/rungpt.py b/llama_index/llms/rungpt.py new file mode 100644 index 0000000000000..9549c04b39c42 --- /dev/null +++ b/llama_index/llms/rungpt.py @@ -0,0 +1,290 @@ +from typing import Any, Optional, Sequence, Dict, List, Tuple, Union +import json + +try: + from pydantic.v1 import Field +except ImportError: + from pydantic import Field + + +from llama_index.llms.base import ( + LLM, + LLMMetadata, + ChatMessage, + ChatResponse, + ChatResponseGen, + MessageRole, + CompletionResponse, + ChatResponseAsyncGen, + CompletionResponseGen, + CompletionResponseAsyncGen, + llm_completion_callback, + llm_chat_callback, +) +from llama_index.constants import DEFAULT_CONTEXT_WINDOW +from llama_index.callbacks import CallbackManager + + +class RunGptLLM(LLM): + """The opengpt of Jina AI models.""" + + model: Optional[str] = Field(description="The rungpt model to use.") + endpoint: str = Field(description="The endpoint of serving address.") + temperature: float = Field(description="The temperature to use for sampling.") + max_tokens: Optional[int] = Field(description="Max tokens model generates.") + context_window: int = Field( + description="The maximum number of context tokens for the model." + ) + additional_kwargs: Dict[str, Any] = Field( + default_factory=dict, description="Additonal kwargs for the Replicate API." + ) + base_url: str = Field( + description="The address of your target model served by rungpt." + ) + + def __init__( + self, + model: Optional[str] = "rungpt", + endpoint: str = "0.0.0.0:51002", + temperature: float = 0.75, + max_tokens: Optional[int] = 256, + context_window: int = DEFAULT_CONTEXT_WINDOW, + additional_kwargs: Optional[Dict[str, Any]] = None, + callback_manager: Optional[CallbackManager] = None, + ): + if endpoint.startswith("http://"): + base_url = endpoint + else: + base_url = "http://" + endpoint + super().__init__( + model=model, + endpoint=endpoint, + temperature=temperature, + max_tokens=max_tokens, + context_window=context_window, + additional_kwargs=additional_kwargs or {}, + callback_manager=callback_manager or CallbackManager([]), + base_url=base_url, + ) + + @classmethod + def class_name(cls) -> str: + return "RunGptLLM" + + @property + def metadata(self) -> LLMMetadata: + """LLM metadata.""" + return LLMMetadata( + context_window=self.context_window, + num_output=self.max_tokens, + model_name=self._model, + ) + + @llm_completion_callback() + def complete(self, prompt: str, **kwargs: Any) -> CompletionResponse: + try: + import requests + except ImportError: + raise ImportError( + "Could not import requests library." + "Please install requests with `pip install requests`" + ) + response_gpt = requests.post( + self.base_url + "/generate", + json=self._request_pack("complete", prompt, **kwargs), + stream=False, + ).json() + + response_gpt = CompletionResponse( + text=response_gpt["choices"][0]["text"], + additional_kwargs=response_gpt["usage"], + raw=response_gpt, + ) + return response_gpt + + @llm_completion_callback() + def stream_complete(self, prompt: str, **kwargs: Any) -> CompletionResponseGen: + try: + import requests + except ImportError: + raise ImportError( + "Could not import requests library." + "Please install requests with `pip install requests`" + ) + response_gpt = requests.post( + self.base_url + "/generate_stream", + json=self._request_pack("complete", prompt, **kwargs), + stream=True, + ) + try: + import sseclient + except ImportError: + raise ImportError( + "Could not import sseclient-py library." + "Please install requests with `pip install sseclient-py`" + ) + client = sseclient.SSEClient(response_gpt) + response_iter = client.events() + + def gen() -> CompletionResponseGen: + text = "" + for item in response_iter: + item_dict = json.loads(json.dumps(eval(item.data))) + delta = item_dict["choices"][0]["text"] + additional_kwargs = item_dict["usage"] + text = text + delta + yield CompletionResponse( + text=text, + delta=delta, + raw=item_dict, + additional_kwargs=additional_kwargs, + ) + + return gen() + + @llm_chat_callback() + def chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse: + message_list = self._message_wrapper(messages) + try: + import requests + except ImportError: + raise ImportError( + "Could not import requests library." + "Please install requests with `pip install requests`" + ) + response_gpt = requests.post( + self.base_url + "/chat", + json=self._request_pack("chat", message_list, **kwargs), + stream=False, + ).json() + chat_message, _ = self._message_unpacker(response_gpt) + response_gpt = ChatResponse(message=chat_message, raw=response_gpt) + return response_gpt + + @llm_chat_callback() + def stream_chat( + self, messages: Sequence[ChatMessage], **kwargs: Any + ) -> ChatResponseGen: + message_list = self._message_wrapper(messages) + try: + import requests + except ImportError: + raise ImportError( + "Could not import requests library." + "Please install requests with `pip install requests`" + ) + response_gpt = requests.post( + self.base_url + "/chat_stream", + json=self._request_pack("chat", message_list, **kwargs), + stream=True, + ) + try: + import sseclient + except ImportError: + raise ImportError( + "Could not import sseclient-py library." + "Please install requests with `pip install sseclient-py`" + ) + client = sseclient.SSEClient(response_gpt) + chat_iter = client.events() + + def gen() -> ChatResponseGen: + content = "" + for item in chat_iter: + item_dict = json.loads(json.dumps(eval(item.data))) + chat_message, delta = self._message_unpacker(item_dict) + content = content + delta + chat_message.content = content + yield ChatResponse(message=chat_message, raw=item_dict, delta=delta) + + return gen() + + @llm_chat_callback() + async def achat( + self, + messages: Sequence[ChatMessage], + **kwargs: Any, + ) -> ChatResponse: + return self.chat(messages, **kwargs) + + @llm_chat_callback() + async def astream_chat( + self, + messages: Sequence[ChatMessage], + **kwargs: Any, + ) -> ChatResponseAsyncGen: + async def gen() -> ChatResponseAsyncGen: + for message in self.stream_chat(messages, **kwargs): + yield message + + # NOTE: convert generator to async generator + return gen() + + @llm_completion_callback() + async def acomplete(self, prompt: str, **kwargs: Any) -> CompletionResponse: + return self.complete(prompt, **kwargs) + + @llm_completion_callback() + async def astream_complete( + self, prompt: str, **kwargs: Any + ) -> CompletionResponseAsyncGen: + async def gen() -> CompletionResponseAsyncGen: + for message in self.stream_complete(prompt, **kwargs): + yield message + + return gen() + + def _message_wrapper(self, messages: Sequence[ChatMessage]) -> List[Dict[str, Any]]: + message_list = list() + for message in messages: + role = message.role.value + content = message.content + message_list.append({"role": role, "content": content}) + return message_list + + def _message_unpacker( + self, response_gpt: Dict[str, Any] + ) -> Tuple[ChatMessage, str]: + message = response_gpt["choices"][0]["message"] + additional_kwargs = response_gpt["usage"] + role = message["role"] + content = message["content"] + key = MessageRole.SYSTEM + for r in MessageRole: + if r.value == role: + key = r + chat_message = ChatMessage( + role=key, content=content, additional_kwargs=additional_kwargs + ) + return chat_message, content + + def _request_pack( + self, mode: str, prompt: Union[str, List[Dict[str, Any]]], **kwargs: Any + ) -> Optional[Dict[str, Any]]: + if mode == "complete": + return { + "prompt": prompt, + "max_tokens": kwargs.pop("max_tokens", self.max_tokens), + "temperature": kwargs.pop("temperature", self.temperature), + "top_k": kwargs.pop("top_k", 50), + "top_p": kwargs.pop("top_p", 0.95), + "repetition_penalty": kwargs.pop("repetition_penalty", 1.2), + "do_sample": kwargs.pop("do_sample", False), + "echo": kwargs.pop("echo", True), + "n": kwargs.pop("n", 1), + "stop": kwargs.pop("stop", "."), + } + elif mode == "chat": + return { + "messages": prompt, + "max_tokens": kwargs.pop("max_tokens", self.max_tokens), + "temperature": kwargs.pop("temperature", self.temperature), + "top_k": kwargs.pop("top_k", 50), + "top_p": kwargs.pop("top_p", 0.95), + "repetition_penalty": kwargs.pop("repetition_penalty", 1.2), + "do_sample": kwargs.pop("do_sample", False), + "echo": kwargs.pop("echo", True), + "n": kwargs.pop("n", 1), + "stop": kwargs.pop("stop", "."), + } + return None diff --git a/tests/llms/test_rungpt.py b/tests/llms/test_rungpt.py new file mode 100644 index 0000000000000..1fd74de8f3ff0 --- /dev/null +++ b/tests/llms/test_rungpt.py @@ -0,0 +1,253 @@ +from typing import List, Any, Generator, Dict +import pytest +from unittest.mock import patch, MagicMock +from llama_index.llms.base import ( + ChatMessage, + MessageRole, +) +from llama_index.llms.rungpt import RunGptLLM + +try: + import sseclient +except ImportError: + sseclient = None + + +def mock_completion(*args: Any, **kwargs: Any) -> Dict[str, Any]: + # Example taken from rungpt example inferece code on github repo. + return { + "id": None, + "object": "text_completion", + "created": 1692891018, + "choices": [ + {"text": "This is an indeed test.", "finish_reason": "length", "index": 0.0} + ], + "prompt": "Once upon a time,", + "usage": {"completion_tokens": 21, "total_tokens": 27, "prompt_tokens": 6}, + } + + +def mock_chat_completion(*args: Any, **kwargs: Any) -> Dict[str, Any]: + # Example taken from rungpt example inferece code on github repo. + return { + "id": None, + "object": "chat.completion", + "created": 1692892252, + "choices": [ + { + "finish_reason": "length", + "index": 0.0, + "message": {"content": "This is an indeed test.", "role": "assistant"}, + } + ], + "prompt": "Test prompt", + "usage": {"completion_tokens": 59, "total_tokens": 103, "prompt_tokens": 44}, + } + + +def mock_completion_stream(*args: Any, **kwargs: Any) -> Generator[str, None, None]: + # Example taken from rungpt example inferece code on github repo. + events = [ + str( + { + "id": None, + "object": "text_completion", + "created": 1692891964, + "choices": [{"text": "This", "finish_reason": None, "index": 0.0}], + "prompt": "This", + "usage": { + "completion_tokens": 1, + "total_tokens": 7, + "prompt_tokens": 6, + }, + } + ), + str( + { + "id": None, + "object": "text_completion", + "created": 1692891964, + "choices": [{"text": " is", "finish_reason": None, "index": 0.0}], + "prompt": " is", + "usage": { + "completion_tokens": 2, + "total_tokens": 9, + "prompt_tokens": 7, + }, + } + ), + str( + { + "id": None, + "object": "text_completion", + "created": 1692891964, + "choices": [{"text": " test.", "finish_reason": None, "index": 0.0}], + "prompt": " test.", + "usage": { + "completion_tokens": 3, + "total_tokens": 11, + "prompt_tokens": 8, + }, + } + ), + ] + for event in events: + yield event + + +def mock_chat_completion_stream( + *args: Any, **kwargs: Any +) -> Generator[str, None, None]: + # Example taken from rungpt example inferece code on github repo. + events = [ + str( + { + "id": None, + "object": "chat.completion", + "created": 1692892378, + "choices": [ + { + "finish_reason": None, + "index": 0.0, + "message": {"content": "This", "role": "assistant"}, + } + ], + "prompt": "Mock prompt", + "usage": { + "completion_tokens": 1, + "total_tokens": 45, + "prompt_tokens": 44, + }, + } + ), + str( + { + "id": None, + "object": "chat.completion", + "created": 1692892378, + "choices": [ + { + "finish_reason": None, + "index": 0.0, + "message": {"content": " is", "role": "assistant"}, + } + ], + "prompt": None, + "usage": { + "completion_tokens": 2, + "total_tokens": 47, + "prompt_tokens": 45, + }, + } + ), + str( + { + "id": None, + "object": "chat.completion", + "created": 1692892379, + "choices": [ + { + "finish_reason": None, + "index": 0.0, + "message": {"content": " test.", "role": "assistant"}, + } + ], + "prompt": None, + "usage": { + "completion_tokens": 3, + "total_tokens": 49, + "prompt_tokens": 46, + }, + } + ), + ] + for event in events: + yield event + + +def mock_chat_history(*args: Any, **kwargs: Any) -> List[ChatMessage]: + return [ + ChatMessage( + role=MessageRole.USER, + message="Hello, my name is zihao, major in artificial intelligence.", + ), + ChatMessage( + role=MessageRole.ASSISTANT, + message="Hello, what can I do for you?", + ), + ChatMessage( + role=MessageRole.USER, + message="Could you tell me what is my name and major?", + ), + ] + + +def test_init() -> None: + dummy = RunGptLLM(model="mock model", endpoint="0.0.0.0:51002") + assert dummy.model == "mock model" + assert dummy.endpoint == "0.0.0.0:51002" + assert isinstance(dummy, RunGptLLM) + + +def test_complete() -> None: + dummy = RunGptLLM() + with patch("requests.post") as mock_post: + mock_post.return_value.json.return_value = mock_completion() + response = dummy.complete("mock prompt") + assert response.text == "This is an indeed test." + + +@pytest.mark.parametrize( + "chat_history", [mock_chat_history(), tuple(mock_chat_history())] +) +def test_chat(chat_history: List[ChatMessage]) -> None: + with patch("requests.post") as mock_post: + mock_post.return_value.json.return_value = mock_chat_completion() + dummy = RunGptLLM() + response = dummy.chat(chat_history) + assert response.message.content == "This is an indeed test." + assert response.message.role == "assistant" + + +@pytest.mark.skipif(sseclient is None, reason="sseclient not installed") +@pytest.mark.parametrize( + "chat_history", [mock_chat_history(), tuple(mock_chat_history())] +) +def test_stream_chat(chat_history: List[ChatMessage]) -> None: + mock_events = [ + MagicMock(data=event_data) for event_data in mock_chat_completion_stream() + ] + mock_event_iterator = iter(mock_events) + + with patch("requests.post"), patch("sseclient.SSEClient") as mock_sseclient: + mock_response = MagicMock() + mock_response.json.return_value = {} + type(mock_response).status_code = 200 + mock_sseclient.return_value.events.return_value = mock_event_iterator + + dummy = RunGptLLM() + response_gen = dummy.stream_chat(chat_history) + responses = list(response_gen) + assert responses[-1].message.content == "This is test." + assert responses[-1].message.role == "assistant" + + +@pytest.mark.skipif(sseclient is None, reason="sseclient not installed") +def test_stream_complete() -> None: + mock_events = [ + MagicMock(data=event_data) for event_data in mock_completion_stream() + ] + mock_event_iterator = iter(mock_events) + mock_prompt = "A mock prompt" + + with patch("requests.post"), patch("sseclient.SSEClient") as mock_sseclient: + mock_response = MagicMock() + mock_response.json.return_value = {} + type(mock_response).status_code = 200 + mock_sseclient.return_value.events.return_value = mock_event_iterator + + dummy = RunGptLLM() + response_gen = dummy.stream_complete(mock_prompt) + responses = list(response_gen) + assert responses[-1].text == "This is test." + assert responses[-1].delta == " test." From 0da9b4dd9526b9011932613b52a0f77daf432b86 Mon Sep 17 00:00:00 2001 From: Riccardo Pinosio Date: Tue, 29 Aug 2023 06:13:48 +0200 Subject: [PATCH 10/17] update to_tool_list to add coroutine to to_tool_list() tools if available (#7282) --- CHANGELOG.md | 1 + llama_index/tools/tool_spec/base.py | 77 +++++++++++++++++++++++------ tests/tools/tool_spec/test_base.py | 36 ++++++++++++-- 3 files changed, 96 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7a427f6ed6a4..ab1feb8bfec1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added support for RunGPT LLM (#7401) - Integration guide and notebook with DeepEval (#7425) - Added `VectorIndex` and `VectaraRetriever` as a managed index (#7440) +- Added support for `to_tool_list` to detect and use async functions (#7282) ## [0.8.12] - 2023-08-28 diff --git a/llama_index/tools/tool_spec/base.py b/llama_index/tools/tool_spec/base.py index bafcda3a9ea42..02246456d823c 100644 --- a/llama_index/tools/tool_spec/base.py +++ b/llama_index/tools/tool_spec/base.py @@ -1,23 +1,27 @@ """Base tool spec class.""" + +from typing import List, Optional, Dict, Type, Union, Tuple, Callable, Awaitable, Any +from llama_index.tools.types import ToolMetadata +from llama_index.tools.function_tool import FunctionTool from inspect import signature -from typing import Dict, List, Optional, Type try: from pydantic.v1 import BaseModel except ImportError: from pydantic import BaseModel -from llama_index.tools.function_tool import FunctionTool -from llama_index.tools.types import ToolMetadata from llama_index.tools.utils import create_schema_from_function +import asyncio + +AsyncCallable = Callable[..., Awaitable[Any]] class BaseToolSpec: """Base tool spec class.""" # list of functions that you'd want to convert to spec - spec_functions: List[str] + spec_functions: List[Union[str, Tuple[str, str]]] def get_fn_schema_from_fn_name(self, fn_name: str) -> Optional[Type[BaseModel]]: """Return map from function name. @@ -39,22 +43,65 @@ def to_tool_list( """Convert tool spec to list of tools.""" func_to_metadata_mapping = func_to_metadata_mapping or {} tool_list = [] - for func_name in self.spec_functions: - func = getattr(self, func_name) - metadata = func_to_metadata_mapping.get(func_name, None) - if metadata is None: - name = func_name - docstring = func.__doc__ or "" - description = f"{name}{signature(func)}\n{docstring}" - fn_schema = self.get_fn_schema_from_fn_name(func_name) - metadata = ToolMetadata( - name=name, description=description, fn_schema=fn_schema + func_sync = None + func_async = None + for func_spec in self.spec_functions: + if isinstance(func_spec, str): + func = getattr(self, func_spec) + if asyncio.iscoroutinefunction(func): + func_async = func + else: + func_sync = func + metadata = func_to_metadata_mapping.get(func_spec, None) + if metadata is None: + name = func_spec + docstring = func.__doc__ or "" + description = f"{name}{signature(func)}\n{docstring}" + fn_schema = self.get_fn_schema_from_fn_name(func_spec) + metadata = ToolMetadata( + name=name, description=description, fn_schema=fn_schema + ) + elif isinstance(func_spec, tuple) and len(func_spec) == 2: + func_sync = getattr(self, func_spec[0]) + func_async = getattr(self, func_spec[1]) + metadata = func_to_metadata_mapping.get(func_spec[0], None) + if metadata is None: + metadata = func_to_metadata_mapping.get(func_spec[1], None) + if metadata is None: + name = func_spec[0] + docstring = func_sync.__doc__ or "" + description = f"{name}{signature(func_sync)}\n{docstring}" + fn_schema = self.get_fn_schema_from_fn_name(func_spec[0]) + metadata = ToolMetadata( + name=name, description=description, fn_schema=fn_schema + ) + else: + raise ValueError( + "spec_functions must be of type: List[Union[str, Tuple[str, str]]]" ) + + if func_sync is None: + if func_async is not None: + func_sync = patch_sync(func_async) + else: + raise ValueError( + f"Could not retrieve a function for spec: {func_spec}" + ) + tool = FunctionTool.from_defaults( - fn=func, + fn=func_sync, name=metadata.name, description=metadata.description, fn_schema=metadata.fn_schema, + async_fn=func_async, ) tool_list.append(tool) return tool_list + + +def patch_sync(func_async: AsyncCallable) -> Callable: + def patched_sync(*args: Any, **kwargs: Any) -> Any: + loop = asyncio.get_event_loop() + return loop.run_until_complete(func_async(*args, **kwargs)) + + return patched_sync diff --git a/tests/tools/tool_spec/test_base.py b/tests/tools/tool_spec/test_base.py index e94b7fe675739..4acd9086943eb 100644 --- a/tests/tools/tool_spec/test_base.py +++ b/tests/tools/tool_spec/test_base.py @@ -1,7 +1,5 @@ """Test tool spec.""" -from typing import List, Type - try: from pydantic.v1 import BaseModel except ImportError: @@ -10,6 +8,9 @@ from llama_index.tools.tool_spec.base import BaseToolSpec from llama_index.tools.types import ToolMetadata +from typing import List, Type, Tuple, Union +import pytest + class FooSchema(BaseModel): arg1: str @@ -25,7 +26,7 @@ class AbcSchema(BaseModel): class TestToolSpec(BaseToolSpec): - spec_functions: List[str] = ["foo", "bar", "abc"] + spec_functions: List[Union[str, Tuple[str, str]]] = ["foo", "bar", "abc"] def foo(self, arg1: str, arg2: int) -> str: """Foo.""" @@ -35,6 +36,14 @@ def bar(self, arg1: bool) -> str: """Bar.""" return f"bar {arg1}" + async def afoo(self, arg1: str, arg2: int) -> str: + """Afoo.""" + return self.foo(arg1=arg1, arg2=arg2) + + async def abar(self, arg1: bool) -> str: + """Abar.""" + return self.bar(arg1=arg1) + def abc(self, arg1: str) -> str: # NOTE: no docstring return f"bar {arg1}" @@ -43,6 +52,8 @@ def get_fn_schema_from_fn_name(self, fn_name: str) -> Type[BaseModel]: """Return map from function name.""" if fn_name == "foo": return FooSchema + elif fn_name == "afoo": + return FooSchema elif fn_name == "bar": return BarSchema elif fn_name == "abc": @@ -90,6 +101,25 @@ def test_tool_spec() -> None: assert fn_schema["properties"]["arg1"]["type"] == "boolean" +@pytest.mark.asyncio +async def test_tool_spec_async() -> None: + """Test async_fn of tool spec.""" + tool_spec = TestToolSpec() + tools = tool_spec.to_tool_list() + assert len(tools) == 3 + assert await tools[0].async_fn("hello", 1) == "foo hello 1" + assert str(await tools[1].acall(True)) == "bar True" + + +def test_async_patching() -> None: + # test sync patching of async function + tool_spec = TestToolSpec() + tool_spec.spec_functions = ["afoo"] + tools = tool_spec.to_tool_list() + assert len(tools) == 1 + assert tools[0].fn("hello", 1) == "foo hello 1" + + def test_tool_spec_schema() -> None: """Test tool spec schemas match.""" tool_spec = TestToolSpec() From 78e48cdeb33ddca967d87ba1cf4775d4a723f7d6 Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 29 Aug 2023 09:49:30 -0600 Subject: [PATCH 11/17] pass context template through (#7463) --- llama_index/chat_engine/context.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/llama_index/chat_engine/context.py b/llama_index/chat_engine/context.py index 1cd9399eff36b..55e3ecd132f16 100644 --- a/llama_index/chat_engine/context.py +++ b/llama_index/chat_engine/context.py @@ -62,6 +62,7 @@ def from_defaults( system_prompt: Optional[str] = None, prefix_messages: Optional[List[ChatMessage]] = None, node_postprocessors: Optional[List[BaseNodePostprocessor]] = None, + context_template: Optional[str] = None, **kwargs: Any, ) -> "ContextChatEngine": """Initialize a ContextChatEngine from default parameters.""" @@ -92,6 +93,7 @@ def from_defaults( prefix_messages=prefix_messages, node_postprocessors=node_postprocessors, callback_manager=service_context.callback_manager, + context_template=context_template, ) def _generate_context(self, message: str) -> Tuple[str, List[NodeWithScore]]: From 9638e27ecca57dfa7c264aff7c682df6a2eafd5c Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Tue, 29 Aug 2023 08:50:55 -0700 Subject: [PATCH 12/17] add embedding finetuning (#7452) --- .../embeddings/finetune_embedding.ipynb | 1376 +++++++++++++++++ llama_index/finetuning/__init__.py | 12 +- llama_index/finetuning/embeddings/__init__.py | 1 + .../embeddings/sentence_transformer.py | 171 ++ llama_index/finetuning/openai/base.py | 4 +- llama_index/finetuning/types.py | 17 +- 6 files changed, 1576 insertions(+), 5 deletions(-) create mode 100644 docs/examples/finetuning/embeddings/finetune_embedding.ipynb create mode 100644 llama_index/finetuning/embeddings/__init__.py create mode 100644 llama_index/finetuning/embeddings/sentence_transformer.py diff --git a/docs/examples/finetuning/embeddings/finetune_embedding.ipynb b/docs/examples/finetuning/embeddings/finetune_embedding.ipynb new file mode 100644 index 0000000000000..8cee1236f4263 --- /dev/null +++ b/docs/examples/finetuning/embeddings/finetune_embedding.ipynb @@ -0,0 +1,1376 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "551753b7-6cd2-4f81-aec0-da119e4705ad", + "metadata": {}, + "source": [ + "# Finetune Embeddings\n", + "\n", + "In this notebook, we show users how to finetune their own embedding models.\n", + "\n", + "We go through three main sections:\n", + "1. Preparing the data (our `generate_qa_embedding_pairs` function makes this easy)\n", + "2. Finetuning the model (using our `SentenceTransformersFinetuneEngine`)\n", + "3. Evaluating the model on a validation knowledge corpus" + ] + }, + { + "cell_type": "markdown", + "id": "99afd542-fc47-44ac-aed0-b3684108dba5", + "metadata": {}, + "source": [ + "## Generate Corpus\n", + "\n", + "First, we create the corpus of text chunks by leveraging LlamaIndex to load some financial PDFs, and parsing/chunking into plain text chunks." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9280d438-b6bd-4ccf-a730-7c8bb3ebdbeb", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "from llama_index import SimpleDirectoryReader\n", + "from llama_index.node_parser import SimpleNodeParser\n", + "from llama_index.schema import MetadataMode" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c5e890bc-557b-4d3c-bede-3e80dfeeee18", + "metadata": {}, + "outputs": [], + "source": [ + "TRAIN_FILES = [\"../../../examples/data/10k/lyft_2021.pdf\"]\n", + "VAL_FILES = [\"../../../examples/data/10k/uber_2021.pdf\"]\n", + "\n", + "TRAIN_CORPUS_FPATH = \"./data/train_corpus.json\"\n", + "VAL_CORPUS_FPATH = \"./data/val_corpus.json\"" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1da871c1-9d58-467a-92fd-06ed3d94534b", + "metadata": {}, + "outputs": [], + "source": [ + "def load_corpus(files, verbose=False):\n", + " if verbose:\n", + " print(f\"Loading files {files}\")\n", + "\n", + " reader = SimpleDirectoryReader(input_files=files)\n", + " docs = reader.load_data()\n", + " if verbose:\n", + " print(f\"Loaded {len(docs)} docs\")\n", + "\n", + " parser = SimpleNodeParser.from_defaults()\n", + " nodes = parser.get_nodes_from_documents(docs, show_progress=verbose)\n", + "\n", + " if verbose:\n", + " print(f\"Parsed {len(nodes)} nodes\")\n", + "\n", + " return nodes" + ] + }, + { + "cell_type": "markdown", + "id": "53056d8b-3b4c-4364-9b07-a375aa84330b", + "metadata": {}, + "source": [ + "We do a very naive train/val split by having the Lyft corpus as the train dataset, and the Uber corpus as the val dataset." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "d3651c77-d085-4fbc-bb34-61f143ad6674", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loading files ['../../../examples/data/10k/lyft_2021.pdf']\n", + "Loaded 238 docs\n" + ] + }, + { + "data": { + "application/json": { + "ascii": false, + "bar_format": null, + "colour": null, + "elapsed": 0.0050051212310791016, + "initial": 0, + "n": 0, + "ncols": null, + "nrows": 37, + "postfix": null, + "prefix": "Parsing documents into nodes", + "rate": null, + "total": 238, + "unit": "it", + "unit_divisor": 1000, + "unit_scale": false + }, + "application/vnd.jupyter.widget-view+json": { + "model_id": "a65de1f9b2b94be4a3f58a5a2881a695", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Parsing documents into nodes: 0%| | 0/238 [00:00)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "embed_model" + ] + }, + { + "cell_type": "markdown", + "id": "828dd6fe-9a8a-419b-8663-56d81ce73774", + "metadata": {}, + "source": [ + "## Evaluate Finetuned Model" + ] + }, + { + "cell_type": "markdown", + "id": "f4a66b83-4cbb-4374-a632-0f1bb2b785ab", + "metadata": {}, + "source": [ + "In this section, we evaluate 3 different embedding models: \n", + "1. proprietary OpenAI embedding,\n", + "2. open source `BAAI/bge-small-en`, and\n", + "3. our finetuned embedding model.\n", + "\n", + "We consider 2 evaluation approaches:\n", + "1. a simple custom **hit rate** metric\n", + "2. using `InformationRetrievalEvaluator` from sentence_transformers\n", + "\n", + "We show that finetuning on synthetic (LLM-generated) dataset significantly improve upon an opensource embedding model." + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "id": "57d5176f-1f21-4bcb-adf5-da1c4cccb8d3", + "metadata": {}, + "outputs": [], + "source": [ + "from llama_index.embeddings import OpenAIEmbedding\n", + "from llama_index import ServiceContext, VectorStoreIndex\n", + "from llama_index.schema import TextNode\n", + "from tqdm.notebook import tqdm\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "dda4c2b8-1ad8-420c-83d2-b88e0519895d", + "metadata": {}, + "source": [ + "### Define eval function" + ] + }, + { + "cell_type": "markdown", + "id": "398c24d3-3d72-4ce8-94a4-2da9c1b2605c", + "metadata": {}, + "source": [ + "**Option 1**: We use a simple **hit rate** metric for evaluation:\n", + "* for each (query, relevant_doc) pair,\n", + "* we retrieve top-k documents with the query, and \n", + "* it's a **hit** if the results contain the relevant_doc.\n", + "\n", + "This approach is very simple and intuitive, and we can apply it to both the proprietary OpenAI embedding as well as our open source and fine-tuned embedding models." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "b89401d3-a157-4f96-86d4-212e631a54bc", + "metadata": {}, + "outputs": [], + "source": [ + "def evaluate(\n", + " dataset,\n", + " embed_model,\n", + " top_k=5,\n", + " verbose=False,\n", + "):\n", + " corpus = dataset.corpus\n", + " queries = dataset.queries\n", + " relevant_docs = dataset.relevant_docs\n", + "\n", + " service_context = ServiceContext.from_defaults(embed_model=embed_model)\n", + " nodes = [TextNode(id_=id_, text=text) for id_, text in corpus.items()]\n", + " index = VectorStoreIndex(nodes, service_context=service_context, show_progress=True)\n", + " retriever = index.as_retriever(similarity_top_k=top_k)\n", + "\n", + " eval_results = []\n", + " for query_id, query in tqdm(queries.items()):\n", + " retrieved_nodes = retriever.retrieve(query)\n", + " retrieved_ids = [node.node.node_id for node in retrieved_nodes]\n", + " expected_id = relevant_docs[query_id][0]\n", + " is_hit = expected_id in retrieved_ids # assume 1 relevant doc\n", + "\n", + " eval_result = {\n", + " \"is_hit\": is_hit,\n", + " \"retrieved\": retrieved_ids,\n", + " \"expected\": expected_id,\n", + " \"query\": query_id,\n", + " }\n", + " eval_results.append(eval_result)\n", + " return eval_results" + ] + }, + { + "cell_type": "markdown", + "id": "7eb16251-bb45-4de0-b65a-e15aa76e0f1e", + "metadata": {}, + "source": [ + "**Option 2**: We use the `InformationRetrievalEvaluator` from sentence_transformers.\n", + "\n", + "This provides a more comprehensive suite of metrics, but we can only run it against the sentencetransformers compatible models (open source and our finetuned model, *not* the OpenAI embedding model)." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "88e89702-ea35-4c22-99c7-f89a5428ef95", + "metadata": {}, + "outputs": [], + "source": [ + "from sentence_transformers.evaluation import InformationRetrievalEvaluator\n", + "from sentence_transformers import SentenceTransformer\n", + "\n", + "\n", + "def evaluate_st(\n", + " dataset,\n", + " model_id,\n", + " name,\n", + "):\n", + " corpus = dataset.corpus\n", + " queries = dataset.queries\n", + " relevant_docs = dataset.relevant_docs\n", + "\n", + " evaluator = InformationRetrievalEvaluator(queries, corpus, relevant_docs, name=name)\n", + " model = SentenceTransformer(model_id)\n", + " return evaluator(model, output_path=\"results/\")" + ] + }, + { + "cell_type": "markdown", + "id": "af2d33dd-c39f-4c05-8adc-65db12163c88", + "metadata": {}, + "source": [ + "### Run Evals" + ] + }, + { + "cell_type": "markdown", + "id": "c630aa25-2395-4a8b-83cf-2885fbc862f4", + "metadata": {}, + "source": [ + "#### OpenAI\n", + "\n", + "Note: this might take a few minutes to run since we have to embed the corpus and queries" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "61a0784f-415e-4d3a-8c88-757b28b9e5df", + "metadata": {}, + "outputs": [ + { + "data": { + "application/json": { + "ascii": false, + "bar_format": null, + "colour": null, + "elapsed": 0.005716085433959961, + "initial": 0, + "n": 0, + "ncols": null, + "nrows": 28, + "postfix": null, + "prefix": "Generating embeddings", + "rate": null, + "total": 418, + "unit": "it", + "unit_divisor": 1000, + "unit_scale": false + }, + "application/vnd.jupyter.widget-view+json": { + "model_id": "c85624354f984327a431332423245100", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Generating embeddings: 0%| | 0/418 [00:00 1\u001b[0m \u001b[43mevaluate_st\u001b[49m\u001b[43m(\u001b[49m\u001b[43mval_dataset\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBAAI/bge-small-en\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mbge\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[0;32mIn[49], line 15\u001b[0m, in \u001b[0;36mevaluate_st\u001b[0;34m(dataset, model_id, name)\u001b[0m\n\u001b[1;32m 13\u001b[0m evaluator \u001b[38;5;241m=\u001b[39m InformationRetrievalEvaluator(queries, corpus, relevant_docs, name\u001b[38;5;241m=\u001b[39mname)\n\u001b[1;32m 14\u001b[0m model \u001b[38;5;241m=\u001b[39m SentenceTransformer(model_id)\n\u001b[0;32m---> 15\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mevaluator\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moutput_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mresults/\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Programming/gpt_index/.venv/lib/python3.10/site-packages/sentence_transformers/evaluation/InformationRetrievalEvaluator.py:104\u001b[0m, in \u001b[0;36mInformationRetrievalEvaluator.__call__\u001b[0;34m(self, model, output_path, epoch, steps, *args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m csv_path \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(output_path, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcsv_file)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39misfile(csv_path):\n\u001b[0;32m--> 104\u001b[0m fOut \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcsv_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mw\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mutf-8\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 105\u001b[0m fOut\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m,\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcsv_headers))\n\u001b[1;32m 106\u001b[0m fOut\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'results/Information-Retrieval_evaluation_bge_results.csv'" + ] + } + ], + "source": [ + "evaluate_st(val_dataset, \"BAAI/bge-small-en\", name=\"bge\")" + ] + }, + { + "cell_type": "markdown", + "id": "1fd87550-f547-4b8b-b21a-f72b355e2cd7", + "metadata": {}, + "source": [ + "### Finetuned" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "402dd440-1934-4778-8ff5-28e15cf1f2d3", + "metadata": {}, + "outputs": [], + "source": [ + "finetuned = \"local:exp_finetune\"\n", + "val_results_finetuned = evaluate(val_dataset, finetuned)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ffd24643-17cb-4773-a535-77f3f8fa2d48", + "metadata": {}, + "outputs": [], + "source": [ + "df_finetuned = pd.DataFrame(val_results_finetuned)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec1dccd1-bbd4-427f-a520-b1011643d83b", + "metadata": {}, + "outputs": [], + "source": [ + "hit_rate_finetuned = df_finetuned[\"is_hit\"].mean()\n", + "hit_rate_finetuned" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d8dd38e-f13d-43e1-9802-cc94b854526b", + "metadata": {}, + "outputs": [], + "source": [ + "evaluate_st(val_dataset, \"exp_finetune\", name=\"finetuned\")" + ] + }, + { + "cell_type": "markdown", + "id": "fbc290bc-5cc3-4ee4-b8ab-e68371441643", + "metadata": {}, + "source": [ + "### Summary of Results" + ] + }, + { + "cell_type": "markdown", + "id": "6f906a11-6a95-4f10-9069-140bf5a56246", + "metadata": {}, + "source": [ + "#### Hit rate" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "705fbe3c-2843-4bab-bb5c-16027fc5564b", + "metadata": {}, + "outputs": [], + "source": [ + "df_ada[\"model\"] = \"ada\"\n", + "df_bge[\"model\"] = \"bge\"\n", + "df_finetuned[\"model\"] = \"fine_tuned\"" + ] + }, + { + "cell_type": "markdown", + "id": "bebc363c-cd07-4dab-916e-1618d16d1254", + "metadata": {}, + "source": [ + "We can see that fine-tuning our small open-source embedding model drastically improve its retrieval quality (even approaching the quality of the proprietary OpenAI embedding)!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "57f38b4b-1b40-42da-a054-ea9593d3e602", + "metadata": {}, + "outputs": [], + "source": [ + "df_all = pd.concat([df_ada, df_bge, df_finetuned])\n", + "df_all.groupby(\"model\").mean(\"is_hit\")" + ] + }, + { + "cell_type": "markdown", + "id": "08094d07-2c0a-44ca-ad2f-8d8bf1387ed9", + "metadata": {}, + "source": [ + "#### InformationRetrievalEvaluator" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27d0444e-a824-42d6-9ddb-4da7179902bc", + "metadata": {}, + "outputs": [], + "source": [ + "df_st_bge = pd.read_csv(\"results/Information-Retrieval_evaluation_bge_results.csv\")\n", + "df_st_finetuned = pd.read_csv(\n", + " \"results/Information-Retrieval_evaluation_finetuned_results.csv\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "c0903ed3-df05-4d98-8b0a-6f352c681735", + "metadata": {}, + "source": [ + "We can see that embedding finetuning improves metrics consistently across the suite of eval metrics " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81ec1c46-5aa0-4f8a-a0c5-2553e08cceb1", + "metadata": {}, + "outputs": [], + "source": [ + "df_st_bge[\"model\"] = \"bge\"\n", + "df_st_finetuned[\"model\"] = \"fine_tuned\"\n", + "df_st_all = pd.concat([df_st_bge, df_st_finetuned])\n", + "df_st_all = df_st_all.set_index(\"model\")\n", + "df_st_all" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "llama_index_v2", + "language": "python", + "name": "llama_index_v2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/llama_index/finetuning/__init__.py b/llama_index/finetuning/__init__.py index a6b54faaecc4e..276bc55d9c35d 100644 --- a/llama_index/finetuning/__init__.py +++ b/llama_index/finetuning/__init__.py @@ -1,5 +1,15 @@ """Finetuning modules.""" from llama_index.finetuning.openai.base import OpenAIFinetuneEngine +from llama_index.finetuning.embeddings.sentence_transformer import ( + generate_qa_embedding_pairs, + EmbeddingQAFinetuneDataset, + SentenceTransformersFinetuneEngine, +) -__all__ = ["OpenAIFinetuneEngine"] +__all__ = [ + "OpenAIFinetuneEngine", + "generate_qa_embedding_pairs", + "EmbeddingQAFinetuneDataset", + "SentenceTransformersFinetuneEngine", +] diff --git a/llama_index/finetuning/embeddings/__init__.py b/llama_index/finetuning/embeddings/__init__.py new file mode 100644 index 0000000000000..c637335013c59 --- /dev/null +++ b/llama_index/finetuning/embeddings/__init__.py @@ -0,0 +1 @@ +"""Init params.""" diff --git a/llama_index/finetuning/embeddings/sentence_transformer.py b/llama_index/finetuning/embeddings/sentence_transformer.py new file mode 100644 index 0000000000000..5893942c0310c --- /dev/null +++ b/llama_index/finetuning/embeddings/sentence_transformer.py @@ -0,0 +1,171 @@ +"""Sentence Transformer Finetuning Engine.""" + +from llama_index.embeddings.base import BaseEmbedding + +from typing import Dict, Any, List, Optional +from pydantic import BaseModel + +from llama_index.schema import TextNode, MetadataMode +from llama_index.llms.openai import OpenAI +from llama_index.llms.base import LLM +from llama_index.embeddings.utils import resolve_embed_model +from llama_index.finetuning.types import BaseEmbeddingFinetuneEngine +from tqdm import tqdm +import uuid +import re +import json + + +class EmbeddingQAFinetuneDataset(BaseModel): + """Embedding QA Finetuning Dataset.""" + + queries: Dict[str, str] # dict id -> query + corpus: Dict[str, str] # dict id -> string + relevant_docs: Dict[str, List[str]] # query id -> list of doc ids + + def save_json(self, path: str) -> None: + """Save json.""" + with open(path, "w") as f: + json.dump(self.dict(), f, indent=4) + + @classmethod + def from_json(cls, path: str) -> "EmbeddingQAFinetuneDataset": + """Load json.""" + with open(path, "r") as f: + data = json.load(f) + return cls(**data) + + +DEFAULT_QA_GENERATE_PROMPT_TMPL = """\ +Context information is below. + +--------------------- +{context_str} +--------------------- + +Given the context information and not prior knowledge. +generate only questions based on the below query. + +You are a Teacher/ Professor. Your task is to setup \ +{num_questions_per_chunk} questions for an upcoming \ +quiz/examination. The questions should be diverse in nature \ +across the document. Restrict the questions to the \ +context information provided." +""" + + +# generate queries as a convenience function +def generate_qa_embedding_pairs( + nodes: List[TextNode], + llm: Optional[LLM] = None, + qa_generate_prompt_tmpl: str = DEFAULT_QA_GENERATE_PROMPT_TMPL, + num_questions_per_chunk: int = 2, +) -> EmbeddingQAFinetuneDataset: + """Generate examples given a set of nodes.""" + node_dict = { + node.node_id: node.get_content(metadata_mode=MetadataMode.NONE) + for node in nodes + } + + llm = llm or OpenAI(model="gpt-3.5-turbo") + + queries = {} + relevant_docs = {} + for node_id, text in tqdm(node_dict.items()): + query = qa_generate_prompt_tmpl.format( + context_str=text, num_questions_per_chunk=num_questions_per_chunk + ) + response = llm.complete(query) + + result = str(response).strip().split("\n") + questions = [ + re.sub(r"^\d+[\).\s]", "", question).strip() for question in result + ] + questions = [question for question in questions if len(question) > 0] + + for question in questions: + question_id = str(uuid.uuid4()) + queries[question_id] = question + relevant_docs[question_id] = [node_id] + + # construct dataset + dataset = EmbeddingQAFinetuneDataset( + queries=queries, corpus=node_dict, relevant_docs=relevant_docs + ) + + return dataset + + +class SentenceTransformersFinetuneEngine(BaseEmbeddingFinetuneEngine): + """Sentence Transformers Finetune Engine.""" + + def __init__( + self, + dataset: EmbeddingQAFinetuneDataset, + model_id: str = "BAAI/bge-small-en", + model_output_path: str = "exp_finetune", + batch_size: int = 10, + val_dataset: Optional[EmbeddingQAFinetuneDataset] = None, + loss: Optional[Any] = None, + epochs: int = 2, + show_progress_bar: bool = True, + evaluation_steps: int = 50, + ) -> None: + """Init params.""" + from sentence_transformers import InputExample, SentenceTransformer, losses + from torch.utils.data import DataLoader + + self.dataset = dataset + + self.model_id = model_id + self.model_output_path = model_output_path + self.model = SentenceTransformer(model_id) + + # TODO: support more than 1 doc per query + examples: Any = [] + for query_id, query in dataset.queries.items(): + node_id = dataset.relevant_docs[query_id][0] + text = dataset.corpus[node_id] + example = InputExample(texts=[query, text]) + examples.append(example) + self.examples = examples + + self.loader: DataLoader = DataLoader(examples, batch_size=batch_size) + + # define evaluator + from sentence_transformers.evaluation import InformationRetrievalEvaluator + + evaluator: Optional[InformationRetrievalEvaluator] = None + if val_dataset is not None: + evaluator = InformationRetrievalEvaluator( + val_dataset.queries, val_dataset.corpus, val_dataset.relevant_docs + ) + self.evaluator = evaluator + + # define loss + self.loss = loss or losses.MultipleNegativesRankingLoss(self.model) + + self.epochs = epochs + self.show_progress_bar = show_progress_bar + self.evaluation_steps = evaluation_steps + self.warmup_steps = int(len(self.loader) * epochs * 0.1) + + def finetune(self, **train_kwargs: Any) -> None: + """Finetune model.""" + self.model.fit( + train_objectives=[(self.loader, self.loss)], + epochs=self.epochs, + warmup_steps=self.warmup_steps, + output_path=self.model_output_path, + show_progress_bar=self.show_progress_bar, + evaluator=self.evaluator, + evaluation_steps=self.evaluation_steps, + ) + + def get_finetuned_model(self, **model_kwargs: Any) -> BaseEmbedding: + """Gets finetuned model.""" + + embed_model_str = "local:" + self.model_output_path + embed_model = resolve_embed_model(embed_model_str) + + return embed_model diff --git a/llama_index/finetuning/openai/base.py b/llama_index/finetuning/openai/base.py index d12595f42c3e2..c0e2b1328b2ed 100644 --- a/llama_index/finetuning/openai/base.py +++ b/llama_index/finetuning/openai/base.py @@ -1,6 +1,6 @@ """OpenAI Finetuning.""" -from llama_index.finetuning.types import BaseFinetuningEngine +from llama_index.finetuning.types import BaseLLMFinetuneEngine from llama_index.callbacks import OpenAIFineTuningHandler from llama_index.finetuning.openai.validate_json import validate_json from typing import Any, Optional @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -class OpenAIFinetuneEngine(BaseFinetuningEngine): +class OpenAIFinetuneEngine(BaseLLMFinetuneEngine): """OpenAI Finetuning Engine.""" def __init__( diff --git a/llama_index/finetuning/types.py b/llama_index/finetuning/types.py index 63ac3f2cb0870..c2ba5ad546dfb 100644 --- a/llama_index/finetuning/types.py +++ b/llama_index/finetuning/types.py @@ -2,11 +2,12 @@ from abc import ABC, abstractmethod from llama_index.llms.base import LLM +from llama_index.embeddings.base import BaseEmbedding from typing import Any -class BaseFinetuningEngine(ABC): - """Base finetuning engine.""" +class BaseLLMFinetuneEngine(ABC): + """Base LLM finetuning engine.""" @abstractmethod def finetune(self) -> None: @@ -15,3 +16,15 @@ def finetune(self) -> None: @abstractmethod def get_finetuned_model(self, **model_kwargs: Any) -> LLM: """Gets finetuned model.""" + + +class BaseEmbeddingFinetuneEngine(ABC): + """Base Embedding finetuning engine.""" + + @abstractmethod + def finetune(self) -> None: + """Goes off and does stuff.""" + + @abstractmethod + def get_finetuned_model(self, **model_kwargs: Any) -> BaseEmbedding: + """Gets finetuned model.""" From 1bd5eca7ab9f2914b5ad919c263f544d40bed5d3 Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Tue, 29 Aug 2023 09:02:39 -0700 Subject: [PATCH 13/17] patch integrations docs (#7464) --- docs/community/integrations.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/community/integrations.md b/docs/community/integrations.md index 13ec68863af54..e72ada566eb09 100644 --- a/docs/community/integrations.md +++ b/docs/community/integrations.md @@ -13,7 +13,7 @@ The full set of agent tools are found on [LlamaHub](https://llamahub.ai/) The full set of supported LLMs are found [here](/core_modules/model_modules/llms/modules.md). -## Observability/Tracing +## Observability/Tracing/Evaluation Check out our [one-click observability](/end_to_end_tutorials/one_click_observability.md) page for full tracing integrations. @@ -25,6 +25,7 @@ maxdepth: 1 /end_to_end_tutorials/one_click_observability.md integrations/graphsignal.md integrations/trulens.md +integrations/deepeval.md ``` @@ -38,16 +39,16 @@ Guardrails OpenAI Function Calling ``` -## Storage +## Storage and Managed Indexes ```{toctree} --- maxdepth: 1 --- integrations/vector_stores.md integrations/graph_stores.md +integrations/managed_indices.md ``` - ## Application Frameworks ```{toctree} --- From ecc5a0520cf6c2cb5d872b1fefbe249163ba5717 Mon Sep 17 00:00:00 2001 From: Jerry Liu Date: Tue, 29 Aug 2023 09:13:00 -0700 Subject: [PATCH 14/17] [version] bump version to 0.8.13 (#7465) --- CHANGELOG.md | 3 ++- docs/end_to_end_tutorials/finetuning.md | 8 ++++++++ experimental/openai_fine_tuning/openai_fine_tuning.ipynb | 9 ++++----- llama_index/VERSION | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1feb8bfec1a..aa4c7080c49e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # ChangeLog -## Unreleased +## [0.8.13] - 2023-08-29 ### New Features +- Add embedding finetuning (#7452) - Added support for RunGPT LLM (#7401) - Integration guide and notebook with DeepEval (#7425) - Added `VectorIndex` and `VectaraRetriever` as a managed index (#7440) diff --git a/docs/end_to_end_tutorials/finetuning.md b/docs/end_to_end_tutorials/finetuning.md index b04a5fba1443c..c571827dc281b 100644 --- a/docs/end_to_end_tutorials/finetuning.md +++ b/docs/end_to_end_tutorials/finetuning.md @@ -36,6 +36,14 @@ We created a comprehensive repo/guide showing you how to finetune an open-source Finetuning gives you a 5-10% increase in retrieval evaluation metrics. You can then plug this fine-tuned model into your RAG application with LlamaIndex. +```{toctree} +--- +maxdepth: 1 +--- +Embedding Fine-tuning Guide +``` + +**Old** ```{toctree} --- maxdepth: 1 diff --git a/experimental/openai_fine_tuning/openai_fine_tuning.ipynb b/experimental/openai_fine_tuning/openai_fine_tuning.ipynb index 9f44573674802..11945bad226fb 100644 --- a/experimental/openai_fine_tuning/openai_fine_tuning.ipynb +++ b/experimental/openai_fine_tuning/openai_fine_tuning.ipynb @@ -811,7 +811,7 @@ ], "metadata": { "kernelspec": { - "display_name": "llama-index", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -825,10 +825,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" - }, - "orig_nbformat": 4 + "version": "3.10.10" + } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/llama_index/VERSION b/llama_index/VERSION index 7eff8ab952664..c2f73c6ecf7c1 100644 --- a/llama_index/VERSION +++ b/llama_index/VERSION @@ -1 +1 @@ -0.8.12 +0.8.13 From d93693a33f55f1bd9440590b4cfcd053c48caa9a Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 29 Aug 2023 16:08:00 -0600 Subject: [PATCH 15/17] support both str and templates for query_wrapper_prompt in HF LLMs (#7473) --- llama_index/llms/huggingface.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/llama_index/llms/huggingface.py b/llama_index/llms/huggingface.py index ab842a0b31966..4aedaffbfc9ed 100644 --- a/llama_index/llms/huggingface.py +++ b/llama_index/llms/huggingface.py @@ -1,6 +1,6 @@ import logging from threading import Thread -from typing import Any, List, Optional +from typing import Any, List, Optional, Union try: from pydantic.v1 import Field, PrivateAttr @@ -15,6 +15,7 @@ llm_completion_callback, ) from llama_index.llms.custom import CustomLLM +from llama_index.prompts.base import PromptTemplate logger = logging.getLogger(__name__) @@ -41,7 +42,8 @@ class HuggingFaceLLM(CustomLLM): query_wrapper_prompt: str = Field( description=( "The query wrapper prompt, containing the query placeholder. " - "The model card on HuggingFace should specify if this is needed." + "The model card on HuggingFace should specify if this is needed. " + "Should contain a `{query_str}` placeholder." ), ) tokenizer_name: str = Field( @@ -86,7 +88,7 @@ def __init__( context_window: int = 4096, max_new_tokens: int = 256, system_prompt: str = "", - query_wrapper_prompt: str = "", + query_wrapper_prompt: Union[str, PromptTemplate] = "{query_str}", tokenizer_name: str = "StabilityAI/stablelm-tuned-alpha-3b", model_name: str = "StabilityAI/stablelm-tuned-alpha-3b", model: Optional[Any] = None, @@ -151,6 +153,9 @@ def __call__( self._stopping_criteria = StoppingCriteriaList([StopOnTokens()]) + if isinstance(query_wrapper_prompt, PromptTemplate): + query_wrapper_prompt = query_wrapper_prompt.template + super().__init__( context_window=context_window, max_new_tokens=max_new_tokens, From 9b6c14c786664c85a476b9b054f22489ea3dcc8a Mon Sep 17 00:00:00 2001 From: Logan Date: Tue, 29 Aug 2023 16:55:25 -0600 Subject: [PATCH 16/17] improve fine-tuned model parsing (#7474) --- CHANGELOG.md | 5 +++++ llama_index/llms/openai_utils.py | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa4c7080c49e3..f6750ddcf3987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # ChangeLog +## Unreleased + +### Bug Fixes / Nits +- Improve openai fine-tuned model parsing (#7474) + ## [0.8.13] - 2023-08-29 ### New Features diff --git a/llama_index/llms/openai_utils.py b/llama_index/llms/openai_utils.py index a54d9b9b31328..5b51e418002cc 100644 --- a/llama_index/llms/openai_utils.py +++ b/llama_index/llms/openai_utils.py @@ -176,10 +176,10 @@ def openai_modelname_to_contextsize(modelname: str) -> int: https://github.com/hwchase17/langchain/blob/master/langchain/llms/openai.py """ # handling finetuned models - if "ft-" in modelname: # legacy fine-tuning - modelname = modelname.split(":")[0] - elif modelname.startswith("ft:"): + if modelname.startswith("ft:"): modelname = modelname.split(":")[1] + elif ":ft-" in modelname: # legacy fine-tuning + modelname = modelname.split(":")[0] if modelname in DISCONTINUED_MODELS: raise ValueError( From bbb911c26aa49f1824e66cf1897cffad62e7461c Mon Sep 17 00:00:00 2001 From: Sourabh Desai Date: Tue, 29 Aug 2023 16:31:10 -0700 Subject: [PATCH 17/17] doing some code de-duplication (#7468) --- llama_index/tools/function_tool.py | 20 +++++++++------ llama_index/tools/tool_spec/base.py | 38 ++++++++++++++++------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/llama_index/tools/function_tool.py b/llama_index/tools/function_tool.py index da34e116826cc..0e9d7c14a03f3 100644 --- a/llama_index/tools/function_tool.py +++ b/llama_index/tools/function_tool.py @@ -50,16 +50,20 @@ def from_defaults( description: Optional[str] = None, fn_schema: Optional[Type[BaseModel]] = None, async_fn: Optional[AsyncCallable] = None, + tool_metadata: Optional[ToolMetadata] = None, ) -> "FunctionTool": - name = name or fn.__name__ - docstring = fn.__doc__ - description = description or f"{name}{signature(fn)}\n{docstring}" - if fn_schema is None: - fn_schema = create_schema_from_function( - f"{name}", fn, additional_fields=None + if tool_metadata is None: + name = name or fn.__name__ + docstring = fn.__doc__ + description = description or f"{name}{signature(fn)}\n{docstring}" + if fn_schema is None: + fn_schema = create_schema_from_function( + f"{name}", fn, additional_fields=None + ) + tool_metadata = ToolMetadata( + name=name, description=description, fn_schema=fn_schema ) - metadata = ToolMetadata(name=name, description=description, fn_schema=fn_schema) - return cls(fn=fn, metadata=metadata, async_fn=async_fn) + return cls(fn=fn, metadata=tool_metadata, async_fn=async_fn) @property def metadata(self) -> ToolMetadata: diff --git a/llama_index/tools/tool_spec/base.py b/llama_index/tools/tool_spec/base.py index 02246456d823c..6c31418b2f11b 100644 --- a/llama_index/tools/tool_spec/base.py +++ b/llama_index/tools/tool_spec/base.py @@ -36,6 +36,24 @@ def get_fn_schema_from_fn_name(self, fn_name: str) -> Optional[Type[BaseModel]]: raise ValueError(f"Invalid function name: {fn_name}") + def get_metadata_from_fn_name(self, fn_name: str) -> Optional[ToolMetadata]: + """Return map from function name. + + Return type is Optional, meaning that the schema can be None. + In this case, it's up to the downstream tool implementation to infer the schema. + + """ + try: + func = getattr(self, fn_name) + except AttributeError: + return None + name = fn_name + docstring = func.__doc__ or "" + description = f"{name}{signature(func)}\n{docstring}" + fn_schema = self.get_fn_schema_from_fn_name(fn_name) + metadata = ToolMetadata(name=name, description=description, fn_schema=fn_schema) + return metadata + def to_tool_list( self, func_to_metadata_mapping: Optional[Dict[str, ToolMetadata]] = None, @@ -54,13 +72,7 @@ def to_tool_list( func_sync = func metadata = func_to_metadata_mapping.get(func_spec, None) if metadata is None: - name = func_spec - docstring = func.__doc__ or "" - description = f"{name}{signature(func)}\n{docstring}" - fn_schema = self.get_fn_schema_from_fn_name(func_spec) - metadata = ToolMetadata( - name=name, description=description, fn_schema=fn_schema - ) + metadata = self.get_metadata_from_fn_name(func_spec) elif isinstance(func_spec, tuple) and len(func_spec) == 2: func_sync = getattr(self, func_spec[0]) func_async = getattr(self, func_spec[1]) @@ -68,13 +80,7 @@ def to_tool_list( if metadata is None: metadata = func_to_metadata_mapping.get(func_spec[1], None) if metadata is None: - name = func_spec[0] - docstring = func_sync.__doc__ or "" - description = f"{name}{signature(func_sync)}\n{docstring}" - fn_schema = self.get_fn_schema_from_fn_name(func_spec[0]) - metadata = ToolMetadata( - name=name, description=description, fn_schema=fn_schema - ) + metadata = self.get_metadata_from_fn_name(func_spec[0]) else: raise ValueError( "spec_functions must be of type: List[Union[str, Tuple[str, str]]]" @@ -90,10 +96,8 @@ def to_tool_list( tool = FunctionTool.from_defaults( fn=func_sync, - name=metadata.name, - description=metadata.description, - fn_schema=metadata.fn_schema, async_fn=func_async, + tool_metadata=metadata, ) tool_list.append(tool) return tool_list