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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: causalif-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 ee8681302d039ad884d9cebae89fea50fb6c0defcb1c816803a120749b10eafd
MD5 656df408c5700c40065d7aaf0c28efae
BLAKE2b-256 5fbda701f6a91c3b615cf9e70101d688f301a4e3612f2e352998d2ae0b5f2739

See more details on using hashes here.

File details

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

File metadata

  • Download URL: causalif-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ff908d89edd674059b2549970d3ea5cd2a698e3e79180559cb1d43e1f52664c
MD5 003dce617b57deabeece08358e0cd060
BLAKE2b-256 114b0677caaa98f0e7cb527d2187439828261352444f57bc6a044103a77bf659

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