Skip to content

API Reference

This document provides a reference for the WhyHow API.

All synchronous functions in WhyHow API have corresponding asynchronous counterparts. WhyHow client is essentially a thin wrapper around httpx, which provides flexibility for customization. Users should close the client when it's no longer needed, as outlined in the httpx documentation.

client

Implementation of the client logic.

Classes:

  • AsyncWhyHow

    Asynchronous client for the WhyHow API.

  • WhyHow

    Synchronous client for the WhyHow API.

AsyncWhyHow

AsyncWhyHow(api_key: str | None = None, base_url: str | None = None, httpx_kwargs: dict[str, Any] | None = None)

Asynchronous client for the WhyHow API.

Parameters:

  • api_key

    (str, default: None ) –

    The API key to use for authentication. If not provided, the WHYHOW_API_KEY environment variable will be used.

  • base_url

    (str, default: None ) –

    The base URL for the API.

  • httpx_kwargs

    (dict, default: None ) –

    Additional keyword arguments to pass to the httpx async client.

Attributes:

  • httpx_client (AsyncClient) –

    An async httpx client.

Methods:

  • close

    Close the async client.

close async

close() -> None

Close the async client.

WhyHow

WhyHow(api_key: str | None = None, base_url: str | None = None, httpx_kwargs: dict[str, Any] | None = None)

Synchronous client for the WhyHow API.

Parameters:

  • api_key

    (str, default: None ) –

    The API key to use for authentication. If not provided, the WHYHOW_API_KEY environment variable will be used.

  • base_url

    (str, default: None ) –

    The base URL for the API.

  • httpx_kwargs

    (dict, default: None ) –

    Additional keyword arguments to pass to the httpx client.

Attributes:

  • httpx_client (Client) –

    A synchronous httpx client.

Methods:

close

close() -> None

Close the client.

create_graph_from_knowledge_table

create_graph_from_knowledge_table(file_path: str, workspace_name: str, graph_name: str) -> str

Create a graph from a knowledge table file.

Parameters:

  • file_path
    (str) –

    Path to the knowledge table file.

  • workspace_name
    (str) –

    Name of the workspace to use or create.

  • graph_name
    (str) –

    Name for the graph to be created.

Returns:

  • str

    The ID of the created graph.

export_all

export_all(workspace_id: str | None = None) -> str

Output all of your WhyHow data to a JSON file.

Returns:

  • str

    Success or failure message.

resources

Collection of route specific resources.

Modules:

  • base

    Base classes for API schemas.

  • chunks

    Chunks resource.

  • documents

    Documents resource.

  • graphs

    Graph resources.

  • nodes

    Nodes resource.

  • schemas

    Schemas resource.

  • triples

    Triples resource.

  • utils

    Utility functions for WhyHow resources.

  • workspaces

    Workspaces resource.

Classes:

AsyncChunksResource

Bases: AsyncResource

Chunk resource.

Methods:

  • create

    Add chunks to a workspace.

  • get

    Get chunk by ID.

  • get_all

    Get all chunks.

  • vector_search

    Perform vector chunk retrieval with pagination.

create async

create(workspace_id: str, chunks: list[Chunk]) -> list[Chunk]

Add chunks to a workspace.

Parameters:

  • workspace_id
    (str) –

    The ID of the workspace.

  • chunks
    (list[Chunk]) –

    The chunks to add.

Returns:

  • list[Chunk]

    The updated chunks.

get async

get(chunk_id: str, include_embeddings: bool | None = None) -> Chunk

Get chunk by ID.

Parameters:

  • chunk_id
    (str) –

    The ID of the chunk.

  • include_embeddings
    (bool, default: None ) –

    Whether to include embeddings.

Returns:

get_all async

get_all(limit: int = 10, workspace_id: str | None = None, workspace_name: str | None = None, document_id: str | None = None, document_filename: str | None = None, include_embeddings: bool | None = None) -> AsyncIterator[Chunk]

Get all chunks.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of chunks to return.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace.

  • workspace_name
    (str, default: None ) –

    The name of the workspace.

  • document_id
    (str, default: None ) –

    The ID of the document.

  • document_filename
    (str, default: None ) –

    The filename of the document.

  • include_embeddings
    (bool, default: None ) –

    Whether to include embeddings.

Returns:

  • AsyncIterator[Chunk]

    The chunk iterator.

Yields:

vector_search(query: str, workspace_id: Optional[str] = None, graph_id: Optional[str] = None, limit: int = 10) -> AsyncIterator[Chunk]

Perform vector chunk retrieval with pagination.

Parameters:

  • query
    (str) –

    The search query to embed and compare against chunks

  • workspace_id
    (Optional[str], default: None ) –

    The workspace ID to search within

  • graph_id
    (Optional[str], default: None ) –

    The graph ID to search within

  • limit
    (int, default: 10 ) –

    Maximum total number of results to return

Returns:

  • AsyncIterator[Chunk]

    Asyncronous iterator of chunks, ordered by relevance

Raises:

  • ValueError

    If both workspace_id and graph_id are provided or if neither are provided

AsyncDocumentsResource

Bases: AsyncResource

Async documents resource.

Methods:

  • delete

    Delete a document.

  • get

    Get documents.

  • get_all

    Get all documents.

  • upload

    Upload a document.

delete async

delete(document_id: str) -> Document

Delete a document.

Parameters:

  • document_id
    (str) –

    The document ID.

Returns:

Raises:

  • ValueError

    If the document is deleted but not returned.

