Skip to content

Latest commit

Β 

History

History
406 lines (338 loc) Β· 12.1 KB

File metadata and controls

406 lines (338 loc) Β· 12.1 KB

AI Search - Laravel + Vue 3 + TypeScript

A modern full-stack application combining Laravel backend with Vue 3 (TypeScript) frontend for semantic document search using TF-IDF and cosine similarity.

Features

  • πŸ” Semantic Search: TF-IDF-based search with cosine similarity scoring
  • οΏ½ Data Sources: Connect to external APIs, URLs, RSS feeds, and databases
  • οΏ½πŸ“Š User Dashboard: Interactive Vue 3 dashboard with TypeScript
  • πŸ—„οΈ SQLite Database: Lightweight database for document storage
  • 🌐 REST API: Complete API for searching and managing documents
  • 🐍 Python Integration: Enhanced AI search script with API support
  • 🎨 Modern UI: Beautiful, responsive interface with gradient designs
  • πŸ”„ Smart Caching: Configurable cache TTL with automatic background refresh
  • πŸ” API Authentication: Support for Bearer, API Key, Basic Auth, and OAuth2

Tech Stack

Backend

  • Laravel 10+
  • SQLite Database
  • PHP 8.1+

Frontend

  • Vue 3 with Composition API
  • TypeScript
  • Vite
  • Modern CSS with gradients and animations

AI Search

  • Python 3.8+
  • scikit-learn (TF-IDF vectorization)
  • NumPy (numerical operations)

New: Data Sources Feature πŸ”Œ

Search across multiple data sources simultaneously!

The Data Sources feature allows you to integrate external data into your AI search:

Supported Source Types

  1. Database πŸ—„οΈ - Execute SQL queries against any database
  2. URL/File 🌐 - Fetch JSON, XML, CSV, RSS feeds, or plain text
  3. API πŸ”Œ - Connect to REST APIs with authentication

Quick Start

# Seed sample data sources
php artisan db:seed --class=DataSourceSeeder

# Refresh all data sources
php artisan data-sources:refresh --all

# View in browser
# Navigate to: /data-sources

Example Uses

  • Fetch product catalogs from external APIs
  • Import RSS news feeds
  • Query remote databases
  • Aggregate data from multiple sources
  • Cache frequently accessed external data

See docs/DATA_SOURCES_GUIDE.md for detailed documentation.

Installation

Prerequisites

  • PHP >= 8.1
  • Composer
  • Node.js >= 18
  • npm or yarn
  • Python 3.8+
  • pip

Setup Steps

  1. Clone the repository

    git clone https://github.com/net-shell/kepler.git
  2. Install PHP dependencies

    composer install
  3. Install Node dependencies

    npm install
  4. Install Python dependencies

    pip3 install scikit-learn numpy dotenv
  5. Set up environment

    cp .env.example .env
    python3 -m venv scripts/venv
    php artisan key:generate
  6. Create SQLite database

    touch database/database.sqlite
  7. Run migrations

    php artisan migrate
  8. Build frontend assets

    npm run build
    # Or for development with hot reload:
    npm run dev
  9. Start the Laravel server

    php artisan serve
  10. Access the application Open your browser to: http://localhost:8000

API Endpoints

Search Endpoints

  • POST /api/search - Search documents

    {
      "query": "your search query",
      "limit": 5
    }
  • GET /api/search/stats - Get search statistics

Data Management Endpoints

  • GET /api/data - List all documents (paginated)

  • POST /api/data - Create a new document

    {
      "title": "Document Title",
      "body": "Document content",
      "tags": ["tag1", "tag2"],
      "metadata": {"key": "value"}
    }
  • POST /api/data/batch - Batch create documents

  • GET /api/data/{id} - Get a specific document

  • PUT /api/data/{id} - Update a document

  • DELETE /api/data/{id} - Delete a document

Python Script Usage

Interactive Demo Mode

python3 scripts/ai_search_api.py

API Mode (via Laravel)

The script is automatically called by Laravel when performing searches.

Standalone API Mode

echo '{"data": [...], "query": "search term", "limit": 5}' | python3 scripts/ai_search_api.py

Project Structure

