Python lib created only for RAG related text based enterprise solutions
Project description
🔗 ORICHAIN
Orichain is a Python library designed as a custom wrapper for Retrieval-Augmented Generation (RAG) use cases, built to integrate seamlessly with your endpoints.
It provides support for:
-
Embedding creation
- AWS Bedrock
- Cohere embeddings
- Titan embeddings
- OpenAI Embeddings
- TogetherAI Embedding Models
- Google Gemini & Vertex AI Embeddings
- Azure OpenAI Embeddings
- Sentence Transformers
- AWS Bedrock
-
Knowledge base (Vector Databases)
- Pinecone
- ChromaDB
-
Large Language Models
- OpenAI
- Azure OpenAI
- Anthropic
- Google Gemini & Vertex AI Models
- TogetherAI
- AWS Bedrock
- Anthropic models (Series 3, 3.5, 3.7, 4)
- LLAMA models (Series 3, 3.1, 3.2, 3.3, 4)
- Amazon Titan text models
- Amazon Nova series models
- Mistral models
- Inference Profiles
This library was built to make the applications of all the codes easy to write and review. It can be said that it was inspired by LangChain but is optimized for better performance. The entire codebase is asynchronous and threaded, eliminating the need for you to worry about optimization.
📚 Documentation
Full documentation is available here: ➡️ https://orichain.readthedocs.io/en/latest/
Table of Contents
📦 Installation
🚧 Note:
- The Library was rewritten in v2.0.0 released in March of 2025. There were significant changes made.
- Starting from version 2.0.1 (May 2025), a
providerargument is now required when initializing the LLM and EmbeddingModel classes.
Install via pip:
pip install orichain
We have added Sentence Transformers and Lingua Language Detector as optional packages, so if you want to use them, please do one of the following:
Installation Options
1️⃣ Install with orichain:
- For
sentence-transformers:
pip install "orichain[sentence-transformers]"
- For
lingua-language-detector:
pip install "orichain[lingua-language-detector]"
2️⃣ Install directly:
- For
sentence-transformers:
pip install sentence-transformers==3.4.1
- For
lingua-language-detector:
pip install lingua-language-detector==2.1.0
🚀 Usage Example
A quick example of how to use Orichain:
from orichain.llm import AsyncLLM
import os
from dotenv import load_dotenv
load_dotenv()
llm = AsyncLLM(
model_name="gpt-5-mini",
provider="OpenAI",
api_key=os.getenv("OPENAI_KEY")
)
user_message = "I am feeling sad"
system_prompt = """You need to return a JSON object with a key emotion and detect the user emotion like this:
{
"emotion": return the detected emotion of user
}"""
llm_response = await llm(
user_message=user_message,
system_prompt=system_prompt,
do_json=True # This insures that the response will be a json
)
✨ Features
Reasons to use Orichain:
- Supports Both Sync and Async: Provides flexibility for different use cases.
- Optimized Performance: Utilizes threading for efficiency, especially when used with FastAPI.
- Hot-Swappable Components: Easily modify RAG components as project requirements evolve, ensuring high flexibility.
- Unified tool-calling interface across all providers, ensuring seamless modularity.
💡 Example
Here is a basic example of how to use this code:
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse, Response, StreamingResponse
from orichain.embeddings import AsyncEmbeddingModel
from orichain.knowledge_base import AsyncKnowledgeBase
from orichain.llm import AsyncLLM
import os
from dotenv import load_dotenv
from typing import Dict
load_dotenv()
# Initialize embedding model
embedding_model = AsyncEmbeddingModel(
model_name="text-embedding-ada-002",
provider="OpenAI",
api_key=os.getenv("OPENAI_KEY")
)
# Initialize vector database manager
knowledge_base_manager = AsyncKnowledgeBase(
vector_db_type="pinecone",
api_key=os.getenv("PINECONE_KEY"),
index_name="<set your index name>",
namespace="<set your namespace>",
)
# Initialize LLM
llm = AsyncLLM(
model_name="gpt-5-mini",
provider="OpenAI",
api_key=os.getenv("OPENAI_KEY")
)
app = FastAPI(redoc_url=None, docs_url=None)
@app.post("/generative_response")
async def generate(request: Request) -> Response:
# Parse incoming request
request_json = await request.json()
user_message = request_json.get("user_message")
prev_pairs = request_json.get("prev_pairs")
metadata = request_json.get("metadata")
# Generate embeddings for the user query
user_message_vector = await embedding_model(user_message=user_message)
if isinstance(user_message_vector, Dict):
return JSONResponse(user_message_vector)
# Retrieve relevant chunks from the knowledge base
retrived_chunks = await knowledge_base_manager(
user_message_vector=user_message_vector,
num_of_chunks=5,
)
if isinstance(retrived_chunks, Dict) and "error" in retrived_chunks:
return JSONResponse(retrived_chunks)
# Convert retrieved data into plain text list
matched_sentence = convert_to_text_list(retrived_chunks)
# (Define `convert_to_text_list` to process KB output into a list of strings)
system_prompt = f"""As a helpful, engaging, and friendly chatbot, answer the user's query based on the following context:
<data>
{"\n\n".join(matched_sentence)}
</data>"""
# Streaming response
if metadata.get("stream"):
return StreamingResponse(
llm.stream(
request=request,
user_message=user_message,
matched_sentence=matched_sentence,
system_prompt=system_prompt,
chat_hist=prev_pairs
),
headers={
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"X-Accel-Buffering": "no",
},
media_type="text/event-stream",
)
# Non-streaming response
else:
llm_response = await llm(
request=request,
user_message=user_message,
matched_sentence=matched_sentence,
system_prompt=system_prompt,
chat_hist=prev_pairs
)
return JSONResponse(llm_response)
🛣️ Roadmap
Here's our plan for upcoming features and improvements:
Short-term goals
- Do testing of the latest version
- Release stable 1.0.0 version
- Create Documentation
- Write class and function definitions
- Add function calling support
- Add Together AI support
Long-term goals
- Publish it to pypi
- Refactor the code for better readability
🤝 Contributing
We welcome contributions to help us achieve these goals!
📝 Steps
- Stage all changes
git add .
- Commit the changes
git commit -m "Release vX.X.X"
- Create a new tag
git tag vX.X.X
- Push commits to main branch
git push origin main
- Push the new tag
git push origin vX.X.X
Deleting Tags:
- Delete a Local Tag
git tag -d vX.X.X
- Delete a Remote Tag
git push origin --delete vX.X.X
📄 License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orichain-2.5.0.tar.gz.
File metadata
- Download URL: orichain-2.5.0.tar.gz
- Upload date:
- Size: 100.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3ca3aac3ff437f710546ffb4f3aed65845446f8af755b29df418847dfda47d4
|
|
| MD5 |
40d2a4ed658a3da633f6f98abb7c1344
|
|
| BLAKE2b-256 |
f20f030df3500d1ace3998cd90d738cd368ecf6be1069d62a5c2a0cfe4279467
|
Provenance
The following attestation bundles were made for orichain-2.5.0.tar.gz:
Publisher:
publish.yml on OriserveAI/orichain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orichain-2.5.0.tar.gz -
Subject digest:
e3ca3aac3ff437f710546ffb4f3aed65845446f8af755b29df418847dfda47d4 - Sigstore transparency entry: 701959522
- Sigstore integration time:
-
Permalink:
OriserveAI/orichain@1a50bf631e2d73fa723368cda180e30059d9c6b6 -
Branch / Tag:
refs/tags/v2.5.0 - Owner: https://github.com/OriserveAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1a50bf631e2d73fa723368cda180e30059d9c6b6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file orichain-2.5.0-py3-none-any.whl.
File metadata
- Download URL: orichain-2.5.0-py3-none-any.whl
- Upload date:
- Size: 75.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba767cac85501751deeadcf906a72bd7bb39010d671c7b3ab0daa985fcdca6fb
|
|
| MD5 |
30250e1217013f4304854c2f6335fdbc
|
|
| BLAKE2b-256 |
3dda8b1efa26280f77628d4e14e2ed645d7dad811dcb148811854586904c94ae
|
Provenance
The following attestation bundles were made for orichain-2.5.0-py3-none-any.whl:
Publisher:
publish.yml on OriserveAI/orichain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
orichain-2.5.0-py3-none-any.whl -
Subject digest:
ba767cac85501751deeadcf906a72bd7bb39010d671c7b3ab0daa985fcdca6fb - Sigstore transparency entry: 701959523
- Sigstore integration time:
-
Permalink:
OriserveAI/orichain@1a50bf631e2d73fa723368cda180e30059d9c6b6 -
Branch / Tag:
refs/tags/v2.5.0 - Owner: https://github.com/OriserveAI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1a50bf631e2d73fa723368cda180e30059d9c6b6 -
Trigger Event:
push
-
Statement type: