langchain_experimental.graph_transformers.diffbot.DiffbotGraphTransformer¶

class langchain_experimental.graph_transformers.diffbot.DiffbotGraphTransformer(diffbot_api_key: Optional[str] = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True)[source]¶

Transforms documents into graph documents using Diffbot’s NLP API.

A graph document transformation system takes a sequence of Documents and returns a sequence of Graph Documents.

Example

class DiffbotGraphTransformer(BaseGraphDocumentTransformer):

    def transform_documents(
        self, documents: Sequence[Document], **kwargs: Any
    ) -> Sequence[GraphDocument]:
        results = []

        for document in documents:
            raw_results = self.nlp_request(document.page_content)
            graph_document = self.process_response(raw_results, document)
            results.append(graph_document)
        return results

    async def atransform_documents(
        self, documents: Sequence[Document], **kwargs: Any
    ) -> Sequence[Document]:
        raise NotImplementedError

Initialize the graph transformer with various options.

Parameters
  • diffbot_api_key (str) – The API key for Diffbot’s NLP services.

  • fact_confidence_threshold (float) – Minimum confidence level for facts to be included.

  • include_qualifiers (bool) – Whether to include qualifiers in the relationships.

  • include_evidence (bool) – Whether to include evidence for the relationships.

  • simplified_schema (bool) – Whether to use a simplified schema for relationships.

Methods

__init__([diffbot_api_key, ...])

Initialize the graph transformer with various options.

convert_to_graph_documents(documents)

Convert a sequence of documents into graph documents.

nlp_request(text)

Make an API request to the Diffbot NLP endpoint.

process_response(payload, document)

Transform the Diffbot NLP response into a GraphDocument.

__init__(diffbot_api_key: Optional[str] = None, fact_confidence_threshold: float = 0.7, include_qualifiers: bool = True, include_evidence: bool = True, simplified_schema: bool = True) None[source]¶

Initialize the graph transformer with various options.

Parameters
  • diffbot_api_key (str) – The API key for Diffbot’s NLP services.

  • fact_confidence_threshold (float) – Minimum confidence level for facts to be included.

  • include_qualifiers (bool) – Whether to include qualifiers in the relationships.

  • include_evidence (bool) – Whether to include evidence for the relationships.

  • simplified_schema (bool) – Whether to use a simplified schema for relationships.

convert_to_graph_documents(documents: Sequence[Document]) List[GraphDocument][source]¶

Convert a sequence of documents into graph documents.

Parameters
  • documents (Sequence[Document]) – The original documents.

  • **kwargs – Additional keyword arguments.

Returns

The transformed documents as graphs.

Return type

Sequence[GraphDocument]

nlp_request(text: str) Dict[str, Any][source]¶

Make an API request to the Diffbot NLP endpoint.

Parameters

text (str) – The text to be processed.

Returns

The JSON response from the API.

Return type

Dict[str, Any]

process_response(payload: Dict[str, Any], document: Document) GraphDocument[source]¶

Transform the Diffbot NLP response into a GraphDocument.

Parameters
  • payload (Dict[str, Any]) – The JSON response from Diffbot’s NLP API.

  • document (Document) – The original document.

Returns

The transformed document as a graph.

Return type

GraphDocument