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:

Example usage

example notebook: https://github.com/awslabs/causalif/blob/subhro/bug_fix/examples/causalif.ipynb

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
from langchain_aws import ChatBedrock
```

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.

version updates

v 0.1.4 -> base version v 0.1.5 -> readme update v 0.1.6 -> removed directed graph dependecies from engine.py and added an example notebook

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.6.tar.gz (23.0 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.6-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: causalif-0.1.6.tar.gz
  • Upload date:
  • Size: 23.0 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.6.tar.gz
Algorithm Hash digest
SHA256 bee04f847100baabeb52fb3cd4472065b17d316729ce72205d33daecc45eafcb
MD5 39ced6cc7f07a6b12e0cb3905dab0790
BLAKE2b-256 490bc3817c36136fc891cbb9d7eb8fb35044fe6f34a669b14bb57624cd71711e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: causalif-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 23.0 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0f125c093a6ffd0a5674b55f788e88ceb4cda4c6674a12bcebca2f37b875148b
MD5 1702c61952df89a17f2d7181674338cc
BLAKE2b-256 10067092a4835aa4dbe9b60581787b60915afd5730a761069cc8f8e0e9b1984d

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