whyhow


Namewhyhow JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryWhyhow automated KG SDK
upload_time2024-04-21 02:17:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords sdk kg
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WhyHow Knowledge Graph Creation SDK

[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)
[![PyPI Version](https://img.shields.io/pypi/v/whyhow)](https://pypi.org/project/why/)
[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](https://mypy-lang.org/)
[![Whyhow Discord](https://dcbadge.vercel.app/api/server/9bWqrsxgHr?compact=true&style=flat)](https://discord.gg/9bWqrsxgHr)

The WhyHow Knowledge Graph Creation SDK enables you to quickly and easily build automated knowledge graphs tailored to your unique worldview. Instantly build, extend, and query well-scoped KGs with your data.

# Installation

## Prerequisites

- Python 3.10 or higher
- [OpenAI API key](https://openai.com/)
- [Pinecone API key](https://www.pinecone.io/)
- [Neo4j credentials](https://neo4j.com/cloud/platform/aura-graph-database/) (username, password, and URL)

## Install from PyPI

You can install the SDK directly from PyPI using pip:

```shell
pip install whyhow

export OPENAI_API_KEY=<your openai api key>
export PINECONE_API_KEY=<your pinecone api key>
export NEO4J_URL=<your neo4j url>
export NEO4J_USERNAME=<your neo4j username>
export NEO4J_PASSWORD=<your neo4j password>
```

## Install from Github

Alternatively, you can clone the repo and install the package

```shell

git clone git@github.com:whyhow-ai/whyhow.git
cd whyhow
pip install .

export OPENAI_API_KEY=<your openai api key>
export PINECONE_API_KEY=<your pinecone api key>
export NEO4J_URL=<your neo4j url>
export NEO4J_USERNAME=<your neo4j username>
export NEO4J_PASSWORD=<your neo4j password>
```

# Examples

Navigate to the `examples/`.

# How to

## Initialize SDK

Import the SDK and initialize the client using your WhyHow API key.

```shell
from whyhow import WhyHow

client = WhyHow(api_key=<your whyhow api key>)
```

## Add documents to namespace

Your namespace is a logical grouping of the raw data you upload, the seed concepts you define, and the graphs you create. Namespaces are meant to be tightly scoped to your use case. You can create as many namespaces as you want.

```shell

namespace = "harry-potter"
documents = ["files/harry_potter_and_the_philosophers_stone.pdf","files/harry_potter_and_the_chamber_of_secrets.pdf"]

documents_response = client.graph.add_documents(namespace, documents)
print(documents_response)
# Adding your documents

```

## Create a graph

You can create a graph in two different ways. First, you can create a graph using a user-defined schema, giving you complete control over the types of entities and relationships that are extracted and used to build the graph. Or, you can create a graph using a set of seed questions. In this case, WhyHow will automatically extract entities and relationships that are most applicable to the things you want to know, and construct a graph from these concepts.

Create graph with **schema** if...

1. Your graph must adhere to a consistent structure.
2. You are very familiar with the structure of your raw documents.
3. You need comprehensive extraction of concepts across the entire document.

Create graph with **seed questions** if...

1. You are unsure as to which relationships and patterns you'd like to build into your graph.
2. You want to build your graph with only the most semantically similar raw data.

### Create a graph with schema

Tell the WhyHow SDK exactly which entities, relationships, and patterns you'd like to extract and build into your graph by defining them in a JSON-based schema.

```shell

#schema.json

{
  "entities": [
    {
      "name": "character",
      "description": "A person appearing in the book, e.g., Harry Potter, Ron Weasley, Hermione Granger, Albus Dumbledore."
    },
    {
      "name": "object",
      "description": "Inanimate items that characters use or interact with, e.g., wand, Philosopher's Stone, Invisibility Cloak, broomstick."
    }
    ...
  ],
  "relations": [
    {
      "name": "friends with",
      "description": "Denotes a friendly relationship between characters."
    },
    {
      "name": "interacts with",
      "description": "Describes a scenario in which a character engages with another character, creature, or object."
    },
    ...
  ],
  "patterns": [
    {
      "head": "character",
      "relation": "friends with",
      "tail": "character",
      "description": "One character is friends with another, e.g., Harry Potter is friends with Ron Weasley."
    },
    {
      "head": "character",
      "relation": "interacts with",
      "tail": "object",
      "description": "A character interacting with an object, e.g., Harry Potter interacts with the Invisibility Cloak."
    }
  ]
}

```

Using this schema, we extract relevant concepts from your raw data, construct triples, and generate a graph according to the patterns you define.

```shell
# Create graph from schema

schema = "files/schema.json"
create_graph_with_schema_response = client.graph.create_graph_from_schema(namespace, schema)
print(create_graph_with_schema_response)
# Creating your graph

```

### Create a graph with seed questions

Tell the WhyHow SDK what you care about by providing a list of concepts in the form of natural language questions. Using these questions, we create a small ontology to guide extraction of entities and relationships that are most relevant to your use case, then construct a graph.

```shell

questions = ["What does Harry wear?","Who is Harry friends with?"]

create_graph_response = client.graph.create_graph(namespace, questions)
print(create_graph_response)
# Creating your graph

```

## Query a graph

Query your graph using natural language. Using your natural language query, we automatically construct a Cypher query to run against the graph stored in your Neo4j instance.

```shell

query = "What does Harry wear?"

query_response = client.graph.query_graph(namespace, query)
print(query_response)
# {answer: "Harry wears a cloak, glasses, robe, and Dudley's old clothes.", cypher_query: "MATCH (:Entity {name: "Harry"})-[:WEARS]->(clothing:Entity)\nRETURN clothing;"}

```

### Support

WhyHow.AI is building tools to help developers bring more determinism and control to their RAG pipelines using graph structures. If you're thinking about, in the process of, or have already incorporated knowledge graphs in RAG, we’d love to chat at team@whyhow.ai, or follow our newsletter at [WhyHow.AI](https://www.whyhow.ai/). Join our discussions about rules, determinism and knowledge graphs in RAG on our [Discord](https://discord.com/invite/9bWqrsxgHr).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "whyhow",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "SDK, KG",
    "author": null,
    "author_email": "Tom Smoker <tom@whyhow.ai>, Chris Rec <chris@whyhow.ai>",
    "download_url": "https://files.pythonhosted.org/packages/54/59/67df81144292a083aa417bb3083f929df17a49c36156a8ed0e2c2704d4a9/whyhow-0.0.4.tar.gz",
    "platform": null,
    "description": "# WhyHow Knowledge Graph Creation SDK\n\n[![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)\n[![PyPI Version](https://img.shields.io/pypi/v/whyhow)](https://pypi.org/project/why/)\n[![Code Style: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Checked with mypy](https://img.shields.io/badge/mypy-checked-blue)](https://mypy-lang.org/)\n[![Whyhow Discord](https://dcbadge.vercel.app/api/server/9bWqrsxgHr?compact=true&style=flat)](https://discord.gg/9bWqrsxgHr)\n\nThe WhyHow Knowledge Graph Creation SDK enables you to quickly and easily build automated knowledge graphs tailored to your unique worldview. Instantly build, extend, and query well-scoped KGs with your data.\n\n# Installation\n\n## Prerequisites\n\n- Python 3.10 or higher\n- [OpenAI API key](https://openai.com/)\n- [Pinecone API key](https://www.pinecone.io/)\n- [Neo4j credentials](https://neo4j.com/cloud/platform/aura-graph-database/) (username, password, and URL)\n\n## Install from PyPI\n\nYou can install the SDK directly from PyPI using pip:\n\n```shell\npip install whyhow\n\nexport OPENAI_API_KEY=<your openai api key>\nexport PINECONE_API_KEY=<your pinecone api key>\nexport NEO4J_URL=<your neo4j url>\nexport NEO4J_USERNAME=<your neo4j username>\nexport NEO4J_PASSWORD=<your neo4j password>\n```\n\n## Install from Github\n\nAlternatively, you can clone the repo and install the package\n\n```shell\n\ngit clone git@github.com:whyhow-ai/whyhow.git\ncd whyhow\npip install .\n\nexport OPENAI_API_KEY=<your openai api key>\nexport PINECONE_API_KEY=<your pinecone api key>\nexport NEO4J_URL=<your neo4j url>\nexport NEO4J_USERNAME=<your neo4j username>\nexport NEO4J_PASSWORD=<your neo4j password>\n```\n\n# Examples\n\nNavigate to the `examples/`.\n\n# How to\n\n## Initialize SDK\n\nImport the SDK and initialize the client using your WhyHow API key.\n\n```shell\nfrom whyhow import WhyHow\n\nclient = WhyHow(api_key=<your whyhow api key>)\n```\n\n## Add documents to namespace\n\nYour namespace is a logical grouping of the raw data you upload, the seed concepts you define, and the graphs you create. Namespaces are meant to be tightly scoped to your use case. You can create as many namespaces as you want.\n\n```shell\n\nnamespace = \"harry-potter\"\ndocuments = [\"files/harry_potter_and_the_philosophers_stone.pdf\",\"files/harry_potter_and_the_chamber_of_secrets.pdf\"]\n\ndocuments_response = client.graph.add_documents(namespace, documents)\nprint(documents_response)\n# Adding your documents\n\n```\n\n## Create a graph\n\nYou can create a graph in two different ways. First, you can create a graph using a user-defined schema, giving you complete control over the types of entities and relationships that are extracted and used to build the graph. Or, you can create a graph using a set of seed questions. In this case, WhyHow will automatically extract entities and relationships that are most applicable to the things you want to know, and construct a graph from these concepts.\n\nCreate graph with **schema** if...\n\n1. Your graph must adhere to a consistent structure.\n2. You are very familiar with the structure of your raw documents.\n3. You need comprehensive extraction of concepts across the entire document.\n\nCreate graph with **seed questions** if...\n\n1. You are unsure as to which relationships and patterns you'd like to build into your graph.\n2. You want to build your graph with only the most semantically similar raw data.\n\n### Create a graph with schema\n\nTell the WhyHow SDK exactly which entities, relationships, and patterns you'd like to extract and build into your graph by defining them in a JSON-based schema.\n\n```shell\n\n#schema.json\n\n{\n  \"entities\": [\n    {\n      \"name\": \"character\",\n      \"description\": \"A person appearing in the book, e.g., Harry Potter, Ron Weasley, Hermione Granger, Albus Dumbledore.\"\n    },\n    {\n      \"name\": \"object\",\n      \"description\": \"Inanimate items that characters use or interact with, e.g., wand, Philosopher's Stone, Invisibility Cloak, broomstick.\"\n    }\n    ...\n  ],\n  \"relations\": [\n    {\n      \"name\": \"friends with\",\n      \"description\": \"Denotes a friendly relationship between characters.\"\n    },\n    {\n      \"name\": \"interacts with\",\n      \"description\": \"Describes a scenario in which a character engages with another character, creature, or object.\"\n    },\n    ...\n  ],\n  \"patterns\": [\n    {\n      \"head\": \"character\",\n      \"relation\": \"friends with\",\n      \"tail\": \"character\",\n      \"description\": \"One character is friends with another, e.g., Harry Potter is friends with Ron Weasley.\"\n    },\n    {\n      \"head\": \"character\",\n      \"relation\": \"interacts with\",\n      \"tail\": \"object\",\n      \"description\": \"A character interacting with an object, e.g., Harry Potter interacts with the Invisibility Cloak.\"\n    }\n  ]\n}\n\n```\n\nUsing this schema, we extract relevant concepts from your raw data, construct triples, and generate a graph according to the patterns you define.\n\n```shell\n# Create graph from schema\n\nschema = \"files/schema.json\"\ncreate_graph_with_schema_response = client.graph.create_graph_from_schema(namespace, schema)\nprint(create_graph_with_schema_response)\n# Creating your graph\n\n```\n\n### Create a graph with seed questions\n\nTell the WhyHow SDK what you care about by providing a list of concepts in the form of natural language questions. Using these questions, we create a small ontology to guide extraction of entities and relationships that are most relevant to your use case, then construct a graph.\n\n```shell\n\nquestions = [\"What does Harry wear?\",\"Who is Harry friends with?\"]\n\ncreate_graph_response = client.graph.create_graph(namespace, questions)\nprint(create_graph_response)\n# Creating your graph\n\n```\n\n## Query a graph\n\nQuery your graph using natural language. Using your natural language query, we automatically construct a Cypher query to run against the graph stored in your Neo4j instance.\n\n```shell\n\nquery = \"What does Harry wear?\"\n\nquery_response = client.graph.query_graph(namespace, query)\nprint(query_response)\n# {answer: \"Harry wears a cloak, glasses, robe, and Dudley's old clothes.\", cypher_query: \"MATCH (:Entity {name: \"Harry\"})-[:WEARS]->(clothing:Entity)\\nRETURN clothing;\"}\n\n```\n\n### Support\n\nWhyHow.AI is building tools to help developers bring more determinism and control to their RAG pipelines using graph structures. If you're thinking about, in the process of, or have already incorporated knowledge graphs in RAG, we\u2019d love to chat at team@whyhow.ai, or follow our newsletter at [WhyHow.AI](https://www.whyhow.ai/). Join our discussions about rules, determinism and knowledge graphs in RAG on our [Discord](https://discord.com/invite/9bWqrsxgHr).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Whyhow automated KG SDK",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/whyhow-ai/whyhow"
    },
    "split_keywords": [
        "sdk",
        " kg"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba0c53b12cc210fe57b8229e2e9e802fcb7e23badcb285ac5686273ac24dfec6",
                "md5": "e7ae253b0c4547d9f3490025acae7a03",
                "sha256": "232358ec61e3ebcc51e3a47c6d7410a30743da520e6ed06e5a9758235357dc99"
            },
            "downloads": -1,
            "filename": "whyhow-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7ae253b0c4547d9f3490025acae7a03",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10549,
            "upload_time": "2024-04-21T02:17:24",
            "upload_time_iso_8601": "2024-04-21T02:17:24.846348Z",
            "url": "https://files.pythonhosted.org/packages/ba/0c/53b12cc210fe57b8229e2e9e802fcb7e23badcb285ac5686273ac24dfec6/whyhow-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "545967df81144292a083aa417bb3083f929df17a49c36156a8ed0e2c2704d4a9",
                "md5": "84d85eeef1057beac4da59a6446be8be",
                "sha256": "3bb4d7fc2faa77dbbb8f27a0549fcf3a14619a621eaccaf1d9b6318b803a9f7c"
            },
            "downloads": -1,
            "filename": "whyhow-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "84d85eeef1057beac4da59a6446be8be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12810,
            "upload_time": "2024-04-21T02:17:26",
            "upload_time_iso_8601": "2024-04-21T02:17:26.508338Z",
            "url": "https://files.pythonhosted.org/packages/54/59/67df81144292a083aa417bb3083f929df17a49c36156a8ed0e2c2704d4a9/whyhow-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 02:17:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "whyhow-ai",
    "github_project": "whyhow",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "whyhow"
}
        
Elapsed time: 0.23370s