kepler/
β”œβ”€β”€ ai/
β”‚   └── ai_search.py                    # AI search implementation
β”‚
β”œβ”€β”€ www/                                # Main Laravel application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ Actions/
β”‚   β”‚   β”‚   └── Fortify/               # Authentication actions
β”‚   β”‚   β”œβ”€β”€ Console/
β”‚   β”‚   β”‚   β”œβ”€β”€ Commands/
β”‚   β”‚   β”‚   β”‚   └── SearchStats.php    # Search statistics command
β”‚   β”‚   β”‚   └── Kernel.php
β”‚   β”‚   β”œβ”€β”€ Exceptions/
β”‚   β”‚   β”‚   └── Handler.php
β”‚   β”‚   β”œβ”€β”€ Http/
β”‚   β”‚   β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Controller.php
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DataController.php         # Document CRUD & bulk upload
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SearchController.php       # AI search API
β”‚   β”‚   β”‚   β”‚   └── Settings/                  # User settings controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ Middleware/                    # HTTP middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ Requests/
β”‚   β”‚   β”‚   β”‚   └── Settings/                  # Form requests
β”‚   β”‚   β”‚   └── Kernel.php
β”‚   β”‚   β”œβ”€β”€ Models/
β”‚   β”‚   β”‚   β”œβ”€β”€ Document.php           # Document model with folder path
β”‚   β”‚   β”‚   └── User.php               # User model with 2FA
β”‚   β”‚   β”œβ”€β”€ Providers/
β”‚   β”‚   β”‚   β”œβ”€β”€ AppServiceProvider.php
β”‚   β”‚   β”‚   β”œβ”€β”€ FortifyServiceProvider.php
β”‚   β”‚   β”‚   └── RouteServiceProvider.php
β”‚   β”‚   └── Services/
β”‚   β”‚       └── FileProcessingService.php      # File parsing service
β”‚   β”‚
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ aisearch.php               # AI search configuration
β”‚   β”‚   β”œβ”€β”€ app.php
β”‚   β”‚   β”œβ”€β”€ auth.php
β”‚   β”‚   β”œβ”€β”€ database.php
β”‚   β”‚   β”œβ”€β”€ fortify.php
β”‚   β”‚   └── inertia.php
β”‚   β”‚
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   β”œβ”€β”€ migrations/
β”‚   β”‚   β”‚   β”œβ”€β”€ create_users_table.php
β”‚   β”‚   β”‚   β”œβ”€β”€ create_documents_table.php
β”‚   β”‚   β”‚   β”œβ”€β”€ add_two_factor_columns_to_users_table.php
β”‚   β”‚   β”‚   └── add_path_to_documents_table.php
β”‚   β”‚   β”œβ”€β”€ factories/
β”‚   β”‚   └── seeders/
β”‚   β”‚
β”‚   β”œβ”€β”€ docs/
β”‚   β”‚   β”œβ”€β”€ ARCHITECTURE.md            # System architecture
β”‚   β”‚   β”œβ”€β”€ BULK_UPLOAD_GUIDE.md       # Bulk upload documentation
β”‚   β”‚   β”œβ”€β”€ BULK_UPLOAD_QUICKSTART.md  # Quick start guide
β”‚   β”‚   β”œβ”€β”€ DOCUMENTATION_INDEX.md     # Documentation index
β”‚   β”‚   β”œβ”€β”€ FOLDER_TREE_FEATURE.md     # Folder tree documentation
β”‚   β”‚   β”œβ”€β”€ INSTALLATION_GUIDE.md      # Installation guide
β”‚   β”‚   β”œβ”€β”€ PROJECT_SUMMARY.md         # Project summary
β”‚   β”‚   β”œβ”€β”€ QUICKSTART.md              # Quick start
β”‚   β”‚   β”œβ”€β”€ README_BULK_UPLOAD.md      # Bulk upload README
β”‚   β”‚   └── VISUAL_GUIDE.md            # Visual guide
β”‚   β”‚
β”‚   β”œβ”€β”€ resources/
β”‚   β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”‚   └── app.css
β”‚   β”‚   β”œβ”€β”€ js/
β”‚   β”‚   β”‚   β”œβ”€β”€ actions/               # Auto-generated Wayfinder actions
β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AlertError.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppContent.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppHeader.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppLogo.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppShell.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppSidebar.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BulkUploadComponent.vue    # Bulk upload interface
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.vue              # Main dashboard
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DataFeedComponent.vue      # Data input form
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DocumentCard.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DocumentList.vue           # Document list
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FolderTree.vue             # Folder navigation
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SearchComponent.vue        # Search interface
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TwoFactorSetupModal.vue    # 2FA setup
β”‚   β”‚   β”‚   β”‚   └── ui/                        # shadcn/ui components
β”‚   β”‚   β”‚   β”œβ”€β”€ composables/           # Vue composables
β”‚   β”‚   β”‚   β”œβ”€β”€ layouts/               # Page layouts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AppLayout.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AuthLayout.vue
β”‚   β”‚   β”‚   β”‚   └── settings/
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”‚   └── utils.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth/              # Authentication pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ settings/          # User settings pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.vue
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DocumentShow.vue
β”‚   β”‚   β”‚   β”‚   └── Welcome.vue
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/                # Wayfinder routes
β”‚   β”‚   β”‚   β”œβ”€β”€ types/                 # TypeScript definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ wayfinder/             # Wayfinder config
β”‚   β”‚   β”‚   β”œβ”€β”€ app.ts                 # Vue app entry
β”‚   β”‚   β”‚   └── ssr.ts                 # SSR entry
β”‚   β”‚   └── views/
β”‚   β”‚       └── app.blade.php
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ api.php                    # API routes
β”‚   β”‚   β”œβ”€β”€ console.php                # Console routes
β”‚   β”‚   β”œβ”€β”€ settings.php               # Settings routes
β”‚   β”‚   └── web.php                    # Web routes
β”‚   β”‚
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── ai_search_api.py           # Python AI search script
β”‚   β”‚
β”‚   β”œβ”€β”€ storage/
β”‚   β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”‚   └── uploads/               # Uploaded files
β”‚   β”‚   β”œβ”€β”€ framework/
β”‚   β”‚   └── logs/
β”‚   β”‚
β”‚   β”œβ”€β”€ tests/
β”‚   β”‚   β”œβ”€β”€ Feature/
β”‚   β”‚   β”œβ”€β”€ Unit/
β”‚   β”‚   └── Pest.php
β”‚   β”‚
β”‚   β”œβ”€β”€ composer.json                  # PHP dependencies
β”‚   β”œβ”€β”€ package.json                   # Node dependencies
β”‚   β”œβ”€β”€ vite.config.ts                 # Vite configuration
β”‚   β”œβ”€β”€ tsconfig.json                  # TypeScript configuration
β”‚   β”œβ”€β”€ components.json                # shadcn/ui config
β”‚   └── README.md                      # This file

