Skip to main content

LLM assisted causal reasoning with JAX and RAG

Project description

Causal Inference Framework for AWS (causalif)

LLM assisted causal reasoning library built with JAX and RAG. Designed primarily for agentic LLM applications, this library can also be used standalone in Jupyter notebooks with access to Bedrock.

github: https://github.com/awslabs/causalif pypi: https://pypi.org/project/causalif/

Architecture and usage in applications

Library architecture: Overall design where causalif integrates with agentic applciations:

prerequisites

This library is based on RAG; it requires a knowledgebase to be ready before using this library. Below steps are required to be performed before using this library.

Step-1:

You can set up a bedrock knowledgebase following the instructions.

Step-2:

After setting up a knowledgebase, you can create a retriever tool like the following:

```python
from langchain_aws.retrievers import AmazonKnowledgeBasesRetriever
from langchain.tools.retriever import create_retriever_tool

retriever = AmazonKnowledgeBasesRetriever(
    knowledge_base_id="",
    retrieval_config={
        "vectorSearchConfiguration": {
            "numberOfResults": 20 #it could be any of your desired number
        }
    },
)

retriever_tool = create_retriever_tool(
    retriever,
    "",
    "",
)```

Installation

```bash
pip install causalif
```

QuickStart

```python
from causalif import set_causalif_engine, causalif_tool, visualize_causalif_results
```

Configure the engine

```python
set_causalif_engine(
model=your_model,       #Bedrock or any other provider. Please import the provider if it is other than Bedrock.
retriever_tool=retriever_tool,      # retriever_tool from prerequisites.
dataframe=your_dataframe,       # if you want all columns of your dataframe to be considered in causal analysis. Otherwise, leave it as 'None'.
factors = list of factors,      # list of your factors, e.g., ['water', 'food', 'exercise'].
domains = list of domains,      # list of your domains, e.g., ['life', 'health', 'well being'].
max_degrees=1,      # degrees of relationships that you wish to check.
max_parallel_queries=10         # it could be between 4 to 50 but it depends on the model throughput.
)
```

Use the tool

```python
result = causalif_tool("Why is water so low in body after we wake up?")
```
```python
"""
Allowed formation of enqueries (<\target_factor> is the column or factor whose dependencies with other variables we want to analyze):

1. why (is|are) <\target_factor> so (low|high|poor|bad|good),
2. what (causes|affects|influences) <\target_factor>,
3. <\target_factor> (is|are) too (low|high)",
4. analyze the causes (of|for) <\target_factor>,
5. dependencies (of|for) <\target_factor>,
6. factors (affecting|influencing) <\target_factor>
"""
```

Visualize results

```python
fig = visualize_causalif_results(result)
fig.show()
```

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

causalif-0.1.5.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causalif-0.1.5-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file causalif-0.1.5.tar.gz.

File metadata

  • Download URL: causalif-0.1.5.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for causalif-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3f4244cf707a5780abb42b48d153cfa1f62bff2248ade473eeee0f007267fdfb
MD5 fb5d2b1603090577cbf68483ba7dcf7f
BLAKE2b-256 92d259901e56507ab5cf57fe74132915d1a275204f35b7547ddb6dbdefb2ca1a

See more details on using hashes here.

File details

Details for the file causalif-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: causalif-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for causalif-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d9115217f8197350ee61d98c443bfe94bcc4091c05bb987460b7a8ee0bcbb3a5
MD5 324804f8d74dcbea00e7fd1a7bfaa530
BLAKE2b-256 b5948db2b8cf2dad92199dba706d2d997893abb2c31bf731acef290d000548d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page