Spaces:
Sleeping
Sleeping
Commit ·
d912766
0
Parent(s):
implemented pdf chunking pipeline for rag system
Browse files- .gitattributes +7 -0
- .gitignore +7 -0
- README.md +49 -0
- ai-saftey-audit/README.md +8 -0
- ai-saftey-audit/__init__.py +0 -0
- multimodal-engine/README.md +8 -0
- multimodal-engine/__init__.py +0 -0
- rag-system/README.md +8 -0
- rag-system/__init__.py +0 -0
- rag-system/app/__init__.py +0 -0
- rag-system/app/load_pdf.py +33 -0
- rag-system/app/testdb_load.py +48 -0
- rag-system/data/ArtificiaL_.pdf +3 -0
- rag-system/requirements.txt +0 -0
- requirements.txt +11 -0
.gitattributes
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
.env
|
| 3 |
+
__pycache__/
|
| 4 |
+
*.pyc
|
| 5 |
+
instance/
|
| 6 |
+
*.log
|
| 7 |
+
chroma_db
|
README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🗺️ AI Engineering Roadmap
|
| 2 |
+
|
| 3 |
+
Welcome to the AI Engineering learning roadmap. This repository tracks the journey from core RAG architecture to advanced multimodal systems and AI safety frameworks.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 🚀 Phase 1: Foundation & Retrieval-Augmented Generation (RAG)
|
| 8 |
+
* **Duration:** ~12 Days
|
| 9 |
+
* **Core Objective:** Build a production-ready system capable of chatting with unstructured documents.
|
| 10 |
+
|
| 11 |
+
### 📚 Core Concepts
|
| 12 |
+
- [ ] **Text Chunking:** Strategies for splitting text without losing context.
|
| 13 |
+
- [ ] **Embeddings:** Converting words and sentences into numerical vectors.
|
| 14 |
+
- [ ] **Vector Databases:** Storing and querying high-dimensional vector data.
|
| 15 |
+
- [ ] **Information Retrieval:** Fetching the most relevant context for a user query.
|
| 16 |
+
- [ ] **Prompt Engineering:** Structuring system instructions for optimal LLM output.
|
| 17 |
+
- [ ] **Hallucination Reduction:** Designing guardrails to ensure factual accuracy.
|
| 18 |
+
- [ ] **API Development:** Building robust backends using **FastAPI**.
|
| 19 |
+
- [ ] **UI Development:** Creating interactive web interfaces with **Streamlit**.
|
| 20 |
+
|
| 21 |
+
📦 **Final Deliverable:** **Chat with PDF AI System**
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 🎬 Phase 2: Multimodal AI & Media Automation
|
| 26 |
+
* **Duration:** ~8 Days
|
| 27 |
+
* **Core Objective:** Process and synthesize multiple data types (audio, video, text) into automated pipelines.
|
| 28 |
+
|
| 29 |
+
### 📚 Core Concepts
|
| 30 |
+
- [ ] **Audio Transcription:** Deploying OpenAI's **Whisper** for high-accuracy speech-to-text.
|
| 31 |
+
- [ ] **AI Summarization:** Condensing long-form media content into key insights.
|
| 32 |
+
- [ ] **Video Processing:** Constructing automated workflows to slice and stitch video timelines.
|
| 33 |
+
- [ ] **Automation Workflows:** Linking multiple model outputs into a seamless production pipeline.
|
| 34 |
+
|
| 35 |
+
📦 **Final Deliverable:** **AI Reel Generator System**
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## 🛡️ Phase 3: AI Safety, Security & Evaluation
|
| 40 |
+
* **Duration:** ~6 Days
|
| 41 |
+
* **Core Objective:** Stress-test LLMs against adversarial inputs and implement strict safety guardrails.
|
| 42 |
+
|
| 43 |
+
### 📚 Core Concepts
|
| 44 |
+
- [ ] **Prompt Attacks:** Understanding prompt injection and adversarial manipulation.
|
| 45 |
+
- [ ] **Jailbreak Testing:** Red-teaming models to bypass standard system alignment.
|
| 46 |
+
- [ ] **AI Evaluation:** Quantifying model performance, bias, and correctness.
|
| 47 |
+
- [ ] **Safety Frameworks:** Implementing responsible AI principles and compliance guidelines.
|
| 48 |
+
|
| 49 |
+
📦 **Final Deliverable:** **AI Safety Audit Report + Testing Framework**
|
ai-saftey-audit/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GuardrailAI: Safety & Bias Evaluation Toolkit
|
| 2 |
+
|
| 3 |
+
An alignment and auditing framework built to detect bias, mitigate toxicity, and secure LLM applications.
|
| 4 |
+
|
| 5 |
+
### Key Features:
|
| 6 |
+
* **Prompt Injection Defense:** Real-time filtering to block malicious user inputs.
|
| 7 |
+
* **Bias & Fairness Auditing:** Automated test suites to scan model responses for stereotypes or unfair bias.
|
| 8 |
+
* **Toxicity Guardrails:** An evaluation layer that ensures model outputs remain safe and compliant.
|
ai-saftey-audit/__init__.py
ADDED
|
File without changes
|
multimodal-engine/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SynapseMedia: Multimodal Content Engine
|
| 2 |
+
|
| 3 |
+
An AI engine designed to process, analyze, and generate content across multiple data types (Text, Images, and Audio).
|
| 4 |
+
|
| 5 |
+
### Key Features:
|
| 6 |
+
* **Cross-Modal Search:** Search image and video databases using natural language queries.
|
| 7 |
+
* **Automated Asset Generation:** Generates text descriptions from visual inputs and vice versa.
|
| 8 |
+
* **Unified API:** A single backend framework handling both vision and language models.
|
multimodal-engine/__init__.py
ADDED
|
File without changes
|
rag-system/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ContextFlow: Advanced RAG Pipeline
|
| 2 |
+
|
| 3 |
+
A production-ready Retrieval-Augmented Generation (RAG) system built to connect LLMs to custom data.
|
| 4 |
+
|
| 5 |
+
### Key Features:
|
| 6 |
+
* **Hybrid Search:** Combines semantic vector search with keyword matching.
|
| 7 |
+
* **Smart Re-ranking:** Optimizes context relevance before sending data to the LLM.
|
| 8 |
+
* **Document Pipeline:** Handles PDF parsing, text chunking, and automated vector database ingestion.
|
rag-system/__init__.py
ADDED
|
File without changes
|
rag-system/app/__init__.py
ADDED
|
File without changes
|
rag-system/app/load_pdf.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from langchain_community.document_loaders import PyPDFLoader
|
| 4 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 5 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 6 |
+
#from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 7 |
+
from langchain_community.vectorstores import Chroma
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
# load PDF
|
| 12 |
+
pdf_path = r"C:/Users/ajmel/desktop/internship-projects/rag-system/data/ArtificiaL_.pdf"
|
| 13 |
+
loader = PyPDFLoader(pdf_path)
|
| 14 |
+
documents = loader.load()
|
| 15 |
+
|
| 16 |
+
# split into chunks
|
| 17 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 18 |
+
chunks = text_splitter.split_documents(documents)
|
| 19 |
+
|
| 20 |
+
#create embeding
|
| 21 |
+
embeding_model = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 22 |
+
persistence_directory = "./chroma_db"
|
| 23 |
+
|
| 24 |
+
vectorstore = Chroma.from_documents(
|
| 25 |
+
documents=chunks,
|
| 26 |
+
embedding=embeding_model,
|
| 27 |
+
collection_name="pdf_chunks",
|
| 28 |
+
persist_directory=persistence_directory
|
| 29 |
+
)
|
| 30 |
+
vectorstore.persist()
|
| 31 |
+
|
| 32 |
+
print(f"Successfully loaded and embedded {len(chunks)} chunks into ChromaDB!")
|
| 33 |
+
|
rag-system/app/testdb_load.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import chromadb
|
| 2 |
+
|
| 3 |
+
# sample data
|
| 4 |
+
raw_document = (
|
| 5 |
+
"The domestic cat (Felis catus) is a small carnivorous mammal. It is the only "
|
| 6 |
+
"domesticated species in the family Felidae. Cats are known for their agility, "
|
| 7 |
+
"exceptional hunting skills, and flexible bodies. On the other hand, the "
|
| 8 |
+
"domestic dog (Canis lupus familiaris) is a domesticated descendant of the wolf. "
|
| 9 |
+
"Dogs were the first species to be domesticated by humans over 15,000 years ago, "
|
| 10 |
+
"evolving to become uniquely attuned to human behavior."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# chunking
|
| 14 |
+
def text_chunking(text, chunk_size = 20, overlap = 5):
|
| 15 |
+
words = text.split()
|
| 16 |
+
chunks = []
|
| 17 |
+
i = 0
|
| 18 |
+
while i < len(words):
|
| 19 |
+
chunk = " ".join(words[i: i + chunk_size])
|
| 20 |
+
chunks.append(chunk)
|
| 21 |
+
|
| 22 |
+
i += chunk_size - overlap
|
| 23 |
+
|
| 24 |
+
return chunks
|
| 25 |
+
chunk_text = text_chunking(raw_document, chunk_size=20, overlap=5)
|
| 26 |
+
|
| 27 |
+
chroma_client = chromadb.Client()
|
| 28 |
+
collection = chroma_client.get_or_create_collection(name="animal_knowladge")
|
| 29 |
+
unique_ids = [f"chunks_{i}" for i in range(len(chunk_text))]
|
| 30 |
+
collection.add(
|
| 31 |
+
documents=chunk_text,
|
| 32 |
+
ids=unique_ids
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
query = "Tell me about feline traits"
|
| 36 |
+
|
| 37 |
+
search_result = collection.query(
|
| 38 |
+
query_texts= [query],
|
| 39 |
+
n_results=1
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
collection.get(ids=["chunks_0"])
|
| 43 |
+
|
| 44 |
+
print(f"______rag pipeline______")
|
| 45 |
+
print(f"user query: {query}\n")
|
| 46 |
+
print(f"Retrived Context Chunk:")
|
| 47 |
+
print(search_result["documents"][0][0])
|
| 48 |
+
print(f"\nDistance Score (Lower means closer match): {search_result['distances'][0][0]}")
|
rag-system/data/ArtificiaL_.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4cdae8b6aaa4b525decc36e0d80d2c16dc709aa924e21266640eb47cbe327800
|
| 3 |
+
size 11745647
|
rag-system/requirements.txt
ADDED
|
Binary file (2.3 kB). View file
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests>=2.31.0
|
| 2 |
+
cryptography>=42.0.0
|
| 3 |
+
pyjwt>=2.8.0
|
| 4 |
+
python-dotenv>=1.0.0
|
| 5 |
+
langchain>=0.1.0
|
| 6 |
+
langchain-community>=0.0.10
|
| 7 |
+
langchain-openai>=0.1.0
|
| 8 |
+
langchain-google-genai>=1.0.0
|
| 9 |
+
chromadb>=0.4.24
|
| 10 |
+
streamlit>=1.32.0
|
| 11 |
+
pypdf>=6.12.0
|