get async

get(document_id: str) -> Document

Get documents.

Parameters:

  • document_id
    (str) –

    The document ID.

Returns:

get_all async

get_all(limit: int = 10, filename: str | None = None, workspace_id: str | None = None, workspace_name: str | None = None) -> AsyncIterator[Document]

Get all documents.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of documents to return.

  • filename
    (str, default: None ) –

    The filename.

  • workspace_id
    (str, default: None ) –

    The workspace ID.

  • workspace_name
    (str, default: None ) –

    The workspace name.

Returns:

  • AsyncIterator[Document]

    The document iterator.

Yields:

upload async

upload(path: str | Path, workspace_id: str, max_seconds: int = 60, sleep_seconds: float = 1.5) -> Document

Upload a document.

Parameters:

  • path
    (Path) –

    The path to the document.

  • workspace_id
    (str) –

    The workspace ID.

  • max_seconds
    (int, default: 60 ) –

    The maximum number of seconds to wait for the document to be uploaded/processed.

  • sleep_seconds
    (float, default: 1.5 ) –

    The number of seconds to sleep between polling.

Returns:

Raises:

  • FileNotFoundError

    If the file is not found.

  • ValueError

    If the file format is not supported or the upload failed.

AsyncGraphsResource

Bases: AsyncResource

Graph resources.

Methods:

add_chunks async

add_chunks(graph_id: str, document_ids: list[str] | None = None, data_types: list[VALID_DATA_TYPE] | None = None, tags: list[str] | None = None, user_metadata: dict[str, Any] | None = None, ids: list[str] | None = None, timeout: int = 120, poll_interval: int = 5) -> Graph

Add chunks to a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • document_ids
    (list[str], default: None ) –

    The IDs of the documents.

  • data_types
    (list[str], default: None ) –

    The data types. Possible values are "string" and "object".

  • tags
    (list[str], default: None ) –

    The tags.

  • user_metadata
    (dict[str, Any], default: None ) –

    The user metadata.

  • ids
    (list[str], default: None ) –

    The IDs of the chunks.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

add_triples async

add_triples(graph_id: str, triples: list[Triple], strict_mode: bool = False, timeout: int = 120, poll_interval: int = 5) -> Task

Add triples to a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • triples
    (list[Triple]) –

    The triples.

  • strict_mode
    (bool, default: False ) –

    Whether to use strict mode.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

  • Task

    The task.

apply_rule async

apply_rule(graph_id: str, from_strings: list[str], to_string: str, entity_type: str, save_as_rule: bool | None = True, strict_mode: bool | None = False) -> Rule

Get the rules of a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • download_csv
    (bool) –

    Whether to save the rules to a CSV file.

Returns:

  • List[Rule]

    The rules.

create_graph_from_graph_chunks async

create_graph_from_graph_chunks(name: str, workspace_id: str, graph_chunks: list[GraphChunk], timeout: int = 120, poll_interval: int = 5) -> Graph

Create a graph from graph chunks.

Parameters:

  • name
    (str) –

    The name of the graph.

  • workspace_id
    (str) –

    The ID of the workspace.

  • graph_chunks
    (list[GraphChunk]) –

    The graph chunks.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

create_graph_from_triples async

create_graph_from_triples(name: str, workspace_id: str, triples: list[Triple], schema_id: str | None = None, timeout: int = 120, poll_interval: int = 5) -> Graph

Create a graph from triples.

Parameters:

  • name
    (str) –

    The name of the graph.

  • workspace_id
    (str) –

    The ID of the workspace.

  • triples
    (list[Triple]) –

    The triples.

  • schema_id
    (str, default: None ) –

    The ID of the schema. If not provided, the schema will be inferred.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

export_cypher async

export_cypher(graph_id: str) -> str

Export a graph to Cypher.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

Returns:

  • str

    The Cypher text.

get async

get(graph_id: str) -> Graph

Get a graph by its ID.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

Returns:

get_all async

get_all(limit: int = 10, name: str | None = None, workspace_id: str | None = None, workspace_name: str | None = None, schema_id: str | None = None, schema_name: str | None = None) -> AsyncIterator[Graph]

Get all graphs.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of graphs to return.

  • name
    (str, default: None ) –

    The name of the graph.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace.

  • workspace_name
    (str, default: None ) –

    The name of the workspace.

  • schema_id
    (str, default: None ) –

    The ID of the schema.

  • schema_name
    (str, default: None ) –

    The name of the schema.

Returns:

  • AsyncIterator[Graph]

    The graph iterator.

Yields:

get_all_triples async

get_all_triples(graph_id: str, limit: int = 10) -> AsyncIterator[Triple]

Get all triples.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • limit
    (int, default: 10 ) –

    The number of triples to return.

Returns:

  • AsyncIterator[Triple]

    The triple iterator.

Yields:

get_task async

get_task(task_id: str) -> Task

Get a task.

Parameters:

  • task_id
    (str) –

    The ID of the task.

Returns:

  • Task

    The task.

query_structured async

query_structured(graph_id: str, entities: list[str] | None = None, relations: list[str] | None = None, values: list[str] | None = None) -> Query

Structured query.

query_unstructured async

query_unstructured(graph_id: str, query: str, return_answer: bool = True, include_chunks: bool = False) -> Query

Query an unstructured graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • query
    (str) –

    The query.

  • return_answer
    (bool, default: True ) –

    Whether to return the answer.

  • include_chunks
    (bool, default: False ) –

    Whether to include chunks.

