LogoLogo
HomeNewsSupportVideos
  • Welcome
  • Wisej.NET
  • Concepts
    • Getting Started
    • General Concepts
    • Architecture
    • Extensibility
    • AI Providers
    • Vector Databases
    • Usage Metrics
    • Logging & Error Handling
  • Markup
  • Components
    • API
      • SmartAdapter
        • SmartAudioTTSAdapter
        • SmartAudioWhisperAdapter
        • SmartCalendarAdapter
        • SmartChartAdapter
        • SmartChartJS3Adapter
        • SmartChatBoxAdapter
        • SmartComboBoxAdapter
        • SmartCopilotAdapter
        • SmartDataEntryAdapter
        • SmartDocumentAdapter
        • SmartFullCalendarAdapter
        • SmartObjectAdapter
        • SmartPictureBoxAdapter
        • SmartQueryAdapter
        • SmartRealtimeAdapter
        • SmartReportAdapter
        • SmartTextBoxAdapter
        • SmartAdapter.ExtendsAttribute
        • SmartAdapter.FieldNameAttribute
        • SmartAdapter.FieldPromptAttribute
        • SmartAdapter.FieldRectangleAttribute
        • SmartAdapter.WorksWithAttribute
      • SmartEndpoint
        • AmazonBedrockEndpoint
        • AnthropicEndpoint
        • AzureAIEndpoint
        • CerebrasEndpoint
        • DeepSeekEndpoint
        • GoogleAIEndpoint
        • GroqCloudEndpoint
        • GroqCloudEndpointWhisper
        • HuggingFaceEndpoint
        • HuggingFaceJavaScriptEndpoint
        • LocalAIEndpoint
        • LocalAIEndpointImageGen
        • LocalAIEndpointTTS
        • LocalAIEndpointWhisper
        • NvidiaAIEndpoint
        • OllamaEndpoint
        • OpenAIEndpoint
        • OpenAIEndpointDallE
        • OpenAIEndpointRealtime
        • OpenAIEndpointTTS
        • OpenAIEndpointWhisper
        • SambaNovaEndpoint
        • SmartHttpEndpoint
        • TogetherAIEndpoint
        • XAIEndpoint
        • SmartEndpoint.Metrics
        • SmartEndpoint.Response
      • SmartExtensions
      • SmartHub
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartObject
      • SmartPrompt
        • SmartAgentPrompt
        • SmartParallelPrompt
        • SmartPrompt.Parameter
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
      • SmartRealtimeSession
      • SmartSession
        • SmartSession.ConvertParameterEventArgs
        • SmartSession.ConvertParameterEventHandler
        • SmartSession.ErrorEventArgs
        • SmartSession.ErrorEventHandler
        • SmartSession.InvokeToolEventArgs
        • SmartSession.InvokeToolEventHandler
        • SmartSession.Message
        • SmartSession.MessageCollection
        • SmartSession.MessageRole
        • SmartSession.MessagesEventArgs
        • SmartSession.MessagesEventHandler
        • SmartSession.TrimmingStrategy
      • SmartTool
        • SmartTool.IToolProvider
        • SmartTool.ToolAttribute
        • SmartTool.ToolContext
      • Markup
        • MarkupExtensions
      • Controls
        • UVLightOverlay
      • Embeddings
        • EmbeddedDocument
        • Embedding
        • Matches
        • Metadata
      • Helpers
        • ApiKeys
        • Markdown
        • TextTokenizer
      • Services
        • DefaultSessionTrimmingService
        • IDocumentConversionService
          • DefaultDocumentConversionService
        • IEmbeddingGenerationService
          • DefaultEmbeddingGenerationService
          • HuggingFaceEmbeddingGenerationService
        • IEmbeddingStorageService
          • AzureAISearchEmbeddingStorageService
          • ChromaEmbeddingStorageService
          • FileSystemEmbeddingStorageService
          • MemoryEmbeddingStorageService
          • PineconeEmbeddingStorageService
          • QdrantEmbeddingStorageService
        • IHttpClientService
          • DefaultHttpClientService
        • ILoggerService
          • DefaultLoggerService
        • IOCRService
          • DefaultOCRService
        • IRerankingService
          • DefaultRerankingService
          • LocalAIRerankingService
          • PineconeRerankingService
        • ISessionTrimmingService
          • DefaultSessionTrimmingService
        • ITextSplitterService
          • RecursiveCharacterTextSplitterService
          • TextSplitterServiceBase
        • ITokenizerService
          • DefaultTokenizerService
        • IWebSearchService
          • BingWebSearchService
          • BraveWebSearchService
          • GoogleWebSearchService
      • Tools
        • ArxivTools
        • ChartJS3Tools
        • DatabaseTools
        • DataTableFilterTools
        • DocumentSearchTools
        • DocumentTools
        • FullCalendarTools
        • IToolsContainer
        • MathTools
        • ToolsContainer
        • UtilityTools
        • WebSearchTools
    • Built-in Services
      • IOCRService
      • ILoggerService
      • ITextSplitterService
      • ITokenizerService
      • IHttpClientService
      • IWebSearchService
      • IRerankingService
      • ISessionTrimmingService
      • IDocumentConversionService
      • IEmbeddingStorageService
      • IEmbeddingGenerationService
    • Built-in SmartTools
      • ToolsContainer
      • MathTools
      • UtilityTools
      • DatabaseTools
      • DocumentTools
      • DocumentSearchTools
      • WebSearchTools
      • ChartJS3Tools
      • FullCalendarTools
    • Built-in SmartAdapters
      • SmartAdapter
      • SmartAudioTTSAdapter
      • SmartAudioWhisperAdapter
      • SmartCalendarAdapter
      • SmartChartAdapter
      • SmartChartJS3Adapter
      • SmartChatBoxAdapter
      • SmartComboBoxAdapter
      • SmartCopilotAdapter
      • SmartDataEntryAdapter
      • SmartDocumentAdapter
      • SmartFullCalendarAdapter
      • SmartObjectAdapter
      • SmartPictureBoxAdapter
      • SmartQueryAdapter
      • SmartRealtimeAdapter
      • SmartReportAdapter
      • SmartTextBoxAdapter
    • Configure Services
    • Using SmartHub
    • Using SmartTools
    • Using SmartPrompt
    • Using SmartSession
    • Using SmartRealTimeAdapter
    • UVLightOverlay Control
