Skip to main content

Advanced Gemini-powered search with better grounding and citation control

Project description

GroundCite - AI-Powered Query Analysis Library

Version Python License

GroundCite is a Python library for adding better grounding and valid Citation support when searching using Gemini with google grounding . It combines web search using Gemini with google grounding with context validation, and structured data parsing using multiple AI providers to deliver accurate and reliable answers to complex questions.

๐Ÿš€ Features

Core Capabilities

  • Graph-Based Pipeline: State-driven execution with automatic retry logic and error handling
  • Web Search Integration: Intelligent web search with site filtering and content aggregation
  • AI-Powered Validation: Optional content validation using advanced AI models
  • Structured Data Parsing: Extract structured data using custom JSON schemas
  • Comprehensive Logging: Detailed execution metrics and token usage tracking

Interface Options

  • Command Line Interface (CLI): Feature-rich CLI with rich text formatting
  • REST API: FastAPI-based web service for HTTP integration
  • Python Library: Direct integration into Python applications

Advanced Features

  • Retry Logic: Robust error handling with configurable retry mechanisms
  • Token Usage Tracking: Monitor AI service consumption and costs
  • Correlation Tracking: End-to-end request tracing and debugging
  • Configuration Management: Flexible settings with validation
  • Site Filtering: Include/exclude specific domains in search results

๐Ÿ“‹ Requirements

Key Dependencies

  • langgraph - Graph-based workflow orchestration
  • google-genai - Google Gemini AI integration
  • openai - OpenAI API integration
  • fastapi - REST API framework
  • click - CLI framework
  • rich - Enhanced terminal output
  • pydantic - Data validation and settings

๐Ÿ”ง Installation

From Source

git clone https://github.com/cennest/ground-cite.git
cd ground-cite/GroundCite
pip install -e .

Using pip (when published)

pip install gemini-groundcite

โšก Quick Start

1. Basic CLI Usage

# Simple query analysis
gemini-groundcite analyze -q "What are the latest developments in AI?" --gemini-key your_gemini_key

# With validation and parsing
gemini-groundcite analyze -q "Company X financials" --validate --parse --gemini-key your_gemini_key

# Using OpenAI provider
gemini-groundcite analyze -q "Market trends" --provider openai --openai-key your_key --gemini-key your_gemini_key

2. Python Library Usage

from gemini_groundcite.config.settings import AppSettings
from gemini_groundcite.core.agents import AIAgent

# Configure settings
settings = AppSettings()
settings.ANALYSIS_CONFIG.query = "What are quantum computing breakthroughs?"
settings.ANALYSIS_CONFIG.validate = True
settings.ANALYSIS_CONFIG.parse = True
settings.AI_CONFIG.gemini_ai_key_primary = "your_gemini_key"

# Initialize and run analysis
agent = AIAgent(settings=settings)
results = await agent.analyze_query()

print(f"Analysis completed: {results['completed']}")
print(f"Results: {results['final_content']}")

3. REST API Usage

# Start the API server
python -m gemini_groundcite.main

# Make analysis requests
curl -X POST "http://localhost:8000/api/v1/analyze" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Latest AI developments",
    "config": {"validate": true, "parse": true},
    "search_model_name": "gemini-2.5-flash",
    "api_keys": {"gemini": {"primary": "your_key"}}
  }'

๐Ÿ—๏ธ Architecture

