This project implements a modular Retrieval-Augmented Generation (RAG) assistant using LangChain, designed to answer legal and technical queries based on custom documents. It features document ingestion, semantic retrieval, prompt templating, and LLM-backed response generation—all wrapped in a clean CLI and Streamlit interface.
legal_brief_companion/
├── src/
│ └── legal_brief_companion/
│ ├── __init__.py
│ ├── config/
│ │ └── settings.py # Application configuration and env loading
│ ├── ingestion/
│ │ ├── document_loader.py # Load PDFs/texts into the pipeline
│ │ └── text_splitter.py # Chunk large documents
│ ├── retrieval/
│ │ ├── vector_store.py # Manage vector store persistence (Chroma)
│ │ └── retriever.py # Query and rank relevant chunks
│ ├── llm/
│ │ ├── chain.py # LLM orchestration and chains
│ │ └── prompt_templates.py # Reusable prompt templates
│ ├── interface/
│ │ └── cli.py # CLI for local usage
│ ├── utils/
│ │ └── helpers.py # Shared utilities and helpers
│ └── tests/ # Unit tests
│ | ├── test_chain.py
│ | ├── test_ingestion.py
│ | └── test_llm.py
│ └── ingest.py # CLI/script entry for ingestion
├── data/
│ ├── documents/ # User documents (PDFs, txt)
│ └── vector_store/ # Persisted vector DB files
│ └── <instance-id>/
|
├── app.py # Streamlit / main app entry
├── pyproject.toml
├── requirements.txt
├── .env
├── .gitignore
└── README.md
- Python 3.9+
- Groq API key
- pip or poetry
-
Clone the repository:
git clone <your_repository_url> cd legal_brief_companion
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up your environment variables in the
.envfile. Important: Do not hardcode your API key directly in the.envfile. Instead, set it as an environment variable in your system.GROQ_API_KEY=your_groq_key EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2 LLM_PROVIDER=groq LLM_MODEL=llama3-8b-8192 DATABASE_URL=sqlite:///data/knowledge_base.db DOCUMENTS_PATH=data/documents PERSIST_DIRECTORY=data/vector_store MODEL_NAME=llama3-8b-8192 VECTOR_STORE_TYPE=chroma debug = true -
Set your Groq API key as an environment variable:
# PowerShell $env:GROQ_API_KEY="your_api_key_here" # Linux/macOS export GROQ_API_KEY="your_api_key_here"
-
Ingest your documents: This process will create the vector store.
python src/legal_brief_companion/ingest.py
-
Run the application:
streamlit run app.py
After running the application, you can interact with the assistant through the command-line interface or the Streamlit interface. Provide your queries, and the assistant will respond based on the ingested documents.
- Document Ingestion: Load and chunk legal PDFs or text files using
document_loader.pyandtext_splitter.py. - Vector Store Retrieval: Embed and retrieve relevant chunks using ChromaDB, managed by
vector_store.pyandretriever.py. - LLM Interaction: Generate answers using Groq-hosted LLaMA models, orchestrated by
chain.py. - Prompt Templates: Modular prompts for transparent reasoning, defined in
prompt_templates.py. - User Interface: Streamlit frontend (
app.py) and CLI (cli.py) for flexible interaction. - Config Management: Pydantic-based
.envloader for reproducibility viasettings.py.
- PDF and text file ingestion
- Intelligent document chunking
- Semantic embedding generation
- ChromaDB vector store integration
- Similarity-based chunk retrieval
- Context ranking and selection
- Groq-hosted LLaMA models
- Structured prompt engineering
- Response chain orchestration
Basic unit tests are included under src/legal_brief_companion/tests/. Run with:
pytest src/legal_brief_companion/tests/- Never commit your
.envfile or API keys to GitHub. The.gitignorefile is set up to exclude secrets and unnecessary files. - Use environment variables for secrets
- Follow security best practices
- Regular dependency updates
This project is licensed under the MIT License.
Built by Getahune Wondemenhu Alemayhu.
- Email: [getahune.alemayhu@gmail.com] For questions, contributions, or collaboration, feel free to reach out or open an issue.
Please open issues or submit pull requests for improvements or bug fixes. Follow the existing code style and include tests for new features and suggestions.