Development

Run in development mode

# Terminal 1: Laravel server
php artisan serve

# Terminal 2: Vite dev server (hot reload)
npm run dev

Build for production

npm run build

Test the Python script

python3 scripts/ai_search_api.py

Features Explained

1. Dashboard Tab

  • View total document count
  • Quick statistics overview

2. Search Tab

  • Enter search queries
  • Adjust result limit
  • View ranked results with scores
  • See document tags and metadata

3. Add Data Tab

  • Create new documents
  • Add tags
  • Add custom metadata
  • Batch operations support

4. Documents Tab

  • Browse all documents
  • Pagination support
  • Delete documents
  • View creation dates

Customization

Modify Search Algorithm

Edit scripts/ai_search_api.py to adjust:

  • TF-IDF parameters
  • Scoring weights (title, body, tags)
  • n-gram ranges
  • Minimum score thresholds

Update UI Theme

Edit resources/js/style.css and component styles to change:

  • Color schemes
  • Gradients
  • Animations
  • Layout

Add New Features

  1. Create new Vue components in resources/js/components/
  2. Add new API routes in routes/api.php
  3. Create corresponding controllers in app/Http/Controllers/

Troubleshooting

Python script not found

  • Ensure Python 3 is installed and in PATH
  • Verify script path in SearchController.php

Database errors

  • Check SQLite database exists: database/database.sqlite
  • Run migrations: php artisan migrate

Frontend not loading

  • Build assets: npm run build
  • Check Vite is running: npm run dev
  • Clear cache: php artisan cache:clear

License

This project is open-source and available for educational purposes.

Contributing

Feel free to submit issues and enhancement requests!