Powered by GitBook
On this page
  • Overview
  • Configuration
  • Properties
  • Query
  • ServerType
  • DataSource
  • Connection
  • Schema
  • SchemaTables
  • SQL
Export as PDF
  1. Components
  2. Built-in SmartAdapters

SmartQueryAdapter

PreviousSmartPictureBoxAdapterNextSmartRealtimeAdapter

Last updated 4 days ago

Overview

The SmartQueryAdapter acts as an intermediary layer between an AI model and a BindingSource (specified by the property).

Uses the string and table to construct and execute an statement, returning any data retrieved from the database.

Default prompt
#
# SmartQueryAdapter
#
[SmartQueryAdapter.Prompt]
You are a skilled SQL programmer.
Your job is to generate a valid SQL statement for the database "{{database-name}}" from the user’s question.

## Instructions:
- Use only the tables defined in the Database Schema
- The generated SQL statement MUST be valid for "{{server-type}}"
- Define column aliases within quotes, with proper casing and with a space in between words
- Output only the SQL statement without any text before or after
- Enclose column names in []

```Database Schema
{{database-schema}}
```

Configuration

[WorksWith(typeof(SmartHttpEndpoint))]

Properties

Query

The Query property is used to specify the query string that will be sent to the AI model for generating an SQL statement. For example, if you set this.adapter.Query = "Total sales in Canada for the past 5 years", Wisej.AI sends this natural language query to the AI model, which then generates a valid SQL statement based on the request. The generated SQL statement is returned in the SQL property.

Additionally, the SQL statement is executed, and the resulting data is assigned to the DataSource property.

When the AutoRun property is set to true, assigning a value to the Query property automatically prompts the AI model to generate and execute the corresponding SQL statement.

ServerType

The ServerType property is a string that specifies the target database server for which valid SQL should be generated. By default, this property is set to "Microsoft SQL Server".

DataSource

he DataSource property refers to an instance of the Wisej.NET BindingSource class. When the adapter executes an SQL statement, it assigns the resulting DataSet to the DataSource property of the BindingSource.

You have the option to assign your own BindingSource instance to the adapter before executing the SQL statement, or you can use the default instance created by the adapter. If you have any Wisej.NET controls bound to this DataSource, they will be automatically populated with data when the adapter executes the SQL query.

Connection

The Connection property represents an ADO.NET connection to a database. You must assign a valid instance of an ADO.NET connection object (such as SqlConnection, OleDbConnection, or NpgsqlConnection). When required, the adapter will automatically invoke the Open() method on the provided connection to establish a connection to the database. Ensure the connection object is properly configured before assigning it to this property.

Schema

It is important to note that Wisej.AI does not automatically detect foreign key relationships from the schema. Instead, it relies solely on column names to infer table relationships. For optimal results, it is recommended to create simplified database views with clear and consistent naming conventions. This approach helps the AI model better understand table associations and valid join conditions. Use meaningful and consistent column names to explicitly indicate relationships. For example:

  • Invoice (InvoiceId, Date, Number)

  • InvoiceLine (InvoiceId, LineNumber, Quantity, Description, Price, ItemId)

By using the same column name (such as InvoiceId) in related tables, you make the relationships clear and more easily recognizable to the model. This practice enhances the AI's ability to generate accurate queries and understand the data structure.

SchemaTables

An array of strings that identifies the tables to be included when constructing the schema context for the AI model.

Utilize this property to restrict the schema to only include tables or views specifically intended for use by the AI model. By doing so, you can optimize the data structure for the AI's needs, eliminating extraneous data and focusing solely on the tables or views that are purpose-built for the AI's functionality and analysis.

SQL

The SQL property is a read-only property that returns the SQL statement generated by the model.

In addition to the properties inherited from the , the SmartQueryAdapter exposes the following additional properties.

The Schema property is a DataTable that defines the structure of the tables and columns accessible to the AI model. This property follows the standard "Columns" format. Wisej.AI specifically utilizes the following columns from this schema: "TABLE_NAME", "COLUMN_NAME", and "DATA_TYPE".

SmartAdapter
schema collection
DataSource
Query
Schema
SQL