Skip to content

Conversation

@SumonRayy
Copy link

Description

This PR adds support for the Ollama LLM client as one of the supported language models in NeoBase. This enhancement enables users to run NeoBase queries locally without requiring external API keys, supporting offline and secure environments.

Changes

  • Added Ollama-specific prompts and response schemas for multiple database types:
    • PostgreSQL
    • MySQL
    • YugabyteDB
    • Clickhouse
    • MongoDB
  • Each database-specific prompt includes:
    • Schema compliance rules
    • Safety measures for critical operations
    • Query optimization guidelines
    • Response formatting requirements
    • Database-specific optimizations
  • Added comprehensive response schemas for each database type
  • Implemented proper pagination handling for all database types
  • Added support for rollback queries and dependent queries

Database-Specific Optimizations

Clickhouse

  • Columnar storage capabilities
  • Appropriate table engines (MergeTree, ReplacingMergeTree)
  • Materialized views for common queries
  • Proper partitioning and sorting keys
  • Distributed query optimization
  • Appropriate data types (e.g., LowCardinality for strings)
  • Pre-aggregation for analytics
  • Sampling for large datasets
  • Parallel processing capabilities

YugabyteDB

  • Distributed SQL capabilities
  • Table partitioning strategies
  • Colocation for related tables
  • Proper index types (hash, range)
  • Distributed transaction optimization
  • Appropriate consistency levels
  • Geo-distribution considerations

MongoDB

  • Proper index types (single, compound, text)
  • Aggregation framework optimization
  • Read/write concerns
  • Sharding considerations
  • Data modeling patterns
  • Document size and structure optimization

Benefits

  • Enables local, fast, and privacy-first way to run large language models
  • Supports offline and secure environments
  • Offers faster iteration for local development and testing
  • Allows users to use custom trained or hosted Ollama LLMs
  • Maintains data security through self-hosting option

Testing

  • Tested with PostgreSQL database
  • Tested with MySQL database
  • Tested with YugabyteDB database
  • Tested with Clickhouse database (I have no idea about this db if someone can test it that would be helpful)
  • Tested with MongoDB database (MongoDB connection keeps failing)
  • Verified pagination functionality
  • Verified rollback query generation
  • Verified response schema compliance

Related Issues

Resolves #43

Security Considerations

  • No API keys required
  • All processing done locally
  • Secure credentialing maintained
  • Self-hosting option supported

SumonRayy added 5 commits May 27, 2025 17:03
This commit introduces support for the Ollama LLM provider, including configuration options in the environment variables, constants, and the LLM manager. The Ollama client is implemented to handle requests and responses, ensuring proper JSON formatting and schema compliance. Additionally, the necessary constants and prompts for Ollama are defined to facilitate its integration with the existing system.
This commit enhances the MySQL prompt with detailed instructions and rules for generating SQL queries, ensuring compliance with schema requirements and improving user interaction through structured JSON responses.
This commit enhances the Ollama prompts by adding support for YugabyteDB and MySQL, including specific response schemas and optimization guidelines tailored for each database type. The changes improve the assistant's ability to generate accurate and efficient SQL queries while ensuring compliance with the defined schema.
This commit adds support for Clickhouse and MongoDB in the Ollama prompts, including specific response schemas and detailed guidelines for generating SQL and MongoDB queries. The enhancements improve the assistant's ability to provide accurate and efficient responses while ensuring compliance with the defined schema for both database types.
This commit updates the README.md to accurately reflect the current support status for the Ollama LLM client, removing it from the "Planned to be supported LLM Clients" section and adding it to the "Supported LLM Clients" section. Additionally, a minor grammatical correction was made in the contributing guidelines.
@vercel
Copy link

vercel bot commented May 27, 2025

@SumonRayy is attempting to deploy a commit to the Aurivance Technologies Team on Vercel.

A member of the Team first needs to authorize it.

@bhaskarblur
Copy link
Owner

bhaskarblur commented May 27, 2025

Hi @SumonRayy
Thanks for working on this as this is super beneficial for NeoBase offline users.

I will review this soon.

…and YugabyteDB system prompts

This commit extends the Ollama prompt functionality by adding support for PostgreSQL, MySQL, Clickhouse, MongoDB, and YugabyteDB. Each database type now has a corresponding prompt, enhancing the assistant's ability to generate accurate and efficient SQL queries while ensuring compliance with the defined schemas.
ollamaMessages := make([]OllamaMessage, 0)

// Add system message first with explicit JSON formatting instruction
systemPrompt = systemPrompt + "\n\nCRITICAL INSTRUCTION: You MUST respond with ONLY a valid JSON object that strictly follows the schema above. Your response MUST include all required fields: assistantMessage, queries (array), and optionally actionButtons. Do not include any other text, markdown, or HTML in your response. Your entire response must be a single JSON object starting with { and ending with }. Do not include any explanations or additional text."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inject this hardcode prompt from constants of ollama only rather than writing here.

// Add a final instruction message to reinforce JSON formatting
ollamaMessages = append(ollamaMessages, OllamaMessage{
Role: "system",
Content: "Remember: Your response must be ONLY a valid JSON object with all required fields: assistantMessage, queries (array), and optionally actionButtons. Do not include any other text or explanations.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment, pick from constants

Stream: false,
Options: OllamaOptions{
Temperature: c.temperature,
NumPredict: c.maxCompletionTokens,
Copy link
Owner

@bhaskarblur bhaskarblur May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is NumPredict = maxCompletionTokens?
Is this correct?

for _, q := range queries {
if queryStr, ok := q.(string); ok {
queryInfos = append(queryInfos, constants.QueryInfo{
Query: queryStr,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hardcoded these values and not from llm response? Also many properties are missing in this append.

@bhaskarblur
Copy link
Owner

Please also update the docker-compose folder files too like env, docker compose files for these changes configs.

@bhaskarblur
Copy link
Owner

Hi @SumonRayy Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Ollama LLM Client

2 participants