[docs]classDocstoreFn(Docstore):"""Docstore via arbitrary lookup function. This is useful when: * it's expensive to construct an InMemoryDocstore/dict * you retrieve documents from remote sources * you just want to reuse existing objects """
[docs]defsearch(self,search:str)->Document:"""Search for a document. Args: search: search string Returns: Document if found, else error message. """r=self._lookup_fn(search)ifisinstance(r,str):# NOTE: assume the search string is the source IDreturnDocument(page_content=r,metadata={"source":search})elifisinstance(r,Document):returnrraiseValueError(f"Unexpected type of document {type(r)}")