Returns:

Raises:

  • ValueError

    If no queries are found in the response body.

rules async

rules(graph_id: str, download_csv: bool = False) -> Any

Asynchronously get the rules of a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • download_csv
    (bool, default: False ) –

    Whether to save the rules to a CSV file.

Returns:

  • List[Rule]

    The rules.

update async

update(graph_id: str, name: str | None = None, public: bool | None = None) -> Graph

Update a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • name
    (str, default: None ) –

    The name of the graph.

  • public
    (bool, default: None ) –

    Whether the graph is public.

Returns:

AsyncNodesResource

Bases: AsyncResource

Nodes resource.

Methods:

create async

create(name: str, type: str, graph_id: str, properties: dict[str, str | int | bool | float | list[str | int | bool | float | None] | None] | None = None, chunks: list[str] | None = None, strict_mode: bool = False) -> Node

Create a mode.

Parameters:

  • name
    (str) –

    The name of the mode.

  • type
    (str) –

    The type of the mode.

  • graph_id
    (str) –

    The graph ID.

  • properties
    (dict[str, str | int | bool | float | list[str | int | bool | float | None] | None], default: None ) –

    The properties of the node.

  • chunks
    (list[str], default: None ) –

    The IDs of the chunks.

  • strict_mode
    (bool, default: False ) –

    Whether to use strict mode.

Returns:

  • Node

    The created node.

delete async

delete(node_id: str) -> Node

Delete a node.

Parameters:

  • node_id
    (str) –

    The node ID.

get async

get(node_id: str) -> Node

Get a nodes.

Parameters:

  • node_id
    (str) –

    The node ID.

Returns:

  • Node

    The node.

get_all async

get_all(limit: int = 10, name: str | None = None, type: str | None = None, workspace_name: str | None = None, workspace_id: str | None = None, graph_name: str | None = None, graph_id: str | None = None, chunk_ids: list[str] | None = None) -> AsyncIterator[Node]

Iterate over all nodes.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of nodes to fetch in each request.

  • name
    (str, default: None ) –

    The name of the node to filter by.

  • type
    (str, default: None ) –

    The type of the node to filter by.

  • workspace_name
    (str, default: None ) –

    The name of the workspace to filter by.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace to filter by.

  • graph_name
    (str, default: None ) –

    The name of the graph to filter by.

  • graph_id
    (str, default: None ) –

    The ID of the graph to filter by.

  • chunk_ids
    (list[str], default: None ) –

    The IDs of the chunks to filter by.

Yields:

get_chunks async

get_chunks(node_id: str) -> list[Chunk]

Get the chunks of a node.

Parameters:

  • node_id
    (str) –

    The node ID.

Returns:

  • list[Chunk]

    The chunks.

update async

update(node_id: str, name: str | None = None, type: str | None = None, graph_id: str | None = None, add_properties: dict[str, Any] | None = None, remove_properties: list[str] | None = None, clear_properties: bool | None = False, chunks: list[str] | None = None) -> Node

Update a node.

Parameters:

  • node_id
    (str) –

    The node ID.

  • name
    (str, default: None ) –

    The new name for the node.

  • type
    (str, default: None ) –

    The new type for the node.

  • graph_id
    (str, default: None ) –

    The new graph ID for the node.

  • add_properties
    (dict[str, Any], default: None ) –

    Properties to add or update in the node.

  • remove_properties
    (list[str], default: None ) –

    List of property keys to remove from the node.

  • clear_properties
    (bool, default: False ) –

    Whether to clear all properties from the node. Default is False.

  • chunks
    (list[str], default: None ) –

    The new chunks for the node.

Returns:

  • Node

    The updated node.

AsyncSchemasResource

Bases: AsyncResource

Async schemas resource.

Methods:

create async

Create a schema.

Parameters:

  • name
    (str) –

    The schema name.

  • workspace_id
    (str) –

    The workspace ID.

  • entities
    (list[SchemaEntity]) –

    The schema entities.

  • relations
    (list[SchemaRelation]) –

    The schema relations.

  • patterns
    (list[TriplePattern]) –

    The schema patterns.

Returns:

delete async

delete(schema_id: str) -> Schema

Delete a schema.

Parameters:

  • schema_id
    (str) –

    The schema ID.

Returns:

generate async

generate(questions: list[str]) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]

Generate a schema.

Parameters:

  • questions
    (list[str]) –

    The questions.

Returns:

get async

get(schema_id: str) -> Schema

Get a schema.

Parameters:

  • schema_id
    (str) –

    The schema ID.

Returns:

get_all async

get_all(limit: int = 10, workspace_id: str | None = None, workspace_name: str | None = None) -> AsyncIterator[Schema]

Get all schemas.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of schemas to fetch in one request.

  • workspace_id
    (str, default: None ) –

    The workspace ID.

  • workspace_name
    (str, default: None ) –

    The workspace name.

Returns:

  • AsyncIterator[Schema]

    The schema iterator.

Yields:

load_json staticmethod

load_json(file_path: str | Path) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]

Load a JSON file containing a schema.

Parameters:

  • file_path
    (str | Path) –

    The file path.

Returns:

AsyncTriplesResource

Bases: AsyncResource

Triples resource.

Methods:

  • create

    Create a triple.

  • delete

    Delete a triple.

  • get

    Get a triples.

  • get_all

    Iterate over all triples.

  • get_chunks

    Get the chunks of a triple.

create async

