Skip to content

saurabhbansal123/NeoQueryAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔍 NeoQueryAI : Neo4j and FAISS-Powered AI-driven GraphQL query builder

📌 Project Overview

This project automates GraphQL schema processing and natural language query-to-GraphQL generation by:

  • Fetching GraphQL schema via introspection.
  • Storing the schema in a Neo4j graph database.
  • Extracting & indexing types, fields, queries, and mutations.
  • Using LLM-based expansion to add synonyms & enrich search capabilities.
  • Building FAISS indexes for efficient similarity search.
  • Processing user queries in natural language using LLM + FAISS + Neo4j traversal.
  • Generating optimized GraphQL queries dynamically.

🚀 Features

GraphQL Schema Extraction – Pulls schema via introspection & stores in Neo4j
FAISS Indexing – Creates FAISS indexes for types, fields, queries, and mutations
LLM-Based Enrichment – Uses GPT-4 Turbo to expand schema with synonyms & context
Smart FAISS Search – Matches user queries to schema fields with high accuracy
Query Path Selection – Finds optimal queries & traversal paths in Neo4j
GraphQL Query Generation – Converts results into executable GraphQL queries
Minimal Query Optimization – Ensures efficient & minimal query selection


🛠 Installation

1️⃣ Clone the Repository

git clone https://github.com/saurabhbansal123/NeoQueryAI.git
cd NeoQueryAI

2️⃣ Install Dependencies

Ensure Python 3.8+ is installed, then run:

pip install -r requirements.txt

3️⃣ Configure Environment

Use the example configuration:

Edit config/config.ini and set:

  • GraphQL API Endpoint & Access Token
  • Neo4j Credentials
  • OpenAI API Key

⚙️ Configuration

Update config/config.ini:

[graphql]
graphql_api_url = https://your-graphql-endpoint.com/graphql
graphql_access_token = your_graphql_api_key

[neo4j]
uri = bolt://localhost:7687
username = neo4j
password = your_neo4j_password

[openai]
openai_api_key = your_openai_api_key

📌 Workflow & Execution

1️⃣ Fetch & Store GraphQL Schema

Run:

python Process_data.py

This will:

  • Fetch schema via introspection
  • Store schema as a graph in Neo4j
  • Process schema into a structured vocabulary
  • Build FAISS indexes

2️⃣ Process User Queries & Generate GraphQL

Run:

python GenerateGraphQL.py

This will:

  • Use LLM to extract structured fields
  • Search for matching GraphQL fields in FAISS
  • Identify queries from Neo4j schema
  • Optimize query selection & build GraphQL

🔍 How It Works

1️⃣ Schema Processing & Enrichment

  1. Extracts types, fields, queries, mutations from GraphQL API.
  2. Stores schema as a graph in Neo4j.
  3. Expands vocabulary with GPT-4 Turbo (synonyms & context).
  4. Indexes schema using FAISS for fast similarity search.

2️⃣ FAISS-Powered Query Processing

  1. User inputs a natural language query (e.g., "Fetch event details").
  2. LLM extracts relevant GraphQL fields, types, and queries.
  3. FAISS searches for best schema matches.
  4. Neo4j finds optimal queries & traversal paths.

3️⃣ Optimized GraphQL Generation

  1. Prioritizes minimal depth & efficient query selection.
  2. Builds GraphQL query dynamically.
  3. Returns ready-to-use GraphQL query.

🔥 Example: Generating a GraphQL Query

User Input

"Fetch event details along with attendees and their emails"

Extracted Entities & Fields

{
  "queries": ["Query.eventsConnection", "Query.attendeesConnection"],
  "fields": ["Event.id", "Event.name", "Attendee.firstName", "Attendee.email"]
}

Generated GraphQL Query

query {
  eventsConnection {
    nodes {
      id
      name
      attendees {
        nodes {
          firstName
          email
        }
      }
    }
  }
}

📜 License

This project is licensed under the Apache 2.0 License.

You may:

  • Use, modify, and distribute the software for any purpose.
  • Create derivative works and incorporate them into other projects.
  • Commercially use the software.

You must:

  • Provide proper attribution by crediting the original authors when using this work in derivative or redistributed projects.
  • Include a copy of this license in any distribution.
  • State any modifications you make to the original source code.
  • Not hold the original authors liable for any issues arising from the use of this software.

For full details, see: Apache 2.0 License.


🤝 Contributing

💡 Found a bug? Want to improve this? Contributions are welcome!

Some opportunity areas are already highlighted in the code with a TODO comment.

Steps to Contribute

  1. Fork the repository
  2. Create a new branch
    git checkout -b feature-branch
  3. Commit your changes
    git commit -m "Added new feature"
  4. Push your branch
    git push origin feature-branch
  5. Create a Pull Request (PR)

📧 Contact

For questions or collaboration:

About

Neo4j-powered AI-driven GraphQL query builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages