Source code for langchain_community.retrievers.embedchain
"""Wrapper around Embedchain Retriever."""from__future__importannotationsfromtypingimportAny,Iterable,List,Optionalfromlangchain_core.callbacksimportCallbackManagerForRetrieverRunfromlangchain_core.documentsimportDocumentfromlangchain_core.retrieversimportBaseRetriever
[docs]@classmethoddefcreate(cls,yaml_path:Optional[str]=None)->EmbedchainRetriever:""" Create a EmbedchainRetriever from a YAML configuration file. Args: yaml_path: Path to the YAML configuration file. If not provided, a default configuration is used. Returns: An instance of EmbedchainRetriever. """fromembedchainimportPipeline# Create an Embedchain Pipeline instanceifyaml_path:client=Pipeline.from_config(yaml_path=yaml_path)else:client=Pipeline()returncls(client=client)
[docs]defadd_texts(self,texts:Iterable[str],)->List[str]:"""Run more texts through the embeddings and add to the retriever. Args: texts: Iterable of strings/URLs to add to the retriever. Returns: List of ids from adding the texts into the retriever. """ids=[]fortextintexts:_id=self.client.add(text)ids.append(_id)returnids