create(graph_id: str, head: Node | str, tail: Node | str, relation: Relation, properties: dict[str, Any] | None = None, chunks: list[str] | None = None, strict_mode: bool | None = None, timeout: int = 120, poll_interval: int = 5) -> AsyncIterator[Triple]

Create a triple.

Parameters:

  • graph_id
    (str) –

    The graph ID.

  • head
    (Node | str) –

    The head node.

  • tail
    (Node | str) –

    The tail node.

  • relation
    (Relation | str) –

    The relation of the triple.

  • properties
    (dict[str, Any], default: None ) –

    The properties of the triple.

  • chunks
    (list[str], default: None ) –

    The IDs of the chunks.

  • strict_mode
    (bool, default: None ) –

    Whether to use strict mode.

  • timeout
    (int, default: 120 ) –

    The timeout for the operation in seconds. Default is 120 seconds.

  • poll_interval
    (int, default: 5 ) –

    The interval to poll for the operation status in seconds. Default is 5 seconds.

Returns:

  • Iterator[Triple]

    An iterator over the created triples.

delete async

delete(triple_id: str) -> Triple

Delete a triple.

Parameters:

  • triple_id
    (str) –

    The triple ID.

Returns:

  • Triple

    The deleted triple.

get async

get(triple_id: str) -> Triple

Get a triples.

Parameters:

  • triple_id
    (str) –

    The triple ID.

Returns:

get_all async

get_all(limit: int = 10, type: str | None = None, graph_id: str | None = None, graph_name: str | None = None, chunk_ids: list[str] | None = None, head_node_id: str | None = None, tail_node_id: str | None = None, task_id: str | None = None) -> AsyncIterator[Triple]

Iterate over all triples.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of triples to fetch in each request.

  • type
    (str, default: None ) –

    The type of the triple to filter by.

  • graph_id
    (str, default: None ) –

    The graph ID to filter by.

  • graph_name
    (str, default: None ) –

    The graph name to filter by.

  • chunk_ids
    (list[str], default: None ) –

    The IDs of the chunks to filter by.

  • head_node_id
    (str, default: None ) –

    The head node ID to filter by.

  • tail_node_id
    (str, default: None ) –

    The tail node ID to filter by.

Yields:

get_chunks async

get_chunks(triple_id: str) -> list[Chunk]

Get the chunks of a triple.

Parameters:

  • triple_id
    (str) –

    The triple ID.

Returns:

  • list[Chunk]

    The chunks.

AsyncWorkspacesResource

Bases: AsyncResource

Workspaces resource.

Methods:

  • create

    Create a workspace.

  • delete

    Delete a workspace.

  • get

    Get a workspaces.

  • get_all

    Iterate over all workspaces.

  • update

    Update a workspace.

create async

create(name: str) -> Workspace

Create a workspace.

Parameters:

  • name
    (str) –

    The name of the workspace.

Returns:

delete async

delete(workspace_id: str) -> Workspace

Delete a workspace.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

get async

get(workspace_id: str) -> Workspace

Get a workspaces.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

Returns:

get_all async

get_all(limit: int = 10, name: str | None = None) -> AsyncIterator[Workspace]

Iterate over all workspaces.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of workspaces to fetch in each request.

  • name
    (str, default: None ) –

    The name of the workspace to filter by.

Yields:

update async

update(workspace_id: str, name: str) -> Workspace

Update a workspace.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

  • name
    (str) –

    The new name for the workspace.

Returns:

ChunksResource

Bases: Resource

Chunk resource.

Methods:

  • create

    Add chunks to a workspace.

  • get

    Get chunk by ID.

  • get_all

    Get all chunks.

  • vector_search

    Perform vector chunk retrieval with pagination.

create

create(workspace_id: str, chunks: list[Chunk]) -> list[Chunk]

Add chunks to a workspace.

Parameters:

  • workspace_id
    (str) –

    The ID of the workspace.

  • chunks
    (list[Chunk]) –

    The chunks to add.

Returns:

  • list[Chunk]

    The updated chunks.

get

get(chunk_id: str, include_embeddings: bool | None = None) -> Chunk

Get chunk by ID.

Parameters:

  • chunk_id
    (str) –

    The ID of the chunk.

  • include_embeddings
    (bool, default: None ) –

    Whether to include embeddings.

Returns:

get_all

get_all(limit: int = 10, workspace_id: str | None = None, workspace_name: str | None = None, document_id: str | None = None, document_filename: str | None = None, include_embeddings: bool | None = None) -> Iterator[Chunk]

Get all chunks.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of chunks to return.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace.

  • workspace_name
    (str, default: None ) –

    The name of the workspace.

  • document_id
    (str, default: None ) –

    The ID of the document.

  • document_filename
    (str, default: None ) –

    The filename of the document.

  • include_embeddings
    (bool, default: None ) –

    Whether to include embeddings.

Returns:

  • Iterator[Chunk]

    The chunk iterator.

Yields:

vector_search(query: str, workspace_id: Optional[str] = None, graph_id: Optional[str] = None, limit: int = 10) -> Iterator[Chunk]

Perform vector chunk retrieval with pagination.

Parameters:

  • query
    (str) –

    The search query to embed and compare against chunks

  • workspace_id
    (Optional[str], default: None ) –

    The workspace ID to search within

  • graph_id
    (Optional[str], default: None ) –

    The graph ID to search within

  • limit
    (int, default: 10 ) –

    Maximum total number of results to return

