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.
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 the client.
-
create_graph_from_knowledge_table
–Create a graph from a knowledge table file.
-
export_all
–Output all of your WhyHow data to a JSON file.
create_graph_from_knowledge_table
¶
create_graph_from_knowledge_table(file_path: str, workspace_name: str, graph_name: str) -> str
export_all
¶
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
–Chunk resource.
-
AsyncDocumentsResource
–Async documents resource.
-
AsyncGraphsResource
–Graph resources.
-
AsyncNodesResource
–Nodes resource.
-
AsyncSchemasResource
–Async schemas resource.
-
AsyncTriplesResource
–Triples resource.
-
AsyncWorkspacesResource
–Workspaces resource.
-
ChunksResource
–Chunk resource.
-
DocumentsResource
–Documents resource.
-
GraphsResource
–Graph resources.
-
NodesResource
–Nodes resource.
-
SchemasResource
–Schemas resource.
-
TriplesResource
–Triples resource.
-
WorkspacesResource
–Workspaces resource.
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]
get
async
¶
get(chunk_id: str, include_embeddings: bool | None = None) -> Chunk
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:
-
Chunk
–The chunk.
vector_search
async
¶
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
get
async
¶
get(document_id: str) -> Document
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:
-
Document
–The document.
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:
-
Document
–The document.
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
–Add chunks to a graph.
-
add_triples
–Add triples to a graph.
-
apply_rule
–Get the rules of a graph.
-
create_graph_from_graph_chunks
–Create a graph from graph chunks.
-
create_graph_from_triples
–Create a graph from triples.
-
export_cypher
–Export a graph to Cypher.
-
get
–Get a graph by its ID.
-
get_all
–Get all graphs.
-
get_all_triples
–Get all triples.
-
get_task
–Get a task.
-
query_structured
–Structured query.
-
query_unstructured
–Query an unstructured graph.
-
rules
–Asynchronously get the rules of a graph.
-
update
–Update a graph.
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:
-
Graph
–The graph.
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
¶
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:
-
Graph
–The graph.
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:
-
Graph
–The graph.
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_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:
-
Graph
–The graph.
get_all_triples
async
¶
get_task
async
¶
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:
-
Query
–The query.
Raises:
-
ValueError
–If no queries are found in the response body.
rules
async
¶
rules(graph_id: str, download_csv: bool = False) -> Any
update
async
¶
AsyncNodesResource
¶
Bases: AsyncResource
Nodes resource.
Methods:
-
create
–Create a mode.
-
delete
–Delete a node.
-
get
–Get a nodes.
-
get_all
–Iterate over all nodes.
-
get_chunks
–Get the chunks of a node.
-
update
–Update a node.
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
¶
get
async
¶
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:
-
Node
–A node.
get_chunks
async
¶
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
–Create a schema.
-
delete
–Delete a schema.
-
generate
–Generate a schema.
-
get
–Get a schema.
-
get_all
–Get all schemas.
-
load_json
–Load a JSON file containing a schema.
create
async
¶
create(name: str, workspace_id: str, entities: list[SchemaEntity], relations: list[SchemaRelation], patterns: list[SchemaTriplePattern]) -> Schema
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:
-
Schema
–The schema.
delete
async
¶
generate
async
¶
generate(questions: list[str]) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]
Generate a schema.
Parameters:
-
questions
¶list[str]
) –The questions.
Returns:
-
entities
(list[SchemaEntity]
) –The schema entities.
-
relations
(list[SchemaRelation]
) –The schema relations.
-
patterns
(list[SchemaTriplePattern]
) –The schema patterns.
get
async
¶
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:
-
Schema
–A schema.
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:
-
list[SchemaEntity]
–The schema entities.
-
list[SchemaRelation]
–The schema relations.
-
list[SchemaTriplePattern]
–The schema patterns.
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
¶
get
async
¶
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:
-
Triple
–A triple.
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
¶
delete
async
¶
delete(workspace_id: str) -> Workspace
get
async
¶
get(workspace_id: str) -> Workspace
get_all
async
¶
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]
get
¶
get(chunk_id: str, include_embeddings: bool | None = None) -> Chunk
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:
-
Chunk
–The chunk.
vector_search
¶
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
get
¶
get(document_id: str) -> Document
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:
-
Document
–The document.
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:
-
Document
–The document.
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 to a graph.
-
add_triples
–Add triples to a graph.
-
apply_rule
–Get the rules of a graph.
-
create_graph_from_graph_chunks
–Create a graph from graph chunks.
-
create_graph_from_triples
–Create a graph from triples.
-
export_cypher
–Export a graph to Cypher.
-
get
–Get a graph by its ID.
-
get_all
–Get all graphs.
-
get_all_triples
–Get all triples.
-
get_task
–Get a task.
-
query_structured
–Structured query.
-
query_unstructured
–Unstructured query.
-
rules
–Get the rules of a graph.
-
update
–Update a graph.
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:
-
Graph
–The graph.
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
¶
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:
-
Graph
–The graph.
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:
-
Graph
–The graph.
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_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:
-
Graph
–The graph.
get_all_triples
¶
get_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:
-
Query
–The query.
Raises:
-
ValueError
–If no queries are found in the response body.
rules
¶
rules(graph_id: str, download_csv: bool = False) -> list[Rule]
update
¶
NodesResource
¶
Bases: Resource
Nodes resource.
Methods:
-
create
–Create a mode.
-
delete
–Delete a node.
-
get
–Get a nodes.
-
get_all
–Iterate over all nodes.
-
get_chunks
–Get the chunks of a node.
-
update
–Update a node.
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.
get
¶
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:
-
Node
–A node.
get_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.
-
delete
–Delete a schema.
-
generate
–Generate a schema.
-
get
–Get a schema.
-
get_all
–Get all schemas.
-
load_json
–Load a JSON file containing a schema.
create
¶
create(name: str, workspace_id: str, entities: list[SchemaEntity], relations: list[SchemaRelation], patterns: list[SchemaTriplePattern]) -> Schema
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:
-
Schema
–The schema.
delete
¶
generate
¶
generate(questions: list[str]) -> tuple[list[SchemaEntity], list[SchemaRelation], list[SchemaTriplePattern]]
Generate a schema.
Parameters:
-
questions
¶list[str]
) –The questions.
Returns:
-
entities
(list[SchemaEntity]
) –The schema entities.
-
relations
(list[SchemaRelation]
) –The schema relations.
-
patterns
(list[SchemaTriplePattern]
) –The schema patterns.
get
¶
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:
-
Schema
–A schema.
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:
-
list[SchemaEntity]
–The schema entities.
-
list[SchemaRelation]
–The schema relations.
-
list[SchemaTriplePattern]
–The schema patterns.
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
¶
get
¶
get(triple_id: str, embeddings: bool = False) -> Triple
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:
-
Triple
–A triple.
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
¶
delete
¶
delete(workspace_id: str) -> Workspace
get
¶
get(workspace_id: str) -> Workspace
get_all
¶
schemas
¶
User facing pyndantic models.
Classes:
-
Chunk
–Chunk model.
-
ChunkMetadata
–Chunk metadata model.
-
Document
–Document model.
-
DocumentMetadata
–Document metadata model.
-
Graph
–Graph model.
-
GraphChunk
–Graph chunk model.
-
GraphErrorDetails
–Graph error details model.
-
MergeNodesRule
–Merge nodes rule type model.
-
Node
–Node model.
-
Query
–Query model.
-
Relation
–Relation model.
-
Rule
–Rule model.
-
Schema
–Schema model.
-
SchemaEntity
–Entity model.
-
SchemaEntityField
–Entity field model.
-
SchemaRelation
–Relation model.
-
SchemaTriplePattern
–Triple pattern model.
-
Task
–Task model.
-
Triple
–Triple model.
-
Workspace
–Workspace model.
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
¶
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:
-
head
(SchemaEntity
) –The head entity.
-
relation
(SchemaRelation
) –The relation.
-
tail
(SchemaEntity
) –The tail entity.
-
description
(str
) –The triple description.
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.