Skip to main content

LLM assisted causal reasoning with JAX and RAG

Project description

Causal Inference Framework for AWS (causalif)

LLM assisted Causal Reasoning with JAX and RAG

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:

why (is|are)  so (low|high|poor|bad|good)",
what (causes|affects|influences) ",
 (is|are) too (low|high)",
analyze the causes (of|for) ",
dependencies (of|for) ,
factors (affecting|influencing) "
"""
```

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: causalif-0.1.0.tar.gz
  • Upload date:
  • Size: 22.3 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.0.tar.gz
Algorithm Hash digest
SHA256 5591ea9613200dba8638f663b502d165b2e92aa6c86f2bf22a6002a41b03e846
MD5 aae0019df9540bb8ec43c03b0f74b03d
BLAKE2b-256 f48249df9bbebb337e876dd8a0a612c65eeb09b3c92487db75b93b017460dc6e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: causalif-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08d24fa442677334267a9fd71c15b203b2a2ca2ac89ec0108db9f5c771111341
MD5 233d6fa7c9e2e7673133d56e260104a3
BLAKE2b-256 8d4494463090dd8bb1c25dadc0811f5ed6f5af4627da5285ae88c4d397c41f91

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