Returns:

  • Iterator[Chunk]

    Iterator of chunks, ordered by relevance

Raises:

  • ValueError

    If both workspace_id and graph_id are provided or if neither are provided

DocumentsResource

Bases: Resource

Documents resource.

Methods:

  • delete

    Delete a document.

  • get

    Get documents.

  • get_all

    Get all documents.

  • upload

    Upload a document.

delete

delete(document_id: str) -> Document

Delete a document.

Parameters:

  • document_id
    (str) –

    The document ID.

Returns:

Raises:

  • ValueError

    If the document is deleted but not returned.

get

get(document_id: str) -> Document

Get documents.

Parameters:

  • document_id
    (str) –

    The document ID.

Returns:

get_all

get_all(limit: int = 10, filename: str | None = None, workspace_id: str | None = None, workspace_name: str | None = None) -> Iterator[Document]

Get all documents.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of documents to return.

  • filename
    (str, default: None ) –

    The filename.

  • workspace_id
    (str, default: None ) –

    The workspace ID.

  • workspace_name
    (str, default: None ) –

    The workspace name.

Returns:

  • Iterator[Document]

    The document iterator.

Yields:

upload

upload(path: str | Path, workspace_id: str, max_seconds: int = 60, sleep_seconds: float = 1.5) -> Document

Upload a document.

Parameters:

  • path
    (Path) –

    The path to the document.

  • workspace_id
    (str) –

    The workspace ID.

  • max_seconds
    (int, default: 60 ) –

    The maximum number of seconds to wait for the document to be uploaded/processed.

  • sleep_seconds
    (float, default: 1.5 ) –

    The number of seconds to sleep between polling.

Returns:

Raises:

  • FileNotFoundError

    If the file is not found.

  • ValueError

    If the file format is not supported or the upload fails.

GraphsResource

Bases: Resource

Graph resources.

Methods:

add_chunks

add_chunks(graph_id: str, document_ids: list[str] | None = None, data_types: list[VALID_DATA_TYPE] | None = None, tags: list[str] | None = None, user_metadata: dict[str, Any] | None = None, ids: list[str] | None = None, timeout: int = 120, poll_interval: int = 5) -> Graph

Add chunks to a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • document_ids
    (list[str], default: None ) –

    The IDs of the documents.

  • data_types
    (list[str], default: None ) –

    The data types. Possible values are "string" and "object".

  • tags
    (list[str], default: None ) –

    The tags.

  • user_metadata
    (dict[str, Any], default: None ) –

    The user metadata.

  • ids
    (list[str], default: None ) –

    The IDs of the chunks.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

add_triples

add_triples(graph_id: str, triples: list[Triple], strict_mode: bool = False, timeout: int = 120, poll_interval: int = 5) -> Iterator[Triple]

Add triples to a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • triples
    (list[Triple]) –

    The triples.

  • strict_mode
    (bool, default: False ) –

    Whether to use strict mode.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

  • Task

    The task.

apply_rule

apply_rule(graph_id: str, from_strings: list[str], to_string: str, entity_type: str, save_as_rule: bool | None = True, strict_mode: bool | None = False) -> Rule

Get the rules of a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • download_csv
    (bool) –

    Whether to save the rules to a CSV file.

Returns:

  • List[Rule]

    The rules.

create_graph_from_graph_chunks

create_graph_from_graph_chunks(name: str, workspace_id: str, graph_chunks: list[GraphChunk], timeout: int = 120, poll_interval: int = 5) -> Graph

Create a graph from graph chunks.

Parameters:

  • name
    (str) –

    The name of the graph.

  • workspace_id
    (str) –

    The ID of the workspace.

  • graph_chunks
    (list[GraphChunk]) –

    The graph chunks.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

create_graph_from_triples

create_graph_from_triples(name: str, workspace_id: str, triples: list[Triple], schema_id: str | None = None, timeout: int = 120, poll_interval: int = 5) -> Graph

Create a graph from triples.

Parameters:

  • name
    (str) –

    The name of the graph.

  • workspace_id
    (str) –

    The ID of the workspace.

  • triples
    (list[Triple]) –

    The triples.

  • schema_id
    (str, default: None ) –

    The ID of the schema. If not provided, the schema will be inferred.

  • timeout
    (int, default: 120 ) –

    The timeout for the graph creation.

  • poll_interval
    (int, default: 5 ) –

    The interval at which to poll the graph status.

Returns:

export_cypher

export_cypher(graph_id: str) -> str

Export a graph to Cypher.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

Returns:

  • str

    The Cypher text.

get

get(graph_id: str) -> Graph

Get a graph by its ID.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

Returns:

get_all

get_all(limit: int = 10, name: str | None = None, workspace_id: str | None = None, workspace_name: str | None = None, schema_id: str | None = None, schema_name: str | None = None) -> Iterator[Graph]

Get all graphs.

Parameters:

  • limit
    (int, default: 10 ) –

    The number of graphs to return.

  • name
    (str, default: None ) –

    The name of the graph.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace.

  • workspace_name
    (str, default: None ) –

    The name of the workspace.

  • schema_id
    (str, default: None ) –

    The ID of the schema.

  • schema_name
    (str, default: None ) –

    The name of the schema.

Returns:

  • Iterator[Graph]

    The graph iterator.

Yields:

get_all_triples

get_all_triples(graph_id: str, limit: int = 10) -> Iterator[Triple]

Get all triples.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • limit
    (int, default: 10 ) –

    The number of triples to return.

