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.4.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.4-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: causalif-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 73def9290a9960d6020b2a9bb5985c3963033d8592a901c4e6d06b4ad59ebf12
MD5 504903a10574185885e0fb60539fd84b
BLAKE2b-256 6bb4c3af38cf4f2d8bfef4360b200056f82f6cc13c12e45525139d31800a0ab0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: causalif-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cbab879eb0c1cdf034aba629812f805619975f59e1c6953475d2df9a99e4e791
MD5 74e5e90e1e995ce0c159cdbd69bb9b37
BLAKE2b-256 23e54ab681a1942ae347c62ded8374fdb74ac12e79e559d5b67923be88e8656b

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