Intelligent building self-optimization query system and query method
By combining a large language model with a diverse and heterogeneous knowledge base, natural language queries for smart building data are enabled, solving the problems of high query threshold, low efficiency, and static knowledge base. It provides second-level response and high-precision data analysis capabilities to support real-time decision-making.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TAIHUA WISDOM IND GRP CO LTD
- Filing Date
- 2026-01-30
- Publication Date
- 2026-05-12
AI Technical Summary
Smart building data queries face high barriers to entry, low response efficiency, poor flexibility, difficulty in accumulating domain knowledge, and prominent data silo issues, failing to meet real-time decision-making needs.
By combining a large language model with a diverse and heterogeneous knowledge base, the system understands user questions through a natural language processing module, generates structured query language, and uses vector indexing algorithms for knowledge retrieval and querying, thereby achieving dynamic context generation and self-optimization.
It enables data queries with zero barriers and sub-second response times, high-precision domain knowledge fusion, self-evolution of the knowledge base, reduced maintenance costs, and support for real-time decision-making.
Smart Images

Figure CN122019592A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent technology, and more specifically, to a smart building self-optimization query system and query method. Background Technology
[0002] With the rapid development of IoT technology, smart building systems have deployed a large number of sensors and intelligent devices, including access control systems, parking management systems, meeting room reservation systems, and water and electricity meter monitoring systems. These systems generate massive amounts of structured data every day, stored in relational databases. However, building managers and ordinary users often lack database query skills, making it difficult to quickly obtain the information they need, thus failing to fully realize the value of the data.
[0003] Traditional data querying methods require professional database administrators to write SQL statements, resulting in long response times and failing to meet real-time decision-making needs. Although some business intelligence (BI) tools provide visual interfaces, users still need to understand complex data models and query logic, leading to high learning costs and a steep learning curve.
[0004] Existing smart building data query and analysis technologies mainly suffer from the following problems: 1. High query threshold and low response efficiency: Traditional queries rely on SQL language and database knowledge, which are difficult for non-technical personnel to use. Moreover, query requirements need to be translated by the IT department, resulting in long response cycles and failing to meet real-time decision-making needs. 2. Poor flexibility and weak semantic understanding: BI tools usually only provide preset reports and cannot handle temporary or personalized queries. Furthermore, the system cannot understand natural language and must be input in a fixed format, making it unable to handle ambiguous semantics. 3. Difficulty in accumulating domain knowledge: Business rules and query logic are scattered among experts, making them difficult to reuse effectively. The learning cost for new employees is high, and knowledge transfer is difficult. 4. Prominent data silo problem: Smart buildings involve multiple subsystems with dispersed data sources. The lack of a unified query entry point makes cross-system data integration and analysis extremely complex.
[0005] Chinese patent document (application number: 202211299032.7, application date: October 24, 2022) discloses a digital twin smart building brain-computer interface device and system. The disclosed building intelligent system includes: a CA communication automation subsystem, a BA building electromechanical automation subsystem, an SA security automation subsystem, a FA fire protection automation subsystem, an OA office automation subsystem, and a HA residential automation subsystem. Through an SDK development package, the device of this invention reads and interacts with the building intelligent system to read and analyze the following data: communication network security operation data, building electromechanical safety operation data, security video and pedestrian / vehicle flow data, water, electricity, gas, and heating energy consumption data, fire alarm data, office information data, and smart residential operation data. The smart building brain-computer interface device involves the fusion and analysis of data from diverse heterogeneous systems, supporting data reception via multiple protocols such as HTPP, MQTT, and OPC, thereby achieving scalable and compatible data interface methods. The brain-computer interface standard for intelligent buildings has also proposed interface standards and integration directions for the CA (Communication Automation) subsystem, BA (Building Electromechanical Automation) subsystem, SA (Security Automation) subsystem, FA (Fire Automation) subsystem, OA (Office Automation) subsystem, and HA (Residential Automation) subsystem, laying the foundation for building industry and industrial standards for intelligent buildings. The brain-computer database consists of an IoT database, a 3M+3S database, and an expert knowledge database. Although this solution adopts the fusion of data from multiple heterogeneous systems, it does not enable non-technical personnel to query data instantly and suffers from insufficient understanding of specific business queries.
[0006] Therefore, how to solve the following problems has become an urgent technical issue in this field: 1. high query threshold and low efficiency; 2. insufficient understanding of specific business; 3. static and easily outdated knowledge base. Summary of the Invention
[0007] In view of this, the present invention provides a smart building self-optimizing query system and query method to solve the above-mentioned technical problems: 1. high query threshold and low efficiency; 2. insufficient understanding of specific business needs; 3. static and easily outdated knowledge base. This system combines large language models with diverse heterogeneous knowledge bases and dynamic context generation technologies for application in smart building data analysis.
[0008] The first aspect of this application provides a smart building self-optimizing query system, comprising:
[0009] User interaction module, natural language processing module, knowledge retrieval module, knowledge storage module, data access module, and data source module;
[0010] The knowledge storage module stores knowledge vectors, which originate from a vector sub-database within a multi-dimensional heterogeneous knowledge base. These knowledge vectors are obtained by vectorizing the multi-dimensional knowledge from the sub-knowledge bases within the multi-dimensional heterogeneous knowledge base. The sub-knowledge bases include a data structure knowledge sub-database, a business logic knowledge sub-database, and a query pattern knowledge sub-database. The data structure knowledge sub-database is used for data definition language (DDL) storage, including storing the structure definitions of worktables and recording the relationships between them. The structure definitions of worktables include table names, field names, data types, and constraints. These worktables are worktables within the relational database of the smart building business system. The business logic knowledge sub-database stores business rules, calculation logic, terminology definitions, meanings of special fields, value rules, and business scenario descriptions. The query pattern knowledge sub-database stores problem-structured query language pairings as reference templates for generating structured query languages from a large language model. These problem-structured query language pairings consist of typical problems and their corresponding structured query language pairings. The vector sub-database also includes the original text of the multi-dimensional knowledge within the sub-knowledge bases. The vector sub-database is equipped with a vector indexing algorithm.
[0011] The user interaction module is coupled to the natural language processing module and is used to integrate a web interface, a REST API, and instant messaging. The client inputs natural language questions through the user interaction module.
[0012] The natural language processing module is coupled to the user interaction module. The natural language processing module includes a large language model. It receives the natural language question and uses the large language model to understand it. It is also coupled to the knowledge retrieval module, where the large language model performs intent recognition based on prompts output by the knowledge retrieval module, generating a structured query language corresponding to the natural language question. The natural language processing module is coupled to a data access module, which transmits the generated structured query language to the data access module for querying. The natural language processing module obtains and summarizes the query result set.
[0013] The knowledge retrieval module is coupled to the natural language processing module. Based on the structured query language output by the natural language processing module, it converts the natural language question into a question vector. The question vector is then matched with knowledge vectors in the vector sub-database to retrieve corresponding knowledge entries. The knowledge entries are then used to construct a structured context to obtain the constructed prompt words, which are then fed back to the natural language processing module for processing by the large language model. The knowledge retrieval module is also coupled to the knowledge storage module, and it uses the vector database stored in the knowledge storage module to perform knowledge vector retrieval queries.
[0014] The knowledge storage module is coupled to the knowledge retrieval module and provides knowledge vector data for the knowledge retrieval module to perform retrieval and query.
[0015] The data access module is coupled to the natural language processing module and is used to connect the natural language processing module to the data source module, execute queries according to the structured query language generated by the natural language processing module, and return the query results to the natural language processing module for processing.
[0016] The data source module is coupled to the data access module. The data source module includes the relational database of the smart building business system and is used to provide raw data in the relational database for querying.
[0017] Optionally, the large language model is an OpenAI-API compatible model.
[0018] Optionally, the vector indexing algorithm is the Hierarchical Navigation Small World (HNSW) algorithm.
[0019] Optionally, the relational database may include at least one of MySQL, PostgreSQL, and Oracle.
[0020] A second aspect of this application provides a smart building self-optimization query method, including: construction of a multi-dimensional heterogeneous knowledge base, natural language data query, and automatic optimization of multi-dimensional heterogeneous knowledge base data;
[0021] The method for constructing the multi-dimensional heterogeneous knowledge base includes:
[0022] Organize knowledge materials and obtain knowledge data statistics tables, which include data structure knowledge statistics tables, business logic knowledge statistics tables, and query pattern knowledge statistics tables;
[0023] Read the knowledge entries in the knowledge data statistics table, and use a Chinese-optimized text embedding model to convert the text in the knowledge data statistics table into knowledge vectors;
[0024] The knowledge vector and the original text in the knowledge data statistics table are stored in a vector database, and a vector indexing algorithm (such as the HNSW algorithm) is established in the vector database.
[0025] The natural language data query method includes: based on a large language model and a retrieval enhancement generation technology paradigm, converting the natural language question output by the user terminal into a structured query language (SQL), querying the relational database of the smart building business system according to the generated structured query language, processing the obtained query result set, and summarizing and generating query results; wherein:
[0026] The process of converting the natural language question output by the user into a structured query language (SQL) includes:
[0027] The user inputs a natural language question, and the text embedding model is used to convert the natural language question into a question vector, ensuring that the question vector and the knowledge vector are in the same semantic space. The text embedding model is the same as the text embedding model used in the method of constructing the multivariate heterogeneous knowledge base.
[0028] In the vector sub-database, a similarity retrieval is performed on the knowledge entries and the question vectors, and the K retrieval results with the highest similarity to the question vectors are selected, where K=20. Cosine similarity or Euclidean distance is used as the similarity metric. The retrieval results include data structure knowledge, business logic knowledge, and query pattern knowledge.
[0029] The retrieved knowledge items are structured and contextualized, sorted according to importance and relevance, and prompt words are constructed. The prompt words contain the user's question and the retrieved knowledge items, wherein the relevance is the similarity and the importance is the priority of the business.
[0030] The constructed prompt words are input into the large language model, which generates a structured query language based on large language model reasoning (LLM reasoning).
[0031] Check the correctness of the generated structured query language, verify the existence of worksheet names and field names, optimize query performance, and handle special characters and SQL injection risks;
[0032] The step of querying the relational database of the smart building business system according to the generated structured query language and processing the obtained query result set includes:
[0033] The validated Structured Query Language (SCL) is sent to the target database. The target database executes the query according to the SCL and obtains the query result set. If there is an execution exception, the execution exception is captured and error handling is performed. An execution log is recorded for troubleshooting. The target database is at least one of the relational databases of the smart building business system.
[0034] Convert the query result set returned by the target database into a structured format (JSON);
[0035] The summary of generated query results includes:
[0036] Input the user question and the query results, invoke the large language model, and output a summary of results in natural language form; the summary of results includes the natural language question and structured data;
[0037] The automatic optimization of the multi-dimensional heterogeneous knowledge base data includes:
[0038] The structured query language is used to correct the error cases of captured execution exceptions to obtain correct question-answer pairs. The correct question-answer pairs are added to the query pattern knowledge sub-knowledge base in the multivariate heterogeneous knowledge base to form new knowledge entries. The new knowledge entries are vectorized and stored in the vector sub-database.
[0039] Optionally, the optimization of query performance includes:
[0040] Add index hints to special fields of data structure knowledge in the multivariate heterogeneous knowledge base. When constructing the hint words, inform the large language model that for the special fields, the index hints should be given priority for large language model inference. The special fields include time range fields and specific device ID fields.
[0041] Optionally, converting the query result set returned by the database into a structured format includes:
[0042] Process the pagination and truncation of the result set, and format special type data, including dates and numbers.
[0043] Compared with existing technologies, the intelligent building self-optimization query system and query method provided by this invention achieves at least the following beneficial effects:
[0044] This invention combines large language models with diverse heterogeneous knowledge bases and dynamic context generation technologies, and applies them to smart building data analysis, achieving the following significant technical effects:
[0045] First, the barrier to entry is lowered and query efficiency is improved: Ordinary users do not need to understand database structure or SQL, allowing non-technical personnel to ask questions in natural language instead of writing complex SQL; they can complete complex queries through conversational questions, reducing training time from several days to several minutes; the traditional "manual translation, several hours of response" model is transformed into an automated process of "natural language questioning, 5-second response", achieving second-level response, allowing users to directly obtain data and intelligent summaries, supporting real-time decision-making;
[0046] Second, to achieve high-precision domain knowledge fusion and solve the problem of insufficient understanding of specific business: a method for constructing and collaboratively retrieving a "multi-dimensional heterogeneous knowledge base" (DDL, documents, SQL examples) is proposed; through multi-dimensional knowledge collaborative retrieval, high accuracy is ensured, and a closed-loop learning mechanism is provided. The system can self-evolve through expert correction, and through dynamic knowledge injection, the accuracy of SQL generation is greatly improved.
[0047] Third, achieve "live" management and self-optimization of the knowledge base, establish a closed-loop feedback mechanism of "human-machine collaboration", solve the problems of static and outdated knowledge base, enable the system to continuously learn and self-evolve by correcting erroneous cases, and truly realize the accumulation and reuse of expert experience;
[0048] Fourth, knowledge reuse and high system scalability: expert experience can be accumulated and efficiently reused in the form of vectorized query templates; adopting a fine-tuning-free architecture, adapting to new databases or business systems only requires updating the knowledge base, which greatly reduces maintenance costs.
[0049] Of course, any product implementing this invention does not necessarily need to achieve all of the technical effects described above at the same time.
[0050] Other features and advantages of the invention will become clear from the following detailed description of exemplary embodiments of the invention with reference to the accompanying drawings. Attached Figure Description
[0051] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the invention and, together with their description, serve to explain the principles of the invention.
[0052] Figure 1 This is a schematic diagram of each module in the intelligent building self-optimization query system of the present invention;
[0053] Figure 2 This is a schematic diagram of each logical layer in a smart building self-optimization query system of the present invention;
[0054] Figure 3 This is a flowchart of a smart building self-optimization query method according to the present invention;
[0055] Figure 4This is a schematic diagram of the construction of a multi-dimensional heterogeneous knowledge base and the collaborative retrieval process in a smart building self-optimization query method of the present invention;
[0056] Figure 5 This is a schematic diagram of the natural language data query process in the self-optimization query method for smart buildings of the present invention;
[0057] Figure 6 This is a schematic diagram of the natural language to SQL conversion, query execution and return process in the natural language data query of the self-optimization query method for smart buildings in this invention;
[0058] Figure 7 This is a schematic diagram of the automatic optimization process of multi-dimensional heterogeneous knowledge base data in the self-optimization query method for smart buildings of the present invention. Detailed Implementation
[0059] Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the invention.
[0060] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.
[0061] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.
[0062] In all the examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.
[0063] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0064] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of embodiments of this disclosure, unless otherwise stated, "a plurality of" means two or more. Furthermore, the use of "based on" or "according to" implies openness and inclusiveness, because processes, steps, calculations, or other actions "based on" or "according to" one or more of the stated conditions or values may in practice be based on additional conditions or beyond the stated values.
[0065] For ease of understanding, the terms or nouns involved in the embodiments of this invention will be introduced first.
[0066] REST API: Representational State Transfer Application Programming Interface, is an API designed based on the REST architectural style, which enables stateless interaction between clients and servers through HTTP methods;
[0067] SQL: Structured Query Language, is a programming language used to manage relational databases, enabling operations such as data querying, insertion, updating, deletion, and database structure definition.
[0068] HNSW algorithm: Hierarchical navigation small-world algorithm, is a graph indexing algorithm for high-dimensional vector approximate nearest neighbor (ANN) search, which can be used for indexing vector databases;
[0069] OpenAI-API models: Artificial intelligence models that can be called through the official OpenAI application programming interface (API);
[0070] Retrieval Augmentation Generation (RAG) is a technical paradigm that retrieves relevant information from an external knowledge base before generating data, and then uses the retrieval results as context input to LLM to improve the accuracy and timeliness of responses and reduce illusions, without requiring model retraining.
[0071] Similarity: A quantitative metric in semantic space used to measure the semantic closeness of two vectors;
[0072] Cosine similarity: In vector similarity measurement, cosine similarity calculates the cosine of the angle between two vectors in space, with a value range of [-1, 1]. 1 indicates that the directions are exactly the same, 0 indicates that they are orthogonal (unrelated), and -1 indicates that they are completely opposite. The formula for calculating cosine similarity is:
[0073]
[0074] This indicates that the question vector and the knowledge vector are in the same direction and the angle between them is 0°.
[0075] , indicating that the question vector and the knowledge vector are orthogonal / unrelated, with an angle of 90° between them;
[0076] This indicates that the question vector and the knowledge vector are in completely opposite directions, with an angle of 180° between them.
[0077] Euclidean distance: refers to The straight-line distance between corresponding points of two vectors in 3D space calculates the clustering difference at the numerical level of the vectors; the formula for calculating Euclidean distance is:
[0078]
[0079] in, For the problem vector, For knowledge vectors, Let Euclidean distance be the distance between the question vector and the knowledge vector. This indicates that the two vectors are identical. The larger the value, the greater the difference;
[0080] Large Language Model Reasoning (LLM Reasoning): refers to the reasoning ability exhibited by large language models, that is, the process by which the model can understand complex problems, follow logical steps, combine knowledge from multiple domains, and finally deduce the answer or conclusion.
[0081] Existing technologies for intelligent key-value data query and analysis mainly suffer from the following problems: 1. High query threshold and low response efficiency: Traditional queries rely on SQL language and database knowledge, making them difficult for non-technical personnel to use. Furthermore, query requirements need to be translated by the IT department, resulting in long response cycles and failing to meet real-time decision-making needs. 2. Poor flexibility and weak semantic understanding: BI tools typically only provide preset reports and cannot handle temporary or personalized queries. The system also cannot understand natural language, requiring input in a fixed format and failing to handle ambiguous semantics. 3. Difficulty in accumulating domain knowledge: Business rules and query logic are scattered among experts, hindering effective reuse, increasing learning costs for new employees, and making knowledge transfer difficult. 4. Prominent data silo problem: Smart buildings involve multiple subsystems with dispersed data sources; the lack of a unified query entry point makes cross-system data integration and analysis extremely complex.
[0082] This application proposes a self-optimizing query system and method for smart buildings, combining large language models with diverse heterogeneous knowledge bases and dynamic context generation technologies for application in smart building data analysis. It aims to address the core pain points of existing smart building data analysis, such as high query thresholds, slow response times, poor flexibility, and difficulty in reusing domain knowledge. The novel natural language data query and analysis system provided in this application achieves the following technical objectives: 1. Achieving zero-threshold, high-efficiency instant querying; 2. Achieving high-precision domain knowledge fusion; 3. Achieving "live" management and self-optimization of the knowledge base.
[0083] Reference Figures 1-7 , Figure 1 This is a schematic diagram of each module in the intelligent building self-optimization query system of the present invention; Figure 2 This is a schematic diagram of each logical layer in a smart building self-optimization query system of the present invention; Figure 3 This is a flowchart of a smart building self-optimization query method according to the present invention; Figure 4This is a schematic diagram of the construction of a multi-dimensional heterogeneous knowledge base and the collaborative retrieval process in a smart building self-optimization query method of the present invention; Figure 5 This is a schematic diagram of the natural language data query process in the self-optimization query method for smart buildings of the present invention; Figure 6 This is a schematic diagram of the natural language to SQL conversion, query execution and return process in the natural language data query of the self-optimization query method for smart buildings in this invention; Figure 7 This is a schematic diagram of the automatic optimization process of multi-dimensional heterogeneous knowledge base data in the self-optimization query method for smart buildings of the present invention.
[0084] like Figures 1-2 As shown, this embodiment proposes a smart building self-optimization query system, including:
[0085] User interaction module 100, natural language processing module 200, knowledge retrieval module 300, knowledge storage module 400, data access module 500, data source module 600;
[0086] The knowledge storage module 400 stores knowledge vectors, which originate from the knowledge vectors in the vector sub-database of the heterogeneous knowledge base 700. These knowledge vectors are obtained by vectorizing the multivariate knowledge from the sub-knowledge bases within the heterogeneous knowledge base 700. The sub-knowledge bases include a data structure knowledge sub-database 701, a business logic knowledge sub-database 702, and a query pattern knowledge sub-database 703. The data structure knowledge sub-database 701 is used for data definition language (DDL) storage, including storing the structure definitions of worktables and recording the relationships between worktables. The structure definition of a worktable includes table name, field names, and data types. The constraints are as follows: the worksheet is a worksheet within the relational database of the smart building business system; the business logic knowledge sub-database 702 stores business rules, calculation logic, terminology definitions, meanings of special fields, value rules, and business scenario descriptions; the query pattern knowledge sub-database 703 stores problem-structured query language pairs, serving as reference templates for generating structured query languages from the large language model; the problem-structured query language pairs consist of typical problems and their corresponding structured query language pairs; the vector sub-database also includes the original text of multi-dimensional knowledge from the sub-knowledge base; the vector sub-database is equipped with a vector indexing algorithm.
[0087] User interaction module 100 is coupled to natural language processing module 200 and is used to integrate web interface, expressive state transition application programming interface (REST API), instant messaging, and client input natural language questions through user interaction module 100.
[0088] Natural Language Processing (NLP) module 200 is coupled to user interaction module 100. NLP module 200 includes a large language model. NLP module 200 receives natural language questions and uses the large language model to understand the natural language questions. It is also coupled to knowledge retrieval module 300. The large language model performs intent recognition based on prompts output by knowledge retrieval module 300 and generates structured query language corresponding to the natural language questions. NLP module 200 is coupled to data access module 500 to transmit the generated structured query language to data access module 500 for querying. NLP module 200 obtains the query result set and summarizes it.
[0089] The knowledge retrieval module 300 is coupled to the natural language processing module 200. Based on the structured query language output by the natural language processing module 200, it converts the natural language question into a question vector, performs similarity matching between the question vector and the knowledge vector in the vector sub-database, retrieves the corresponding knowledge entries, constructs a structured context for the knowledge entries, obtains the constructed prompt words, and feeds the prompt words back to the natural language processing module 200 for processing by the large language model. The knowledge retrieval module 300 is also coupled to the knowledge storage module 400. The knowledge retrieval module 300 calls the vector database stored in the knowledge storage module 400 to perform knowledge vector retrieval queries.
[0090] The knowledge storage module 400 is coupled to the knowledge retrieval module 300, providing knowledge vector data for the knowledge retrieval module 300 to perform retrieval and query; the knowledge storage module 400 is coupled to the multi-dimensional heterogeneous knowledge base 700, specifically for vectorizing the multi-dimensional knowledge stored in the multi-dimensional heterogeneous knowledge base 700, obtaining knowledge vectors and the original text of the multi-dimensional heterogeneous knowledge base 700 and storing them, and the vector sub-database is equipped with a vector indexing algorithm;
[0091] The data access module 500 is coupled to the natural language processing module 200. It is used to connect the natural language processing module 200 to the data source module 600, execute queries according to the structured query language generated by the natural language processing module 200, and return the query results to the natural language processing module 200 for processing.
[0092] The data source module 600 is coupled to the data access module 500. The data source module 600 includes a relational database of the smart building business system, which is used to provide raw data in the relational database of the smart building business system for querying.
[0093] In this invention, the multi-dimensional heterogeneous knowledge base 700 is the core of the system, containing three types of key information. These three types of key information are stored in the data structure knowledge sub-knowledge base 701, the business logic knowledge sub-knowledge base 702, and the query pattern knowledge sub-knowledge base 703, respectively. The data structure knowledge sub-knowledge base 701, the business logic knowledge sub-knowledge base 702, and the query pattern knowledge sub-knowledge base 703 are set up independently and are all stored in the multi-dimensional heterogeneous knowledge base 700.
[0094] The multi-dimensional heterogeneous knowledge base constructed in this invention deconstructs domain knowledge into three key and heterogeneous components:
[0095] The first category is Data Definition Language (DDL) storage, which solves the problem of "what tables and fields are there". Specifically, it stores the database table structure definition, including table names, field names, data types, constraints, etc.; records the relationships between tables (foreign keys, primary keys); and provides a complete context for the data model to the large language model. Among them, constraints refer to the constraints in the table creation statement. Common constraints include: primary key constraints, foreign key constraints, NOT NULL constraints, unique constraints, check constraints, default value constraints, etc. For example, in the line "create_time" timestamp NOT NULL, "NOTNULL" is a NOT NULL constraint.
[0096] The second category is business document storage, which solves the problems of "what the field values represent" and "how the business rules are calculated" (e.g., "parking space status=0 means it is vacant"). It is used to store knowledge in the fields of business rules, calculation logic, terminology definitions, etc., to explain the meaning and value rules of special fields, and to provide background information on business scenarios.
[0097] The third category is the question-and-answer example (SQL Examples) store, which addresses the question of "how to query this type of question" (e.g., providing an SQL template for "querying total income"). Specifically, it stores the pairing of typical questions with corresponding SQL statements. The question-and-answer example store covers common query scenarios and complex query logic, serving as a reference template for generating SQL from the large language model.
[0098] When a user asks a question, the system does not retrieve a single piece of knowledge. Instead, it vectorizes the question and retrieves the three types of heterogeneous knowledge mentioned above in the vector space. It then combines the most relevant DDL, business documents, and SQL examples to construct a complete context.
[0099] The three types of knowledge complement each other: DDL provides the skeleton, documentation provides the flesh and blood, and SQL examples provide the action paradigm, which greatly improves the accuracy of LLM in understanding complex business and generating high-difficulty SQL (such as multi-table joins and complex aggregations).
[0100] Based on vector retrieval, even if users express different questions (such as "how many parking spaces are left" and "how many parking spaces are available"), the same knowledge items can be accurately matched.
[0101] It should be noted that the vector quantum database is a specific implementation and storage method for a multi-dimensional heterogeneous knowledge base. It vectorizes the multi-dimensional "knowledge" texts in the multi-dimensional heterogeneous knowledge base to obtain knowledge vectors, and then stores them in the vector quantum database. The knowledge storage module specifically refers to the quantum database and is used for retrieval and querying by the knowledge retrieval module.
[0102] Specifically, such as Figure 2 As shown, the smart building self-optimization query system proposed in this embodiment is a novel smart building data mining and analysis system. It adopts a layered architecture design and mainly includes the following modules:
[0103] User Interaction Layer (i.e., User Interaction Module) 100: Used for integration with Web interface, REST API, and instant messaging; Web interface refers to the human-computer interaction interface accessed through a web browser; REST API is a Representational State Transfer Application Programming Interface, an API designed based on the REST architectural style, which realizes stateless interaction between client and server through HTTP methods; Instant Messaging (IM) refers to communication technology that allows users to send text, voice, video, and other messages in real time over the network. The user / client interface handles natural language input through the user interaction layer.
[0104] Natural Language Processing (NLP) layer 200: Used for question understanding, intent recognition, SQL generation, and result summarization; specifically, the NLP layer contains a large language model, receives natural language questions, understands and recognizes the intent of the natural language questions, and generates SQL (Structured Query Language) statements that conform to database syntax based on the context of the prompt words output by the knowledge retrieval layer; the NLP layer also includes summarizing the obtained query result set.
[0105] The knowledge retrieval layer (i.e., the knowledge retrieval module) 300 is used for vectorization, similarity matching, and context construction. Specifically, the knowledge retrieval layer converts the natural language input from the natural language layer into a question vector, retrieves the knowledge entry most similar to the question vector from the vector database, performs similarity matching, and constructs context to build a prompt template. The prompt template is used by the natural language processing layer for intent recognition and SQL generation.
[0106] The knowledge storage layer (i.e., the knowledge storage module) 400 stores a vector database containing three types of knowledge: DDL (Data Definition Language) definitions, business documents, and SQL examples. Specifically, the vector database stores knowledge vectors and raw text. The raw text is the ternary heterogeneous knowledge stored in the multi-dimensional heterogeneous knowledge base 700, including DDL (Data Definition Language) definitions, business documents, and SQL examples. The knowledge vectors are generated by converting the DDL (Data Definition Language) definitions, business documents, and SQL examples in the raw text into vectors using a Chinese-optimized text embedding model. The knowledge storage layer also establishes an efficient vector index to support fast similarity retrieval.
[0107] The data access layer (i.e., the data access module) 500 is used for database connection, query execution, and result return. Specifically, the data access layer establishes a connection with the database (data source layer) and performs retrieval queries based on the SQL statements output by the natural language processing layer, and returns the query results to the natural language processing layer for subsequent result summarization.
[0108] The data source layer (i.e., data source module) 600 mainly refers to the databases of various subsystems of the smart building, and can also be the relational database of the smart building business system. Depending on its functions, the smart building may include, but is not limited to, communication subsystems, security subsystems, fire protection subsystems, OA office subsystems, etc. The data source layer includes the databases of each subsystem, and realizes data calling, querying, etc. by communicating with the data access layer.
[0109] In some optional embodiments provided by this invention, the large language model is an OpenAI-API compatible model, including but not limited to OpenAI-API compatible models such as GLM, Qwen, and Gemini. It is not limited to a single model and can be flexibly switched.
[0110] Specifically, Large Language Models (LLMs) are deep learning-based artificial intelligence models that, through training on massive amounts of text data, can understand, generate, and process natural language, achieving readability and comprehension of human language.
[0111] In some optional embodiments provided by the present invention, the vector indexing algorithm is the Hierarchical Navigation Small World (HNSW) algorithm.
[0112] Specifically, vector indexing involves quickly finding the K most similar vectors to the target vector from a massive vector set. In this embodiment, a vector refers to text data converted into genetic numbers. Cosine similarity or Euclidean distance is used to measure vector similarity; the more similar the vectors, the closer they are, and the closer the cosine similarity is to 1.
[0113] The HNSW algorithm is a graph indexing algorithm that uses high-dimensional vector approximate nearest neighbor (ANN) search. It can be used for indexing vector subdatabases and for accelerating retrieval enhancement generation (RAG) in large language models (LLMs). Specifically, it introduces the multi-level structure of skip lists into graph algorithms.
[0114] The HNSW algorithm divides the graph into multiple layers:
[0115] Layer 0: Contains all points in the dataset. It is a high-density graph with very fine connections between nodes. Upper Layers: Contain only a sample of nodes. The higher the layer, the sparser the nodes. Connection method: Each node is only connected to its nearest neighbors within its own layer.
[0116] The retrieval process is a top-down "greedy search", specifically:
[0117] When a query vector is input, HNSW's search process is as follows:
[0118] Enter from the top floor: Start from the preset starting point at the very top;
[0119] Greedy search: Find the nearest neighbor node to the query point in the current layer;
[0120] Inter-layer switching: Once a closer point cannot be found in the current layer, the search continues from that point to the next layer (a denser layer).
[0121] Final location: Repeat the above process until you land at the bottom layer (Layer 0). The nearest neighbor found at the bottom layer (Layer 0) is the final result.
[0122] The advantage of this design is that the "long side" can be used to quickly locate the target area at higher levels, while the "short side" can be used for fine-tuning at lower levels, which greatly reduces the number of times distance calculations are needed.
[0123] In some optional embodiments provided by the present invention, the database is a relational database, and the specific type includes, but is not limited to, mainstream relational databases such as MySQL, PostgreSQL, and Oracle.
[0124] Specifically, this application supports mainstream relational databases because LLM can easily generate various SQL dialects. Therefore, as long as there is a corresponding driver, it is possible to connect to the database.
[0125] In one embodiment, a smart building self-optimization query method is provided, such as... Figure 3As shown, it includes: construction of a multi-dimensional heterogeneous knowledge base (S100), natural language data query (S200), and automatic optimization of multi-dimensional heterogeneous knowledge base data (S300).
[0126] The multi-dimensional heterogeneous knowledge base 700 includes a data structure knowledge sub-knowledge base 701, a business logic knowledge sub-knowledge base 702, a query pattern knowledge sub-knowledge base 703, and a vector sub-database 704. Among them, the data structure knowledge sub-knowledge base 701 stores a data structure knowledge statistical table, the business logic knowledge sub-knowledge base 702 stores a business logic knowledge statistical table, the query pattern knowledge sub-knowledge base 703 stores a query pattern knowledge statistical table, and the vector sub-database 704 stores knowledge vectors.
[0127] S100, the methods for constructing a multi-dimensional heterogeneous knowledge base include:
[0128] S101. Organize knowledge materials and obtain knowledge data statistics tables, which include data structure knowledge statistics tables, business logic knowledge statistics tables, and query pattern knowledge statistics tables.
[0129] S102. Read the knowledge entries in the knowledge data statistics table, and use a Chinese-optimized text embedding model to convert the text in the knowledge data statistics table into knowledge vectors.
[0130] S103. Store the original text in the knowledge vector and knowledge data statistics table into the vector sub-database, and establish a vector indexing algorithm (such as the HNSW algorithm) in the vector sub-database.
[0131] S200, the method for natural language data querying includes: based on a large language model and retrieval enhancement generation technology paradigm, converting the natural language question output by the user into a structured query language (SQL) (S201), querying the relational database of the smart building business system according to the generated structured query language, processing the obtained query result set, and summarizing and generating query results; among which, such as Figure 5 As shown:
[0132] S201. Converting the natural language question output by the user into the structured query language SQL includes:
[0133] S2011: The user inputs a natural language question, and a text embedding model is used to convert the natural language question into a question vector, ensuring that the question vector and the knowledge vector are in the same semantic space. The text embedding model is the same as the text embedding model used in the method of constructing a multi-dimensional heterogeneous knowledge base. It should be noted that the text embedding model selected in S102 and S2011 is not specifically limited, only that the text embedding model in S102 and S2011 is consistent. In this embodiment, the BAAI BGE M3 model is selected. It should be noted that the text embedding model used before and after must be the same, and once selected, it cannot be switched at will.
[0134] S2012. In the vector database, perform similarity retrieval on knowledge blocks and question vectors, and select the K search results with the highest similarity to the question vector, where K=20. Cosine similarity or Euclidean distance is used as the similarity measurement method. The search results include data structure knowledge, business logic knowledge, and query pattern knowledge. It should be noted that when measuring similarity, cosine similarity and distance similarity are both acceptable; either one can be chosen, with cosine similarity being the preferred method.
[0135] S2013. Construct a structured context for the retrieved knowledge items, sort them according to importance and relevance, and construct prompt words. The prompt words contain the user's question and the retrieved knowledge items, wherein the relevance is the magnitude of the similarity and the importance is the priority of the business.
[0136] Specifically, relevance is the semantic similarity calculated after vector retrieval, sorted by size. Weight is the business priority, which specifically refers to: 1. Architectural foundation: DDL (table structure) is usually more important than business documents because SQL cannot be generated without a DDL model; 2. Timeliness and credibility: Recently updated or manually corrected SQL examples by experts are more important than older or automatically generated examples.
[0137] S2014. Input the constructed prompt words into the large language model. The large language model generates a structured query language based on large language model reasoning (LLM reasoning).
[0138] S2015. Check the correctness of the generated structured query language, verify the existence of worksheet names and field names, optimize query performance, and handle special characters and SQL injection risks.
[0139] S202. Perform queries in the relational database of the smart building business system using the generated structured query language, and process the obtained query result set, including:
[0140] The validated Structured Query Language (SCL) is sent to the target database. The target database executes the query according to the SCL and obtains the query result set. If there is an execution exception, the execution exception is captured and error handling is performed. The execution log is recorded for troubleshooting. The target database is at least one of the relational databases of the smart building business system.
[0141] Convert the query result set returned by the target database into a structured format (JSON);
[0142] S203. Summary of generated query results includes:
[0143] Input the user's question and query results, invoke the large language model, and output a summary of the results in natural language form; the summary of results includes the natural language question and structured data;
[0144] S300, automatic optimization of multi-dimensional heterogeneous knowledge base data includes:
[0145] The structured query language is used to correct the error cases of captured execution exceptions to obtain the correct question-answer pairs. The correct question-answer pairs are added to the query pattern knowledge sub-knowledge base in the multivariate heterogeneous knowledge base to form new knowledge entries. The new knowledge entries are vectorized and stored in the vector sub-database.
[0146] Specifically, such as Figure 3 , Figure 4 As shown, the process of constructing a multi-dimensional heterogeneous knowledge base (S100) and collaborative retrieval includes (the vector database is the vector sub-database mentioned earlier):
[0147] S101, Data Preparation Phase: Business and technical personnel collaborate to organize knowledge materials; data is organized using Excel spreadsheets, including three worksheets: DDL, Documentation, and SQL Examples; each worksheet corresponds to a type of knowledge, DDL corresponds to data structure knowledge, Documentation corresponds to business logic knowledge, and SQL Examples corresponds to query pattern knowledge;
[0148] S102, Vectorization Processing Stage: Extract various knowledge items from the Excel file, and use a Chinese optimized text embedding model to convert the text into knowledge vectors. In this embodiment, the text embedding model adopted is BAAI / bge-small-zh-v1.5.
[0149] S103, Vector Storage Stage: Store vectors and original text in a vector database, establish an efficient vector index (such as the HNSW algorithm), and support fast similarity retrieval (millisecond-level response).
[0150] In S200 natural language data query, converting natural language to SQL (S201) is the core function of this system. It is implemented using a hybrid approach based on a large language model and Retrieval Enhancement Generation (RAG), specifically including (e.g.) Figure 4 , Figure 5 , Figure 6 (as shown)
[0151] S2011, Question Vectorization: The user inputs a natural language question, such as "What time did Han Feng arrive at the company today?", and the question is converted into a question vector using the same embedding model as the multi-dimensional heterogeneous knowledge base, ensuring that the question vector and the knowledge vector are in the same semantic space; in this embodiment, the bge-small-zh-v1.5 text embedding model is used to convert the text into a question vector.
[0152] S2012, Similar Knowledge Retrieval: Retrieve the knowledge entries most similar to the question vector in the vector database, using cosine similarity or Euclidean distance as the similarity measure. Usually, the top-K (e.g., K=20) most relevant results are retrieved. The retrieval results include: relevant DDL definitions, relevant business documents, and similar historical question and answer examples.
[0153] S2013, Context Construction: Organize the retrieved knowledge items into a structured context, sort them according to importance and relevance, and construct a prompt template, including the question + the retrieved knowledge;
[0154] S2014, Large Language Model Inference: Input the constructed prompt words into the large language model. The large language model performs inference based on the large language model (LLM inference), understands the contextual intent of the question, and generates SQL statements that conform to the database syntax.
[0155] S2015, SQL Validation and Optimization: Check the correctness of the generated SQL syntax, verify the existence of table names and field names, optimize query performance (such as adding necessary index hints), and handle special characters and SQL injection risks.
[0156] In S202, the generated structured query language is used to query the subsystem database of the smart building, and the resulting query result set is processed, including:
[0157] S2021, database connection management, supports multiple database types (MySQL, PostgreSQL, etc.), uses connection pooling technology to improve performance, and configures timeout and retry mechanisms to ensure stability;
[0158] S2022, SQL Execution: Send the generated SQL statement to the target database, capture execution exceptions and perform error handling, and record execution logs for troubleshooting;
[0159] S2023, Result Set Processing: Convert the result set returned by the database into a structured format (JSON), handle pagination and truncation of large result sets, and format special data types such as dates and numbers.
[0160] S203. The process of generating query results is an intelligent summary. To make the query results easier for non-technical users to understand, the system provides an intelligent summary function:
[0161] The summary generation process includes:
[0162] Input: User question + query result data;
[0163] Processing: Call the large language model again;
[0164] Output: A summary of the results in natural language.
[0165] In terms of prompt design, it includes user questions and structured data, requiring the large language model to summarize them concisely in Chinese, highlighting key data. For example: Question: "What time did Han Feng arrive at the company today?" Summary: "Han Feng arrived at the company at 8:35 this morning." Question: "How many parking spaces are left?" Summary: "There are currently 23 vacant parking spaces in the parking lot."
[0166] It should be further noted that the knowledge bases of existing query systems are static and cannot automatically correct errors. This invention designs a human-machine collaborative closed-loop learning mechanism, enabling the knowledge base to have self-optimization capabilities.
[0167] S300, automatic optimization of multi-dimensional heterogeneous knowledge base data includes:
[0168] S301 Error capture: The system records query cases that the user considers "inaccurate" (i.e., question-SQL-result pairs);
[0169] S302, Expert Correction: Business experts or DBAs (Database Administrators) can correct erroneous SQL statements on the management interface, generating a "correct" (question, correct SQL) question-and-answer pair.
[0170] S303, Knowledge Reversion: This corrected "correct question-answer pair" will be automatically added back to the "Question-Answer Examples (SQL Examples)" section of the multi-dimensional heterogeneous knowledge base;
[0171] S304, Automatic Optimization: New knowledge entries are vectorized and stored in a vector database;
[0172] S305, Closed-loop formation: When a user raises a similar question again in the future, the system will retrieve this "correct" example, thereby generating the correct SQL and preventing the same error from happening again.
[0173] The specific process is as follows: Figure 7 As shown, when a user asks a question, the query system of this invention generates an SQL statement, executes the query based on the SQL statement, and judges the accuracy of the query results. If accurate, the query results are returned, and the entire process ends. If the results are inaccurate, the system automatically captures errors, records error cases, and performs expert correction on the error cases, specifically correcting the SQL on the management interface. After correction, the corrected "question-SQL" pair is fed back into the knowledge base and automatically added to the "Question and Answer Examples (SQL Examples)" section. The new knowledge entry is vectorized and stored in the vector database, updating the SQL examples. The next time a similar question is asked, the system will automatically retrieve the updated correct example and generate the correct SQL. The management interface is a test front-end interface, using a chat window format, for asking questions and verifying the correctness of answers, and also provides a function to correct and update the knowledge base.
[0174] This technology enables the system to evolve, truly realizing a dynamic process of "knowledge accumulation." The system is no longer a "one-time delivery" but a "continuous evolution," becoming more intelligent with use. It achieves human-machine collaboration, making full use of experts' domain knowledge and efficiently transforming human experience into reusable knowledge assets for machines.
[0175] In some optional embodiments provided by the present invention, optimizing query performance includes: adding index hints to special fields of data structure knowledge in a multivariate heterogeneous knowledge base; informing the large language model when constructing hint words; and prioritizing the use of index hints for large language model inference for special fields, wherein special fields include time range fields and specific device ID fields.
[0176] Specifically, optimizing query performance involves, for example, adding necessary index hints. In the DDL storage portion of a multivariate heterogeneous knowledge base, this involves declaring which fields are indexed. When constructing hints, the Large Language Model (LLM) is told: "When queries involve time ranges or specific device IDs, prioritize using indexes." The LLM then generates optimized statements with database dialect characteristics accordingly.
[0177] In some optional embodiments provided by this invention, handling special characters and SQL injection risks includes:
[0178] Parameters entered by users in natural language (such as names or specially named devices) may pose risks. It is necessary to strictly prohibit the generation of destructive DDL or DML statements such as DROP, DELETE, TRUNCATE, and UPDATE in system prompts. LLMs must be required to enclose all string parameters in single quotes and perform standard escaping. Finally, when connecting to the database at the data access layer, low-privilege accounts should be used, with only read-only SELECT permissions for specific tables.
[0179] In some optional embodiments provided by the present invention, similarity retrieval of knowledge entries and question vectors in the vector sub-database specifically includes the following steps:
[0180] 1. Retrieve the knowledge entry most similar to the question vector from the vector sub-database;
[0181] 2. Use cosine similarity or Euclidean distance as a similarity metric;
[0182] 3. Typically, the top-K (e.g., K=20) most relevant results are retrieved;
[0183] 4. Search results include: relevant DDL definitions, relevant business documents, and similar historical Q&A examples;
[0184] In this invention, a "similarity threshold" can also be set as a protective measure to avoid the following: if the user inputs meaningless characters or questions that are completely unrelated to the business, the system will still forcibly recall the "most similar" knowledge. For example, by setting a "similarity threshold" (e.g., cosine similarity > 0.7), it can be ensured that only truly relevant DDL, business rules, or SQL examples are provided to the model, thereby improving the accuracy of the generated results.
[0185] In some optional embodiments provided by the present invention, converting the query result set returned by the database into a structured format includes:
[0186] Process the pagination and truncation of the result set, and format special data types, including dates and numbers.
[0187] As can be seen from the above embodiments, the intelligent building self-optimization query system and query method provided by the present invention achieves at least the following beneficial effects:
[0188] This invention combines large language models with diverse heterogeneous knowledge bases and dynamic context generation technologies, and applies them to smart building data analysis, achieving the following significant technical effects:
[0189] 1. Lowered barrier to entry and improved query efficiency: Ordinary users do not need to understand database structure or SQL. Non-technical personnel can ask questions in natural language to replace complex SQL writing. They can complete complex queries through conversational questions, reducing training time from several days to several minutes. The traditional "manual translation, hours of response" mode is transformed into an automated process of "natural language questioning, 5-second response", achieving second-level response. Users can directly obtain data and intelligent summaries to support real-time decision-making.
[0190] 2. Achieve high-precision domain knowledge fusion to solve the problem of insufficient understanding of specific business: Propose a construction and collaborative retrieval method for a "multi-dimensional heterogeneous knowledge base" (DDL, documents, SQL examples); through multi-dimensional knowledge collaborative retrieval, high accuracy is ensured, and a closed-loop learning mechanism is provided. The system can self-evolve through expert correction, and through dynamic knowledge injection, the accuracy of SQL generation is greatly improved.
[0191] 3. Achieve "live" management and self-optimization of the knowledge base, establish a closed-loop feedback mechanism of "human-machine collaboration", solve the problems of static and outdated knowledge base, enable the system to continuously learn and self-evolve by correcting erroneous cases, and truly realize the accumulation and reuse of expert experience;
[0192] 4. Knowledge reuse and high system scalability: Expert experience can be accumulated and efficiently reused in the form of vectorized query templates; adopting a fine-tuning-free architecture, adapting to new databases or business systems only requires updating the knowledge base, which greatly reduces maintenance costs.
[0193] While specific embodiments of the invention have been described in detail by way of examples, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. Those skilled in the art should understand that modifications can be made to the above embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.
Claims
1. A smart building self-optimization query system, characterized in that, include: User interaction module, natural language processing module, knowledge retrieval module, knowledge storage module, data access module, and data source module; The knowledge storage module stores knowledge vectors, which originate from a vector sub-database within a multi-dimensional heterogeneous knowledge base. These knowledge vectors are obtained by vectorizing the multi-dimensional knowledge from the sub-knowledge bases within the multi-dimensional heterogeneous knowledge base. The sub-knowledge bases include a data structure knowledge sub-database, a business logic knowledge sub-database, and a query pattern knowledge sub-database. The data structure knowledge sub-database stores data definition languages, including the structure definitions of worktables and recording the relationships between them. The structure definitions of worktables include table names, field names, data types, and constraints. These worktables are within the relational database of the smart building business system. The business logic knowledge sub-database stores business rules, calculation logic, terminology definitions, meanings of special fields, value rules, and business scenario descriptions. The query pattern knowledge sub-database stores problem-structured query language pairs as reference templates for generating structured query languages from a large language model. These problem-structured query language pairs consist of typical problems and their corresponding structured query language pairs. The vector sub-database also includes the original text of the multi-dimensional knowledge from the sub-knowledge bases and incorporates a vector indexing algorithm. The user interaction module is coupled to the natural language processing module and is used to integrate a web interface, a representational state transition application programming interface, and instant messaging. The client inputs natural language questions through the user interaction module. The natural language processing module is coupled to the user interaction module. The natural language processing module includes a large language model. It receives the natural language question and uses the large language model to understand it. It is also coupled to the knowledge retrieval module, where the large language model performs intent recognition based on prompts output by the knowledge retrieval module, generating a structured query language corresponding to the natural language question. The natural language processing module is coupled to a data access module, which transmits the generated structured query language to the data access module for querying. The natural language processing module obtains and summarizes the query result set. The knowledge retrieval module is coupled to the natural language processing module. Based on the structured query language output by the natural language processing module, it converts the natural language question into a question vector. The question vector is then matched with knowledge vectors in the vector sub-database to retrieve corresponding knowledge entries. The knowledge entries are then used to construct a structured context to obtain the constructed prompt words, which are then fed back to the natural language processing module for processing by the large language model. The knowledge retrieval module is also coupled to the knowledge storage module, and it uses the vector database stored in the knowledge storage module to perform knowledge vector retrieval queries. The knowledge storage module is coupled to the knowledge retrieval module, and provides knowledge vector data for the knowledge retrieval module to perform retrieval and query. The data access module is coupled to the natural language processing module and is used to connect the natural language processing module to the data source module, execute queries according to the structured query language generated by the natural language processing module, and return the query results to the natural language processing module for processing. The data source module is coupled to the data access module. The data source module includes the relational database of the smart building business system and is used to provide raw data in the relational database for querying.
2. The intelligent building self-optimization query system according to claim 1, characterized in that, The large language model is an OpenAI-API compatible model.
3. The intelligent building self-optimization query system according to claim 1, characterized in that, The vector indexing algorithm is a hierarchical navigation small-world algorithm.
4. The intelligent building self-optimization query system according to claim 1, characterized in that, The relational database type includes at least one of MySQL, PostgreSQL, and Oracle.
5. A self-optimizing query method for smart buildings, characterized in that, include: Construction of diverse and heterogeneous knowledge bases, natural language data querying, and automatic optimization of diverse and heterogeneous knowledge base data; The method for constructing the multi-dimensional heterogeneous knowledge base includes: Organize knowledge materials and obtain knowledge data statistics tables, which include data structure knowledge statistics tables, business logic knowledge statistics tables, and query pattern knowledge statistics tables; Read the knowledge entries in the knowledge data statistics table, and use a Chinese-optimized text embedding model to convert the text in the knowledge data statistics table into knowledge vectors; Store the knowledge vector and the original text in the knowledge data statistics table into a vector sub-database, and establish a vector indexing algorithm in the vector sub-database; The natural language data query method includes: based on a large language model and a retrieval enhancement generation technology paradigm, converting the natural language question output by the user terminal into a structured query language; querying the relational database of the smart building business system according to the generated structured query language; processing the obtained query result set; and summarizing and generating query results; wherein: The process of converting the natural language question output by the user into a structured query language includes: The user inputs a natural language question, and the text embedding model is used to convert the natural language question into a question vector, ensuring that the question vector and the knowledge vector are in the same semantic space. The text embedding model is the same as the text embedding model used in the method of constructing the multivariate heterogeneous knowledge base. In the vector sub-database, a similarity retrieval is performed on the knowledge entries and the question vectors, and the K retrieval results with the highest similarity to the question vectors are selected, where K=20. Cosine similarity or Euclidean distance is used as the similarity metric. The retrieval results include data structure knowledge, business logic knowledge, and query pattern knowledge. The retrieved knowledge items are structured and contextualized, sorted according to importance and relevance, and prompt words are constructed. The prompt words contain the user's question and the retrieved knowledge items, wherein the relevance is the similarity and the importance is the priority of the business. The constructed prompt words are input into the large language model, which infers based on the large language model to generate a structured query language; Check the correctness of the generated structured query language, verify the existence of worksheet names and field names, optimize query performance, and handle special characters and SQL injection risks; The step of querying the relational database of the smart building business system according to the generated structured query language and processing the obtained query result set includes: The validated Structured Query Language (SCL) is sent to the target database. The target database executes the query according to the SCL and obtains the query result set. If there is an execution exception, the execution exception is captured and error handling is performed. An execution log is recorded for troubleshooting. The target database is at least one of the relational databases of the smart building business system. Convert the query result set returned by the target database into a structured format; The summary of generated query results includes: Input the user question and the query results, invoke the large language model, and output a summary of results in natural language form; the summary of results includes the natural language question and structured data; The automatic optimization of the multi-dimensional heterogeneous knowledge base data includes: The structured query language is used to correct the error cases of captured execution exceptions to obtain correct question-answer pairs. The correct question-answer pairs are added to the query pattern knowledge sub-knowledge base in the multivariate heterogeneous knowledge base to form new knowledge entries. The new knowledge entries are vectorized and stored in the vector sub-database.
6. The intelligent building self-optimization query method according to claim 5, characterized in that, The optimized query performance includes: Add index hints to special fields of data structure knowledge in the multivariate heterogeneous knowledge base. When constructing the hint words, inform the large language model that for the special fields, the index hints should be given priority for large language model inference. The special fields include time range fields and specific device ID fields.
7. The intelligent building self-optimization query method according to claim 5, characterized in that, The process of converting the query result set returned by the database into a structured format includes: Process the pagination and truncation of the result set, and format special type data, including dates and numbers.