Returns:

  • Iterator[Triple]

    The triple iterator.

Yields:

get_task

get_task(task_id: str) -> Task

Get a task.

Parameters:

  • task_id
    (str) –

    The ID of the task.

Returns:

  • Task

    The task.

query_structured

query_structured(graph_id: str, entities: list[str] | None = None, relations: list[str] | None = None, values: list[str] | None = None) -> Query

Structured query.

query_unstructured

query_unstructured(graph_id: str, query: str, return_answer: bool = True, include_chunks: bool = False) -> Query

Unstructured query.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • query
    (str) –

    The query.

  • return_answer
    (bool, default: True ) –

    Whether to return the answer.

  • include_chunks
    (bool, default: False ) –

    Whether to include chunks.

Returns:

Raises:

  • ValueError

    If no queries are found in the response body.

rules

rules(graph_id: str, download_csv: bool = False) -> list[Rule]

Get the rules of a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • download_csv
    (bool, default: False ) –

    Whether to save the rules to a CSV file.

Returns:

  • List[Rule]

    The rules.

update

update(graph_id: str, name: str | None = None, public: bool | None = None) -> Graph

Update a graph.

Parameters:

  • graph_id
    (str) –

    The ID of the graph.

  • name
    (str, default: None ) –

    The name of the graph.

  • public
    (bool, default: None ) –

    Whether the graph is public.

Returns:

NodesResource

Bases: Resource

Nodes resource.

Methods:

create

create(name: str, type: str, graph_id: str, properties: dict[str, str | int | bool | float | list[str | int | bool | float | None] | None] | None = None, chunks: list[str] | None = None, strict_mode: bool = False) -> Node

Create a mode.

Parameters:

  • name
    (str) –

    The name of the mode.

  • type
    (str) –

    The type of the mode.

  • graph_id
    (str) –

    The graph ID.

  • properties
    (dict[str, str | int | bool | float | list[str | int | bool | float | None] | None], default: None ) –

    The properties of the node.

  • chunks
    (list[str], default: None ) –

    The IDs of the chunks.

  • strict_mode
    (bool, default: False ) –

    Whether to use strict mode.

Returns:

  • Node

    The created node.

delete

delete(node_id: str) -> Node

Delete a node.

Parameters:

  • node_id
    (str) –

    The node ID.

get

get(node_id: str) -> Node

Get a nodes.

Parameters:

  • node_id
    (str) –

    The node ID.

Returns:

  • Node

    The node.

get_all

get_all(limit: int = 10, name: str | None = None, type: str | None = None, workspace_name: str | None = None, workspace_id: str | None = None, graph_name: str | None = None, graph_id: str | None = None, chunk_ids: list[str] | None = None) -> Iterator[Node]

Iterate over all nodes.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of nodes to fetch in each request.

  • name
    (str, default: None ) –

    The name of the node to filter by.

  • type
    (str, default: None ) –

    The type of the node to filter by.

  • workspace_name
    (str, default: None ) –

    The name of the workspace to filter by.

  • workspace_id
    (str, default: None ) –

    The ID of the workspace to filter by.

  • graph_name
    (str, default: None ) –

    The name of the graph to filter by.

  • graph_id
    (str, default: None ) –

    The ID of the graph to filter by.

  • chunk_ids
    (list[str], default: None ) –

    The IDs of the chunks to filter by.

Yields:

get_chunks

get_chunks(node_id: str) -> list[Chunk]

Get the chunks of a node.

Parameters:

  • node_id
    (str) –

    The node ID.

Returns:

  • list[Chunk]

    The chunks.

update

update(node_id: str, name: str | None = None, type: str | None = None, graph_id: str | None = None, add_properties: dict[str, Any] | None = None, remove_properties: list[str] | None = None, clear_properties: bool | None = False, chunks: list[str] | None = None) -> Node

Update a node.

Parameters:

  • node_id
    (str) –

    The node ID.

  • name
    (str, default: None ) –

    The new name for the node.

  • type
    (str, default: None ) –

    The new type for the node.

  • graph_id
    (str, default: None ) –

    The new graph ID for the node.

  • add_properties
    (dict[str, Any], default: None ) –

    Properties to add or update in the node.

  • remove_properties
    (list[str], default: None ) –

    List of property keys to remove from the node.

  • clear_properties
    (bool, default: False ) –

    Whether to clear all properties from the node. Default is False.

  • chunks
    (list[str], default: None ) –

    The new chunks for the node.

Returns:

  • Node

    The updated node.

SchemasResource

Bases: Resource

Schemas resource.

Methods:

create

Create a schema.

Parameters:

  • name
    (str) –

    The schema name.

  • workspace_id
    (str) –

    The workspace ID.

  • entities
    (list[SchemaEntity]) –

    The schema entities.

  • relations
    (list[SchemaRelation]) –

    The schema relations.

  • patterns
    (list[TriplePattern]) –

    The schema patterns.

Returns:

delete

delete(schema_id: str) -> Schema

Delete a schema.

Parameters:

  • schema_id
    (str) –

    The schema ID.

Returns:

generate

generate(questions: list[str]) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]

Generate a schema.

Parameters:

  • questions
    (list[str]) –

    The questions.

Returns:

get

get(schema_id: str) -> Schema

Get a schema.

Parameters:

  • schema_id
    (str) –

    The schema ID.

Returns:

get_all

get_all(limit: int = 10, workspace_id: str | None = None, workspace_name: str | None = None) -> Iterator[Schema]