GroundCite uses a sophisticated graph-based architecture that orchestrates multiple AI processing stages:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Entry Point   โ”‚
โ”‚                 โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚     CLI     โ”‚ โ”‚
โ”‚ โ”‚ Interface   โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                 โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚  REST API   โ”‚ โ”‚
โ”‚ โ”‚  (FastAPI)  โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                 โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ Python Lib  โ”‚ โ”‚
โ”‚ โ”‚   Direct    โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Agent      โ”‚
โ”‚  Orchestrator   โ”‚
โ”‚                 โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚    Graph    โ”‚ โ”‚
โ”‚ โ”‚  Executor   โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Graph-Based Pipeline                      โ”‚
โ”‚                                                              โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚ โ”‚Orchestrationโ”‚โ”€โ”€โ”€โ–ถโ”‚   Search    โ”‚โ”€โ”€โ”€โ–ถโ”‚Search Aggr. โ”‚       โ”‚
โ”‚ โ”‚    Node     โ”‚    โ”‚    Node     โ”‚    โ”‚    Node     โ”‚       โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚         โ”‚                                     โ”‚             โ”‚
โ”‚         โ”‚                                     โ–ผ             โ”‚
โ”‚         โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚         โ”‚              โ”‚ Validation  โ”‚โ—€โ”€โ”€โ”€โ”‚Valid. Aggr. โ”‚    โ”‚
โ”‚         โ”‚              โ”‚    Node     โ”‚    โ”‚    Node     โ”‚    โ”‚
โ”‚         โ”‚              โ”‚ (Optional)  โ”‚    โ”‚ (Optional)  โ”‚    โ”‚
โ”‚         โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚         โ”‚                     โ”‚                             โ”‚
โ”‚         โ”‚                     โ–ผ                             โ”‚
โ”‚         โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                      โ”‚
โ”‚         โ”‚              โ”‚   Parsing   โ”‚                      โ”‚
โ”‚         โ”‚              โ”‚    Node     โ”‚                      โ”‚
โ”‚         โ”‚              โ”‚ (Optional)  โ”‚                      โ”‚
โ”‚         โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚
โ”‚         โ”‚                     โ”‚                             โ”‚
โ”‚         โ–ผ                     โ–ผ                             โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚                             โ”‚
โ”‚ โ”‚     END     โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚ โ”‚  (Final)    โ”‚                                             โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

1. AI Agent (gemini_groundcite.core.agents.AIAgent)

  • Central orchestrator for query analysis
  • Manages configuration and pipeline execution

2. Graph Executor (gemini_groundcite.core.executors.GraphExecutor)

  • Implements the graph-based workflow using LangGraph
  • Manages state transitions and node execution
  • Handles concurrent operations and routing

3. Processing Nodes

  • Orchestration Node: Controls overall execution flow
  • Search Node: Performs web searches
  • Search Aggregator: Consolidates search results
  • Validation Node: AI-powered content validation
  • Validation Aggregator: Processes validation results
  • Parsing Node: Extracts structured data

4. AI Clients

  • Google Gemini - Primary AI provider
  • OpenAI - Alternative parsing provider

Data Flow

  1. Input: User query + configuration
  2. Search: Find relevant web content
  3. Validate: AI-powered content validation (if enabled)
  4. Parse: Extract structured data (if enabled)
  5. Output: Analysis results + metadata

Production Considerations

  • Use environment variables for API keys
  • Configure proper logging levels
  • Set up monitoring and alerting
  • Implement rate limiting
  • Use database for configuration storage
  • Set up load balancing for high traffic

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

# Clone the repository
git clone https://github.com/cennest/ground-cite.git
cd ground-cite/GroundCite

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ž Support

๐Ÿ† Acknowledgments

  • Built with LangGraph for workflow orchestration
  • Powered by Google Gemini and OpenAI APIs
  • CLI interface built with Click and Rich
  • Web API built with FastAPI

GroundCite - Empowering intelligent query analysis with AI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_groundcite-1.1.0.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_groundcite-1.1.0-py3-none-any.whl (74.0 kB view details)

Uploaded Python 3

File details

Details for the file gemini_groundcite-1.1.0.tar.gz.

File metadata

  • Download URL: gemini_groundcite-1.1.0.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for gemini_groundcite-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6dd991325324f353f0ff0cde402534d72fb1ecb1a83183d97a66e8e6767f8dee
MD5 c542bbb19ca92a7a2e7fb88a64445d99
BLAKE2b-256 deb19d2749febf12f5f2b3af539c166e4adf83bd7490e976f7cc16f1c383d20a

See more details on using hashes here.

File details

Details for the file gemini_groundcite-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_groundcite-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b0c9d896eb4dbf0276cec2a0eb1f3ffa5757bd42dcd5b5fcf840b1b0ba13f9
MD5 596c5700862ab3a2d20122ae7e4fcb30
BLAKE2b-256 0592626398f74d5fc9d9bd372c2671119a913824da64453860d40d6bdf936297

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page