graphrag_sdk.schema package

Submodules

graphrag_sdk.schema.auto_detect module

graphrag_sdk.schema.auto_detect.convert_table(s, client, model, tbl, columns, foreign_keys)[source]
graphrag_sdk.schema.auto_detect.convert_tables(s, client, model, inspector, table_names)[source]
graphrag_sdk.schema.auto_detect.create_entity(s, client, model, name: str, columns) None[source]
graphrag_sdk.schema.auto_detect.create_entity_with_relation(s, client, model, name: str, columns, foreign_keys) None[source]
graphrag_sdk.schema.auto_detect.create_relation(s, name: str, foreign_keys)[source]
graphrag_sdk.schema.auto_detect.generate_graph_schema(s, client, model)[source]
graphrag_sdk.schema.auto_detect.get_assistant(client, assistant_name, model)[source]
graphrag_sdk.schema.auto_detect.handle_run(client, run, queue)[source]
graphrag_sdk.schema.auto_detect.initiate_interaction(client, assistant, user_message)[source]
graphrag_sdk.schema.auto_detect.process_source(client, assistant, src, queue)[source]
graphrag_sdk.schema.auto_detect.run_sql(arg, queue)[source]
graphrag_sdk.schema.auto_detect.schema_auto_detect(schema, sources, model='gpt-3.5-turbo-0125')[source]
graphrag_sdk.schema.auto_detect.sqlalchemy_to_python_type(sqlalchemy_type)[source]

graphrag_sdk.schema.decoder module

class graphrag_sdk.schema.decoder.SchemaDecoder[source]

Bases: object

decode(schema, data: dict)[source]
from_JSON(schema, json: str)[source]

graphrag_sdk.schema.encoder module

class graphrag_sdk.schema.encoder.SchemaEncoder[source]

Bases: object

encode(schema) dict[source]
to_JSON(schema) str[source]

graphrag_sdk.schema.entity module

class graphrag_sdk.schema.entity.Attribute(name: str, type: type, desc=None, unique=False, mandatory=False)[source]

Bases: object

class graphrag_sdk.schema.entity.Entity(name: str)[source]

Bases: object

Represents an ontolegy entity

add_attribute(name: str, type: type, desc: str | None = None, unique: bool = False, mandatory: bool = False) Entity[source]

Add attribute to entity

Parameters:

name (str): attribute name type (type): attribute type desc (str): short description for attribute unique (bool): is the attribute value unique mandatory (bool): is the attribute mandatory

Returns:

Entity

get_attribute(name: str) Attribute | None[source]

Get attribute

Parameters:

name (str): name of attribute to get

Returns:

attribute

remove_attribute(name: str) Entity[source]

Remove attribute from entity

Parameters:

name (str): name of attribute to remove

Returns:

Entity

unique_attributes() list[Attribute][source]

Get a list of Entity’s unique attributes

Returns:

list of unique attributes

graphrag_sdk.schema.from_graph module

graphrag_sdk.schema.from_graph.schema_from_graph(s, g: Graph)[source]

graphrag_sdk.schema.functions_gen module

graphrag_sdk.schema.functions_gen.entity_to_create_func(e: Entity)[source]
graphrag_sdk.schema.functions_gen.relation_to_create_func(r: Relation)[source]
graphrag_sdk.schema.functions_gen.schema_to_functions(s: Schema)[source]

graphrag_sdk.schema.relation module

class graphrag_sdk.schema.relation.Relation(name: str, src: Entity, dest: Entity)[source]

Bases: object

graphrag_sdk.schema.schema module

class graphrag_sdk.schema.schema.Schema[source]

Bases: object

Knowledge Graph schema (ontology) The schema captures entities types in addition to their attributes and the relationship types between the them

add_entity(name: str) Entity[source]

Add a new entity to schema

Parameters:

name (str): Entity name.

Returns:

entity

add_relation(name: str, src: Entity, dest: Entity) Relation[source]

Add a relationship to schema

Returns:

relation

classmethod auto_detect(sources: list[AbstractSource], model='gpt-3.5-turbo-0125') Schema[source]

Auto detect schema from sources

Parameters:

sources (list[AbstractSource]): list of sources to extract schema from model (str): OpenAI model to use

Returns:

Schema: schema

classmethod from_JSON(json: str) Schema[source]

Create a schema from JSON

Parameters:

json (str): the output from to_JSON

Returns:

Schema: schema

classmethod from_graph(g: Graph) Schema[source]

Create a schema from an ontology graph

Parameters:

g (Graph): ontology graph to load

Returns:

Schema: schema

get_entity(name: str) Entity | None[source]

Get an entity from schema

Returns:

entity

save_graph(g: Graph) None[source]

Save schema as an ontology graph

Parameters:

g (Graph): graph to create

to_JSON() str[source]

Encode schema to JSON string

Returns:

JSON representation of schema

validate() bool[source]

Validate schema

Returns:

True if schema is valid

graphrag_sdk.schema.to_graph module

graphrag_sdk.schema.to_graph.schema_to_graph(s, g: Graph) None[source]

graphrag_sdk.schema.tools_gen module

graphrag_sdk.schema.tools_gen.entity_to_tool(e: Entity)[source]
graphrag_sdk.schema.tools_gen.relation_to_tool(r: Relation)[source]
graphrag_sdk.schema.tools_gen.schema_to_tools(s: Schema)[source]
graphrag_sdk.schema.tools_gen.type_mapping(t) str[source]

Module contents