Get all schemas.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of schemas to fetch in one request.

  • workspace_id
    (str, default: None ) –

    The workspace ID.

  • workspace_name
    (str, default: None ) –

    The workspace name.

Returns:

  • Iterator[Schema]

    The schema iterator.

Yields:

load_json staticmethod

load_json(file_path: str | Path) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]

Load a JSON file containing a schema.

Parameters:

  • file_path
    (str | Path) –

    The file path.

Returns:

TriplesResource

Bases: Resource

Triples resource.

Methods:

  • create

    Create a triple.

  • delete

    Delete a triple.

  • get

    Get a triples.

  • get_all

    Iterate over all triples.

  • get_chunks

    Get the chunks of a triple.

create

create(graph_id: str, head: Node | str, tail: Node | str, relation: Relation, properties: dict[str, Any] | None = None, chunks: list[str] | None = None, strict_mode: bool | None = None, timeout: int = 120, poll_interval: int = 5) -> Iterator[Triple]

Create a triple.

Parameters:

  • graph_id
    (str) –

    The graph ID.

  • head_node
    (Node | str) –

    The head node.

  • tail_node
    (Node | str) –

    The tail node.

  • type
    (str) –

    The type of the triple.

  • properties
    (dict[str, Any], default: None ) –

    The properties of the triple.

  • chunks
    (list[str], default: None ) –

    The IDs of the chunks.

  • strict_mode
    (bool, default: None ) –

    Whether to use strict mode.

Returns:

  • Task

    The task.

delete

delete(triple_id: str) -> Triple

Delete a triple.

Parameters:

  • triple_id
    (str) –

    The triple ID.

Returns:

  • Triple

    The deleted triple.

get

get(triple_id: str, embeddings: bool = False) -> Triple

Get a triples.

Parameters:

  • triple_id
    (str) –

    The triple ID.

  • embeddings
    (bool, default: False ) –

    Whether to include embeddings in the response.

Returns:

get_all

get_all(limit: int = 10, type: str | None = None, graph_id: str | None = None, graph_name: str | None = None, chunk_ids: list[str] | None = None, head_node_id: str | None = None, tail_node_id: str | None = None, embeddings: bool = False, task_id: str | None = None) -> Iterator[Triple]

Iterate over all triples.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of triples to fetch in each request.

  • type
    (str, default: None ) –

    The type of the triple to filter by.

  • graph_id
    (str, default: None ) –

    The graph ID to filter by.

  • graph_name
    (str, default: None ) –

    The graph name to filter by.

  • chunk_ids
    (list[str], default: None ) –

    The IDs of the chunks to filter by.

  • head_node_id
    (str, default: None ) –

    The head node ID to filter by.

  • tail_node_id
    (str, default: None ) –

    The tail node ID to filter by.

  • embeddings
    (bool, default: False ) –

    Whether to include embeddings in the response.

Yields:

get_chunks

get_chunks(triple_id: str) -> list[Chunk]

Get the chunks of a triple.

Parameters:

  • triple_id
    (str) –

    The triple ID.

Returns:

  • list[Chunk]

    The chunks.

WorkspacesResource

Bases: Resource

Workspaces resource.

Methods:

  • create

    Create a workspace.

  • delete

    Delete a workspace.

  • get

    Get a workspaces.

  • get_all

    Iterate over all workspaces.

  • update

    Update a workspace.

create

create(name: str) -> Workspace

Create a workspace.

Parameters:

  • name
    (str) –

    The name of the workspace.

Returns:

delete

delete(workspace_id: str) -> Workspace

Delete a workspace.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

get

get(workspace_id: str) -> Workspace

Get a workspaces.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

Returns:

get_all

get_all(limit: int = 10, name: str | None = None) -> Iterator[Workspace]

Iterate over all workspaces.

Parameters:

  • limit
    (int, default: 10 ) –

    The maximum number of workspaces to fetch in each request.

  • name
    (str, default: None ) –

    The name of the workspace to filter by.

Yields:

update

update(workspace_id: str, name: str) -> Workspace

Update a workspace.

Parameters:

  • workspace_id
    (str) –

    The workspace ID.

  • name
    (str) –

    The new name for the workspace.

Returns:

schemas

User facing pyndantic models.

Classes:

Chunk

Bases: BaseModel

Chunk model.

Attributes:

  • chunk_id (str | None) –

    The chunk ID.

  • created_at (datetime | None) –

    The creation datetime.

  • updated_at (datetime | None) –

    The update datetime.

  • document_id (str | None) –

    The document ID.

  • workspace_ids (list[str] | None) –

    The workspace IDs.

  • metadata (ChunkMetadata | None) –

    The chunk metadata.

  • content (str | dict[str, Any]) –

    The chunk content.

  • embedding (list[float] | None) –

    The chunk embedding.

  • tags (dict[str, list[str]] | list[str]) –

    The chunk tags.

  • user_metadata (dict[str, Any]) –

    The chunk user metadata.

ChunkMetadata

Bases: BaseModel

Chunk metadata model.

Attributes:

  • language ((str, optional)) –

    The chunk language.

  • length ((int, optional)) –

    The chunk length.

  • size ((int, optional)) –

    The chunk size.

  • data_source_type ((str, optional)) –

    The chunk data source type.

  • index ((int, optional)) –

    The chunk index.

  • page ((int, optional)) –

    The chunk page.

  • start ((int, optional)) –

    The chunk start.

  • end ((int, optional)) –

    The chunk end.

Document

