A complete decentralized Retrieval-Augmented Generation (RAG) system combining Walrus storage, Sui blockchain, and AI to create a trustless, permanent document storage and intelligent querying platform.
This project demonstrates a fully functional decentralized RAG system where:
- π€ Users upload documents to Walrus (decentralized storage)
- βοΈ Document ownership is recorded as NFTs on Sui blockchain
- π€ AI-powered querying using OpenAI + LangChain + ChromaDB
- π Wallet-based authentication and access control
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Frontend β β Backend β β Walrus β
β (React) βββββββΆβ (FastAPI) βββββββΆβ Storage β
β β β β β β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β β
β β
βΌ βΌ
βββββββββββββββ ββββββββββββββββ
β Sui Wallet β β Sui Blockchainβ
β β β (pysui) β
βββββββββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββ
β Document β
β Registry β
β (Move) β
ββββββββββββββββ
β
βΌ
ββββββββββββββββ
β RAG β
β (LangChain) β
β (ChromaDB) β
ββββββββββββββββ
- β Document Upload: Upload PDFs, text files, and more to Walrus
- β NFT Minting: Automatic NFT creation on Sui for each document
- β AI Querying: Ask questions about your documents with AI-powered answers
- β Source Citations: Get exact references from your documents
- β Wallet Integration: Connect with Sui wallets for authentication
- β Access Control: Private and public document settings
- π Decentralized Storage: Documents stored on Walrus (no central server)
- βοΈ Blockchain Verification: Ownership tracked on Sui blockchain
- π― Vector Search: Efficient similarity search with ChromaDB
- π§ RAG Pipeline: LangChain-powered retrieval and generation
- π Secure: Wallet-based authentication
- FastAPI: High-performance Python web framework
- pysui: Official Python SDK for Sui blockchain
- LangChain: RAG orchestration framework
- ChromaDB: Vector database for embeddings
- OpenAI: GPT models for text generation
- httpx: Async HTTP client for Walrus
- React: UI framework
- Vite: Build tool and dev server
- @mysten/dapp-kit: Sui wallet integration
- Axios: HTTP client
- Sui Move: Smart contract language
- Walrus: Decentralized blob storage
- Sui Network: Layer 1 blockchain
- Python 3.8+
- Node.js 16+
- Sui CLI (for contract deployment)
- OpenAI API key
- Clone the repository
git clone <repository-url>
cd rag-python- Run setup script
chmod +x setup.sh
./setup.sh- Configure environment
# Edit .env file
cp .env.example .env
nano .envRequired configuration:
SUI_PACKAGE_ID=0x... # From contract deployment
SUI_NETWORK=testnet
OPENAI_API_KEY=sk-... # Your OpenAI API key
WALRUS_PUBLISHER_URL=https://publisher-devnet.walrus.space
WALRUS_AGGREGATOR_URL=https://aggregator-devnet.walrus.spacecd backend
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtcd frontend
npm installcd contracts
sui move build
sui client publish --gas-budget 100000000
# Save the Package ID to your .env filecd backend
source venv/bin/activate # On Windows: venv\Scripts\activate
python run.pyBackend will run on http://localhost:8000
cd frontend
npm run devFrontend will run on http://localhost:3000
Open your browser and navigate to http://localhost:3000
- Click "Connect Wallet" button
- Select your Sui wallet (Sui Wallet, Suiet, etc.)
- Approve the connection
- Click "Choose File" and select a document (PDF, TXT, etc.)
- Optionally check "Make document public"
- Click "Upload to Walrus & Sui"
- Wait for:
- β Upload to Walrus
- β NFT minting on Sui
- β RAG processing
- Type your question in the query box
- Click "Ask AI"
- View AI-generated answer with source citations
- View all your documents in the "My Documents" section
- Download documents
- See metadata (upload date, visibility, etc.)
POST /upload-document- Upload document to Walrus & SuiGET /documents/{wallet_address}- Get user's documentsGET /download/{blob_id}- Download document from Walrus
POST /query- Query documents with AI
GET /health- Health checkGET /- API information
The Sui Move smart contract (contracts/document_registry/sources/registry.move) provides:
Functions:
mint_document()- Create document NFTtransfer_document()- Transfer ownershipset_visibility()- Change public/private status
Events:
DocumentMinted- Emitted when document is createdDocumentTransferred- Emitted on ownership transferVisibilityChanged- Emitted when visibility changes
- Private Keys: Never commit private keys or mnemonics
- API Keys: Keep OpenAI API key secure
- Access Control: Document visibility is enforced on-chain
- Wallet Verification: All operations require wallet signature
cd backend
pytest tests/cd frontend
npm run test- Deploy to any Python-compatible hosting (AWS, GCP, Heroku)
- Set environment variables
- Use gunicorn or uvicorn in production
cd frontend
npm run build
# Deploy 'dist' folder to Vercel, Netlify, or any static hostcd contracts/document_registry
sui move build
sui client publish --gas-budget 100000000rag-python/
βββ backend/
β βββ app/
β β βββ main.py # FastAPI application
β β βββ config.py # Configuration
β β βββ models/
β β β βββ schemas.py # Pydantic models
β β βββ services/
β β βββ walrus_service.py # Walrus integration
β β βββ sui_service.py # Sui blockchain integration
β β βββ rag_service.py # RAG system
β βββ requirements.txt
β βββ run.py
βββ contracts/
β βββ document_registry/
β βββ Move.toml
β βββ sources/
β βββ registry.move # Smart contract
βββ frontend/
β βββ src/
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β β βββ config/
β β β βββ sui.js # Sui configuration
β β βββ components/
β β βββ DocumentUpload.jsx
β β βββ DocumentList.jsx
β β βββ QueryInterface.jsx
β βββ package.json
β βββ vite.config.js
βββ .env.example
βββ .gitignore
βββ setup.sh
βββ README.md
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
- Check Python version:
python --version(need 3.8+) - Verify all dependencies:
pip install -r requirements.txt - Check .env configuration
- Check Node version:
node --version(need 16+) - Clear node_modules:
rm -rf node_modules && npm install
- Check Sui CLI:
sui --version - Verify wallet has gas:
sui client gas - Check network configuration
- Install Sui Wallet browser extension
- Check network (devnet/testnet/mainnet)
- Try refreshing the page
- Sui Documentation
- Walrus Documentation
- LangChain Documentation
- FastAPI Documentation
- pysui Documentation
MIT License - see LICENSE file for details
- Built for the Walrus/Sui Hackathon
- Uses OpenAI GPT models
- Powered by Walrus decentralized storage
- Built on Sui blockchain
For questions or support, please open an issue on GitHub.
Built with β€οΈ using Walrus, Sui, and AI