ask.py  by pengfeng

Python script for search-extract-summarize flow, like an AI search engine

created 9 months ago
269 stars

Top 96.2% on sourcepulse

GitHubView on GitHub
Project Summary

This Python program implements a search-extract-summarize pipeline, mimicking AI search engines like Perplexity. It's designed for developers and researchers to experiment with LLM-based search functionalities, offering flexibility in LLM endpoints, search parameters, and output formats, with both CLI and GradIO UI options.

How It Works

The core functionality follows a search-extract-summarize flow. Given a query, it searches Google (or a specified list of URLs), extracts text content from results, chunks it, and stores it in a vector database. It then performs a hybrid search (vector and BM25) to retrieve relevant chunks, optionally re-ranks them, and uses these as context for an LLM to generate an answer. This modular approach allows for customization of search scope (e.g., date restrictions, target sites) and LLM output (e.g., language, length).

Quick Start & Requirements

  • Install: pip install -r requirements.txt
  • Prerequisites: Python 3.10+, requirements.txt dependencies. API keys for search (Google) and LLM (OpenAI default) are required, configurable via .env file or environment variables.
  • Usage:
    • CLI: python ask.py -c -q "Your query"
    • GradIO UI: python ask.py
  • Docs: HuggingFace Spaces Demo

Highlighted Details

  • Supports custom LLM endpoints (e.g., local Ollama, DeepSeek) and embedding models.
  • Offers local file querying via the data directory.
  • Integrates GradIO for a web UI and deployment to HuggingFace Spaces.
  • Allows fine-grained control over search (date, site) and LLM output (language, length).
  • Includes an extract output mode with Pydantic schema support for structured data extraction.

Maintenance & Community

The project is actively updated, with recent additions including support for separate API endpoints for inference and embedding, .env file switching, and Ollama integration. Community interaction is encouraged via the project's GitHub repository.

Licensing & Compatibility

  • License: MIT
  • Compatibility: The MIT license permits commercial use and linking with closed-source projects.

Limitations & Caveats

The project explicitly states that performance and scalability are not primary concerns, focusing instead on illustrating core AI search engine concepts. A more robust, production-ready toolset is planned for future release.

Health Check
Last commit

1 month ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
11 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems) and Elie Bursztein Elie Bursztein(Cybersecurity Lead at Google DeepMind).

LightRAG by HKUDS

1.0%
19k
RAG framework for fast, simple retrieval-augmented generation
created 10 months ago
updated 21 hours ago
Feedback? Help us improve.