feat: Week 1 Complete - Universal RAG Preprocessor Foundation
Implements Week 1 of the 4-week strategic plan to position Skill Seekers as universal infrastructure for AI systems. Adds RAG ecosystem integrations (LangChain, LlamaIndex, Pinecone, Cursor) with comprehensive documentation. ## Technical Implementation (Tasks #1-2) ### New Platform Adaptors - Add LangChain adaptor (langchain.py) - exports Document format - Add LlamaIndex adaptor (llama_index.py) - exports TextNode format - Implement platform adaptor pattern with clean abstractions - Preserve all metadata (source, category, file, type) - Generate stable unique IDs for LlamaIndex nodes ### CLI Integration - Update main.py with --target argument - Modify package_skill.py for new targets - Register adaptors in factory pattern (__init__.py) ## Documentation (Tasks #3-7) ### Integration Guides Created (2,300+ lines) - docs/integrations/LANGCHAIN.md (400+ lines) * Quick start, setup guide, advanced usage * Real-world examples, troubleshooting - docs/integrations/LLAMA_INDEX.md (400+ lines) * VectorStoreIndex, query/chat engines * Advanced features, best practices - docs/integrations/PINECONE.md (500+ lines) * Production deployment, hybrid search * Namespace management, cost optimization - docs/integrations/CURSOR.md (400+ lines) * .cursorrules generation, multi-framework * Project-specific patterns - docs/integrations/RAG_PIPELINES.md (600+ lines) * Complete RAG architecture * 5 pipeline patterns, 2 deployment examples * Performance benchmarks, 3 real-world use cases ### Working Examples (Tasks #3-5) - examples/langchain-rag-pipeline/ * Complete QA chain with Chroma vector store * Interactive query mode - examples/llama-index-query-engine/ * Query engine with chat memory * Source attribution - examples/pinecone-upsert/ * Batch upsert with progress tracking * Semantic search with filters Each example includes: - quickstart.py (production-ready code) - README.md (usage instructions) - requirements.txt (dependencies) ## Marketing & Positioning (Tasks #8-9) ### Blog Post - docs/blog/UNIVERSAL_RAG_PREPROCESSOR.md (500+ lines) * Problem statement: 70% of RAG time = preprocessing * Solution: Skill Seekers as universal preprocessor * Architecture diagrams and data flow * Real-world impact: 3 case studies with ROI * Platform adaptor pattern explanation * Time/quality/cost comparisons * Getting started paths (quick/custom/full) * Integration code examples * Vision & roadmap (Weeks 2-4) ### README Updates - New tagline: "Universal preprocessing layer for AI systems" - Prominent "Universal RAG Preprocessor" hero section - Integrations table with links to all guides - RAG Quick Start (4-step getting started) - Updated "Why Use This?" - RAG use cases first - New "RAG Framework Integrations" section - Version badge updated to v2.9.0-dev ## Key Features ✅ Platform-agnostic preprocessing ✅ 99% faster than manual preprocessing (days → 15-45 min) ✅ Rich metadata for better retrieval accuracy ✅ Smart chunking preserves code blocks ✅ Multi-source combining (docs + GitHub + PDFs) ✅ Backward compatible (all existing features work) ## Impact Before: Claude-only skill generator After: Universal preprocessing layer for AI systems Integrations: - LangChain Documents ✅ - LlamaIndex TextNodes ✅ - Pinecone (ready for upsert) ✅ - Cursor IDE (.cursorrules) ✅ - Claude AI Skills (existing) ✅ - Gemini (existing) ✅ - OpenAI ChatGPT (existing) ✅ Documentation: 2,300+ lines Examples: 3 complete projects Time: 12 hours (50% faster than estimated 24-30h) ## Breaking Changes None - fully backward compatible ## Testing All existing tests pass Ready for Week 2 implementation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
122
examples/langchain-rag-pipeline/README.md
Normal file
122
examples/langchain-rag-pipeline/README.md
Normal file
@@ -0,0 +1,122 @@
|
||||
# LangChain RAG Pipeline Example
|
||||
|
||||
Complete example showing how to build a RAG (Retrieval-Augmented Generation) pipeline using Skill Seekers documents with LangChain.
|
||||
|
||||
## What This Example Does
|
||||
|
||||
1. **Loads** Skill Seekers-generated LangChain Documents
|
||||
2. **Creates** a persistent Chroma vector store
|
||||
3. **Builds** a RAG query engine with GPT-4
|
||||
4. **Queries** the documentation with natural language
|
||||
|
||||
## Prerequisites
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install langchain langchain-community langchain-openai chromadb openai
|
||||
|
||||
# Set API key
|
||||
export OPENAI_API_KEY=sk-...
|
||||
```
|
||||
|
||||
## Generate Documents
|
||||
|
||||
First, generate LangChain documents using Skill Seekers:
|
||||
|
||||
```bash
|
||||
# Option 1: Use preset config (e.g., React)
|
||||
skill-seekers scrape --config configs/react.json
|
||||
skill-seekers package output/react --target langchain
|
||||
|
||||
# Option 2: From GitHub repo
|
||||
skill-seekers github --repo facebook/react --name react
|
||||
skill-seekers package output/react --target langchain
|
||||
|
||||
# Output: output/react-langchain.json
|
||||
```
|
||||
|
||||
## Run the Example
|
||||
|
||||
```bash
|
||||
cd examples/langchain-rag-pipeline
|
||||
|
||||
# Run the quickstart script
|
||||
python quickstart.py
|
||||
```
|
||||
|
||||
## What You'll See
|
||||
|
||||
1. **Documents loaded** from JSON file
|
||||
2. **Vector store created** with embeddings
|
||||
3. **Example queries** demonstrating RAG
|
||||
4. **Interactive mode** to ask your own questions
|
||||
|
||||
## Example Output
|
||||
|
||||
```
|
||||
============================================================
|
||||
LANGCHAIN RAG PIPELINE QUICKSTART
|
||||
============================================================
|
||||
|
||||
Step 1: Loading documents...
|
||||
✅ Loaded 150 documents
|
||||
Categories: {'overview', 'hooks', 'components', 'api'}
|
||||
|
||||
Step 2: Creating vector store...
|
||||
✅ Vector store created at: ./chroma_db
|
||||
Documents indexed: 150
|
||||
|
||||
Step 3: Creating QA chain...
|
||||
✅ QA chain created
|
||||
|
||||
Step 4: Running example queries...
|
||||
|
||||
============================================================
|
||||
QUERY: How do I use React hooks?
|
||||
============================================================
|
||||
|
||||
ANSWER:
|
||||
React hooks are functions that let you use state and lifecycle features
|
||||
in functional components. The most common hooks are useState and useEffect...
|
||||
|
||||
SOURCES:
|
||||
1. hooks (hooks.md)
|
||||
Preview: # React Hooks\n\nHooks are a way to reuse stateful logic...
|
||||
|
||||
2. api (api_reference.md)
|
||||
Preview: ## useState\n\nReturns a stateful value and a function...
|
||||
```
|
||||
|
||||
## Files in This Example
|
||||
|
||||
- `quickstart.py` - Complete working example
|
||||
- `README.md` - This file
|
||||
- `requirements.txt` - Python dependencies
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Customize** - Modify the example for your use case
|
||||
2. **Experiment** - Try different vector stores (FAISS, Pinecone)
|
||||
3. **Extend** - Add conversational memory, filters, hybrid search
|
||||
4. **Deploy** - Build a production RAG application
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**"Documents not found"**
|
||||
- Make sure you've generated documents first
|
||||
- Check the path in `quickstart.py` matches your output location
|
||||
|
||||
**"OpenAI API key not found"**
|
||||
- Set environment variable: `export OPENAI_API_KEY=sk-...`
|
||||
|
||||
**"Module not found"**
|
||||
- Install dependencies: `pip install -r requirements.txt`
|
||||
|
||||
## Related Examples
|
||||
|
||||
- [LlamaIndex RAG Pipeline](../llama-index-query-engine/)
|
||||
- [Pinecone Integration](../pinecone-upsert/)
|
||||
|
||||
---
|
||||
|
||||
**Need help?** [GitHub Discussions](https://github.com/yusufkaraaslan/Skill_Seekers/discussions)
|
||||
209
examples/langchain-rag-pipeline/quickstart.py
Normal file
209
examples/langchain-rag-pipeline/quickstart.py
Normal file
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
LangChain RAG Pipeline Quickstart
|
||||
|
||||
This example shows how to:
|
||||
1. Load Skill Seekers documents
|
||||
2. Create a Chroma vector store
|
||||
3. Build a RAG query engine
|
||||
4. Query the documentation
|
||||
|
||||
Requirements:
|
||||
pip install langchain langchain-community langchain-openai chromadb openai
|
||||
|
||||
Environment:
|
||||
export OPENAI_API_KEY=sk-...
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from langchain.schema import Document
|
||||
from langchain.vectorstores import Chroma
|
||||
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
|
||||
from langchain.chains import RetrievalQA
|
||||
|
||||
|
||||
def load_documents(json_path: str) -> list[Document]:
|
||||
"""
|
||||
Load LangChain Documents from Skill Seekers JSON output.
|
||||
|
||||
Args:
|
||||
json_path: Path to skill-seekers generated JSON file
|
||||
|
||||
Returns:
|
||||
List of LangChain Document objects
|
||||
"""
|
||||
with open(json_path) as f:
|
||||
docs_data = json.load(f)
|
||||
|
||||
documents = [
|
||||
Document(
|
||||
page_content=doc["page_content"],
|
||||
metadata=doc["metadata"]
|
||||
)
|
||||
for doc in docs_data
|
||||
]
|
||||
|
||||
print(f"✅ Loaded {len(documents)} documents")
|
||||
print(f" Categories: {set(doc.metadata['category'] for doc in documents)}")
|
||||
|
||||
return documents
|
||||
|
||||
|
||||
def create_vector_store(documents: list[Document], persist_dir: str = "./chroma_db") -> Chroma:
|
||||
"""
|
||||
Create a persistent Chroma vector store.
|
||||
|
||||
Args:
|
||||
documents: List of LangChain Documents
|
||||
persist_dir: Directory to persist the vector store
|
||||
|
||||
Returns:
|
||||
Chroma vector store instance
|
||||
"""
|
||||
embeddings = OpenAIEmbeddings()
|
||||
|
||||
vectorstore = Chroma.from_documents(
|
||||
documents,
|
||||
embeddings,
|
||||
persist_directory=persist_dir
|
||||
)
|
||||
|
||||
print(f"✅ Vector store created at: {persist_dir}")
|
||||
print(f" Documents indexed: {len(documents)}")
|
||||
|
||||
return vectorstore
|
||||
|
||||
|
||||
def create_qa_chain(vectorstore: Chroma) -> RetrievalQA:
|
||||
"""
|
||||
Create a RAG question-answering chain.
|
||||
|
||||
Args:
|
||||
vectorstore: Chroma vector store
|
||||
|
||||
Returns:
|
||||
RetrievalQA chain
|
||||
"""
|
||||
retriever = vectorstore.as_retriever(
|
||||
search_type="similarity",
|
||||
search_kwargs={"k": 3} # Return top 3 most relevant docs
|
||||
)
|
||||
|
||||
llm = ChatOpenAI(model_name="gpt-4", temperature=0)
|
||||
|
||||
qa_chain = RetrievalQA.from_chain_type(
|
||||
llm=llm,
|
||||
chain_type="stuff",
|
||||
retriever=retriever,
|
||||
return_source_documents=True
|
||||
)
|
||||
|
||||
print("✅ QA chain created")
|
||||
|
||||
return qa_chain
|
||||
|
||||
|
||||
def query_documentation(qa_chain: RetrievalQA, query: str) -> None:
|
||||
"""
|
||||
Query the documentation and print results.
|
||||
|
||||
Args:
|
||||
qa_chain: RetrievalQA chain
|
||||
query: Question to ask
|
||||
"""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"QUERY: {query}")
|
||||
print(f"{'='*60}\n")
|
||||
|
||||
result = qa_chain({"query": query})
|
||||
|
||||
print(f"ANSWER:\n{result['result']}\n")
|
||||
|
||||
print("SOURCES:")
|
||||
for i, doc in enumerate(result['source_documents'], 1):
|
||||
category = doc.metadata.get('category', 'unknown')
|
||||
file_name = doc.metadata.get('file', 'unknown')
|
||||
print(f" {i}. {category} ({file_name})")
|
||||
print(f" Preview: {doc.page_content[:100]}...\n")
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main execution flow.
|
||||
"""
|
||||
print("="*60)
|
||||
print("LANGCHAIN RAG PIPELINE QUICKSTART")
|
||||
print("="*60)
|
||||
print()
|
||||
|
||||
# Configuration
|
||||
DOCS_PATH = "../../output/react-langchain.json" # Adjust path as needed
|
||||
CHROMA_DIR = "./chroma_db"
|
||||
|
||||
# Check if documents exist
|
||||
if not Path(DOCS_PATH).exists():
|
||||
print(f"❌ Documents not found at: {DOCS_PATH}")
|
||||
print("\nGenerate documents first:")
|
||||
print(" 1. skill-seekers scrape --config configs/react.json")
|
||||
print(" 2. skill-seekers package output/react --target langchain")
|
||||
return
|
||||
|
||||
# Step 1: Load documents
|
||||
print("Step 1: Loading documents...")
|
||||
documents = load_documents(DOCS_PATH)
|
||||
print()
|
||||
|
||||
# Step 2: Create vector store
|
||||
print("Step 2: Creating vector store...")
|
||||
vectorstore = create_vector_store(documents, CHROMA_DIR)
|
||||
print()
|
||||
|
||||
# Step 3: Create QA chain
|
||||
print("Step 3: Creating QA chain...")
|
||||
qa_chain = create_qa_chain(vectorstore)
|
||||
print()
|
||||
|
||||
# Step 4: Query examples
|
||||
print("Step 4: Running example queries...")
|
||||
|
||||
example_queries = [
|
||||
"How do I use React hooks?",
|
||||
"What is the difference between useState and useEffect?",
|
||||
"How do I handle forms in React?",
|
||||
]
|
||||
|
||||
for query in example_queries:
|
||||
query_documentation(qa_chain, query)
|
||||
|
||||
# Interactive mode
|
||||
print("\n" + "="*60)
|
||||
print("INTERACTIVE MODE")
|
||||
print("="*60)
|
||||
print("Enter your questions (type 'quit' to exit)\n")
|
||||
|
||||
while True:
|
||||
user_query = input("You: ").strip()
|
||||
|
||||
if user_query.lower() in ['quit', 'exit', 'q']:
|
||||
print("\n👋 Goodbye!")
|
||||
break
|
||||
|
||||
if not user_query:
|
||||
continue
|
||||
|
||||
query_documentation(qa_chain, user_query)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n👋 Interrupted. Goodbye!")
|
||||
except Exception as e:
|
||||
print(f"\n❌ Error: {e}")
|
||||
print("\nMake sure you have:")
|
||||
print(" 1. Set OPENAI_API_KEY environment variable")
|
||||
print(" 2. Installed required packages:")
|
||||
print(" pip install langchain langchain-community langchain-openai chromadb openai")
|
||||
17
examples/langchain-rag-pipeline/requirements.txt
Normal file
17
examples/langchain-rag-pipeline/requirements.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
# LangChain RAG Pipeline Requirements
|
||||
|
||||
# Core LangChain
|
||||
langchain>=0.1.0
|
||||
langchain-community>=0.0.20
|
||||
langchain-openai>=0.0.5
|
||||
|
||||
# Vector Store
|
||||
chromadb>=0.4.22
|
||||
|
||||
# Embeddings & LLM
|
||||
openai>=1.12.0
|
||||
|
||||
# Optional: Other vector stores
|
||||
# faiss-cpu>=1.7.4 # For FAISS
|
||||
# pinecone-client>=3.0.0 # For Pinecone
|
||||
# weaviate-client>=3.25.0 # For Weaviate
|
||||
Reference in New Issue
Block a user