Bases: BaseModel

Document model.

Attributes:

  • document_id (str) –

    The document ID.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

  • workspace_ids (list[str]) –

    The workspace IDs.

  • metadata (DocumentMetadata) –

    The document metadata.

  • status (str) –

    The document status.

  • tags ((dict[str, Any], optional)) –

    The document tags.

  • user_metadata ((dict[str, Any], optional)) –

    The document user metadata.

DocumentMetadata

Bases: BaseModel

Document metadata model.

Attributes:

  • size (int) –

    The document size.

  • format (str) –

    The document format.

  • filename (str) –

    The document filename.

Graph

Bases: BaseModel

Graph model.

Attributes:

  • graph_id (str) –

    The graph ID.

  • name (str) –

    The graph name.

  • workspace_id (str) –

    The workspace ID.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

  • schema_id ((str, optional)) –

    The schema ID.

  • status (str) –

    The graph status.

  • errors ((list[GraphErrorDetails], optional)) –

    The graph errors.

  • public ((bool, optional)) –

    The graph public status.

GraphChunk

Bases: BaseModel

Graph chunk model.

Attributes:

  • chunk (Chunk) –

    The chunk.

  • triples (list[Triple]) –

    The triples.

GraphErrorDetails

Bases: BaseModel

Graph error details model.

Attributes:

  • message (str) –

    The error message.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • level (str) –

    The error level.

MergeNodesRule

Bases: BaseModel

Merge nodes rule type model.

Attributes:

  • rule_type (str) –

    The type of the rule.

  • from_node_names (list[str]) –

    A list of node names from which to merge.

  • to_node_name (str) –

    The name of the node to which others will be merged.

  • node_type (str) –

    The type of the node.

Node

Bases: BaseModel

Node model.

Attributes:

  • node_id (str) –

    The node ID. It can be None since we allow for the user to also create nodes and only then send them to the server (that will generate the node ID).

  • label ((str, optional)) –

    The node label.

  • name ((str, optional)) –

    The node name.

  • chunk_ids ((list[str], optional)) –

    The chunk IDs.

  • properties ((dict[str, Any], optional)) –

    The node properties.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

  • graph_id ((str, optional)) –

    The graph ID.

Query

Bases: BaseModel

Query model.

Attributes:

  • query_id (str) –

    The query ID.

  • graph_id (str) –

    The graph ID.

  • answer ((str, optional)) –

    The query answer.

  • status (str) –

    The query status.

  • nodes (list[Node]) –

    The query nodes.

  • triples (list[Triple]) –

    The query triples.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

Relation

Bases: BaseModel

Relation model.

Attributes:

  • name (str) –

    The relation name.

  • properties ((dict[str, Any], optional)) –

    The relation properties.

Rule

Bases: BaseModel

Rule model.

Attributes:

  • rule_id (str) –

    The ID of the field associated with the rule.

  • workspace_id (str) –

    The ID of the workspace to which the rule belongs.

  • rule (MergeNodesRule) –

    The rule details, including type and node information.

  • created_at (datetime) –

    The timestamp when the rule was created.

  • updated_at (datetime) –

    The timestamp when the rule was last updated.

Schema

Bases: BaseModel

Schema model.

Attributes:

  • schema_id (str) –

    The schema ID.

  • name (str) –

    The schema name.

  • entities (list[SchemaEntity]) –

    The schema entities.

  • relations (list[SchemaRelation]) –

    The schema relations.

  • patterns (list[SchemaTriplePattern]) –

    The schema patterns.

  • workspace_id (str) –

    The workspace ID.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

SchemaEntity

Bases: BaseModel

Entity model.

Attributes:

  • name (str) –

    The entity name.

  • description ((str, optional)) –

    The entity description.

  • fields ((list[SchemaEntityField], optional)) –

    The entity fields.

SchemaEntityField

Bases: BaseModel

Entity field model.

Attributes:

  • name (str) –

    The field name.

  • properties ((list[str], optional)) –

    The field properties.

SchemaRelation

Bases: BaseModel

Relation model.

Attributes:

  • name (str) –

    The relation name.

  • description ((str, optional)) –

    The relation description.

SchemaTriplePattern

Bases: BaseModel

Triple pattern model.

Attributes:

Task

Bases: BaseModel

Task model.

Attributes:

  • task_id ((str | None, optional)) –

    The task ID.

  • start_time ((datetime | None, optional)) –

    The start time of the task.

  • end_time ((datetime | None, optional)) –

    The end time of the task.

  • status (str) –

    The status of the task.

  • result ((str | None, optional)) –

    The result of the task.

Triple

Bases: BaseModel

Triple model.

Attributes:

  • triple_id ((str, optional)) –

    The triple ID. It can be None since we allow for the user to also create triples and only then send them to the server (that will generate the triple ID).

  • head (Node) –

    The head node.

  • tail (Node) –

    The tail node.

  • relation (Relation) –

    The relation.

  • chunk_ids ((list[str], optional)) –

    The chunk IDs.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.

  • properties ((dict[str, Any], optional)) –

    The triple properties.

  • graph_id ((str, optional)) –

    The graph ID.

  • embedding ((list[float], optional)) –

    The triple embedding.

Workspace

Bases: BaseModel

Workspace model.

Attributes:

  • workspace_id (str) –

    The workspace ID.

  • name (str) –

    The workspace name.

  • created_at ((datetime, optional)) –

    The creation datetime.

  • updated_at ((datetime, optional)) –

    The update datetime.