Data query methods, data processing methods, apparatus, electronic devices and computer-readable storage media

By inserting soft hint vectors into query commands, the semantic guidance on the query side is dynamically adjusted, which solves the problem of insufficient accuracy of general embedding models in specific domains and achieves the effect of improving query accuracy and reducing costs without rebuilding the index.

CN123115386APending Publication Date: 2026-11-17SANGFOR TECH INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611358544.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-02
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

General embedding models perform poorly in specific vertical fields (such as security, healthcare, law, finance, etc.), resulting in inaccurate search results. Furthermore, fine-tuning all parameters requires a lot of computing power and time, and rebuilding the established vector index is costly.

Method used

By inserting soft hint vectors into query commands, encoding them using the target model, and matching the query embedding vectors with a pre-built document vector index while keeping the document vector index unchanged, the semantic guidance on the query side is dynamically adjusted.

Benefits of technology

Without changing the index structure, the accuracy of query results is improved, and the cost of data querying and index maintenance overhead are significantly reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115386A_ABST
    Figure CN123115386A_ABST
Patent Text Reader

Abstract

This application discloses a data query method, data processing method, apparatus, electronic device, and computer-readable storage medium to achieve low-cost and high-accuracy data query. The query method includes: receiving a target query instruction and determining a task identifier for the target query instruction; inserting a soft hint vector matching the task identifier into the target query instruction to obtain an optimized query instruction; encoding the optimized query instruction using a target model to obtain a query embedding vector; matching the query embedding vector with a pre-set document vector index to obtain document data corresponding to the target document vector index and using the document data as the query result corresponding to the target query instruction; wherein, the document vector index is pre-constructed by the target model after encoding the full amount of document data according to the original encoding method, and remains unchanged during the data query process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information retrieval technology, and in particular to data query methods, data processing methods, apparatus, electronic devices, and computer-readable storage media. Background Technology

[0002] Dense retrieval is a core component of current enterprise knowledge base question answering, semantic search, and RAG systems. Its core technology lies in large language model embedding (such as Qwen3-Embedding), which encodes text into high-dimensional dense vectors and then matches queries with documents using cosine similarity. Compared to traditional sparse retrieval (such as BM25), it has significantly better semantic understanding capabilities. However, current general embedding models often underperform in specific vertical domains (security, healthcare, law, finance, etc.) for two reasons: First, there is a discrepancy between general instructions and domain semantics. That is, the instructions of general models (such as "retrieve paragraphs related to the question") have limited guiding effect on domain-specific queries and cannot conform to the semantic habits of professional terminology, thus leading to inaccurate search results. Second, fine-tuning a model with billions of parameters requires a large amount of computing power, time, and complete supervision data. Moreover, when the document encoding method changes during training, the established vector index (usually containing millions or even hundreds of millions of document vectors) also needs to be completely rebuilt, which is extremely costly.

[0003] Therefore, how to effectively reduce the cost of data query while ensuring the accuracy of data query results is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] The purpose of this application is to provide a data query method, data processing method, apparatus, electronic device, and computer-readable storage medium that can effectively reduce the cost of data query while ensuring the accuracy of the data query results.

[0005] Firstly, this application discloses a data query method, including: Receive the target query instruction and determine the task identifier of the target query instruction; The soft hint vector that matches the task identifier is inserted into the target query instruction to obtain the optimized query instruction; The optimized query command is encoded using the target model to obtain a query embedding vector. The query embedding vector is matched with a pre-set document vector index to obtain the document data corresponding to the target document vector index, and the document data is used as the query result corresponding to the target query instruction. The document vector index is pre-constructed by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

[0006] Preferably, the process of setting the document vector index includes: Retrieve all document data; The target model is used to encode each document data to obtain a document embedding vector. Construct a corresponding document vector index based on the document embedding vector.

[0007] This application discloses a data processing method, including: Multiple sets of corresponding query sample and document sample embedding vectors are obtained, and a trainable soft hint vector is inserted into each query sample to obtain each optimized query sample; the document sample embedding vector is the pre-encoded vector of the corresponding document sample. The target model is used to encode each of the optimized query samples to obtain the query sample embedding vector; Loss is calculated based on the query sample embedding vector and the document sample embedding vector, and the trainable soft cue vector is iteratively updated using the loss value to obtain the soft cue vector. The soft suggestion vector is used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

[0008] Preferably, a trainable soft cue vector is inserted into each of the query samples to obtain optimized query samples, including: The query sample is split into a query command segment and a query text segment; The trainable soft cue vector is inserted between the query instruction segment and the query text segment to obtain the optimized query sample.

[0009] Preferably, a trainable soft cue vector is inserted into each of the query samples to obtain optimized query samples, including: The target number of trainable soft cue vectors is determined based on the number of annotations in the query sample. The target number of trainable soft cue vectors are inserted into the query sample to obtain the optimized query sample.

[0010] Preferably, before inserting trainable soft cue vectors into each of the query samples to obtain each optimized query sample, the method further includes: Determine the data query domain to which the query sample and the document sample belong; Obtain the descriptive text corresponding to the data query domain; The descriptive text is encoded using the target model to obtain the initial value of the trainable soft cue vector.

[0011] Preferably, loss calculation is performed based on the query sample embedding vector and the document sample embedding vector, including: The contrastive learning loss is calculated based on the query sample embedding vector and the document sample embedding vector. The loss value is obtained by superimposing the contrastive learning loss on the loss corresponding to the trainable soft cue vector.

[0012] Secondly, this application also discloses a data query device, comprising: The instruction receiving module is used to receive the target query instruction and determine the task identifier of the target query instruction; The instruction optimization module is used to insert a soft hint vector that matches the task identifier into the target query instruction to obtain the optimized query instruction; The vectorization module is used to encode the optimized query command using the target model to obtain a query embedding vector; The query processing module is used to match the query embedding vector with a pre-set document vector index to obtain the document data corresponding to the target document vector index as the query result corresponding to the target query instruction. The document vector index is pre-constructed by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

[0013] This application discloses a data processing apparatus, comprising: The sample optimization module is used to obtain multiple sets of corresponding query samples and document sample embedding vectors, insert trainable soft hint vectors into each query sample, and obtain each optimized query sample; the document sample embedding vector is the pre-encoded vector of the corresponding document sample; The vector processing module is used to encode each of the optimized query samples using the target model to obtain the query sample embedding vector; The training module is used to calculate the loss based on the query sample embedding vector and the document sample embedding vector, and to iteratively update the trainable soft cue vector using the loss value to obtain the soft cue vector. The soft suggestion vector is used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

[0014] Thirdly, this application also discloses an electronic device, comprising: Memory, used to store computer programs; A processor, configured to implement any of the data querying or data processing methods described above when executing the computer program.

[0015] Fourthly, this application also discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the data query methods or data processing methods described above.

[0016] The data query method provided in this application includes: receiving a target query instruction and determining the task identifier of the target query instruction; inserting a soft hint vector matching the task identifier into the target query instruction to obtain an optimized query instruction; encoding the optimized query instruction using a target model to obtain a query embedding vector; matching the query embedding vector with a pre-set document vector index to obtain the document data corresponding to the target document vector index and using the document data as the query result corresponding to the target query instruction; wherein, the document vector index is pre-constructed by the target model after encoding the full amount of document data according to the original encoding method, and remains unchanged during the data query process.

[0017] As can be seen, the data query method provided in this application, by receiving the target query instruction and determining its task identifier, dynamically inserts a soft hint vector that matches the identifier. This allows the original query to receive semantic guidance specific to the task before encoding, thereby enhancing the target model's encoding representation of the query intent and improving the matching accuracy with document vectors. Simultaneously, since the document vector index is pre-built by the target model according to the original encoding method and remains unchanged throughout the entire query process, this method does not require rebuilding the existing vector index due to adjustments on the query side, significantly reducing the system overhead of index maintenance and updates. In summary, this solution achieves an effective balance between query accuracy and engineering cost by adapting soft hints on the query side while maintaining the stability of the index structure.

[0018] The data processing method provided in this application includes: obtaining multiple sets of corresponding query samples and document sample embedding vectors; inserting trainable soft cue vectors into each query sample to obtain optimized query samples; the document sample embedding vector is a pre-encoded vector of the corresponding document sample; encoding each optimized query sample using a target model to obtain a query sample embedding vector; calculating a loss based on the query sample embedding vector and the document sample embedding vector, and iteratively updating the trainable soft cue vector using the loss value to obtain a soft cue vector; wherein the soft cue vector is used to insert target query instructions to optimize the instructions, enabling the target model to perform document queries based on the optimized instructions.

[0019] As can be seen, the data processing method provided in this application obtains a soft suggestion vector, which is used to insert the target query instruction to optimize the instruction, enabling the target model to perform document queries based on the optimized instruction. During the generation of this soft suggestion vector, the document sample embedding vector uses a pre-encoded vector, which ensures the complete preservation of the original encoding baseline on the document side. Therefore, the constructed document vector index does not require any reconstruction or update operations after the soft suggestion vector is generated, maintaining its pre-built stable state. Simultaneously, this soft suggestion vector, as an independently configurable parameter, can flexibly integrate the target query instruction as needed during the query phase, adapting to the target model by adjusting the representation of the query input without modifying the model parameters or network structure of the target model. Thus, effective optimization of the query instruction is achieved without altering the existing index and model.

[0020] The apparatus, electronic equipment, and computer-readable storage medium provided in this application all have the aforementioned beneficial effects, which will not be repeated here. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the prior art and the embodiments of this application, the accompanying drawings used in the description of the prior art and the embodiments of this application will be briefly introduced below. Of course, the accompanying drawings described below with respect to the embodiments of this application are only a part of the embodiments in this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort, and such other drawings also fall within the protection scope of this application.

[0022] Figure 1 A flowchart illustrating a data query method provided in this application; Figure 2 A flowchart of sample processing based on a large language model is provided for this application; Figure 3 This application provides a schematic diagram of a training optimization principle in a low-resource scenario. Figure 4 This application provides a diagram of a multi-task hot-switching inference service architecture. Figure 5 A flowchart illustrating a data processing method provided in this application; Figure 6 A schematic diagram of the structure of a data query device provided in this application; Figure 7 A schematic diagram of the structure of a data processing device provided in this application; Figure 8 This is a schematic diagram of the structure of an electronic device provided in this application. Detailed Implementation

[0023] The core of this application is to provide a data query method that can effectively reduce the cost of data query while ensuring the accuracy of the data query results; another core aspect of this application is to provide a data query device, equipment, and computer-readable storage medium, which also have the above-mentioned beneficial effects.

[0024] To provide a clearer and more complete description of the technical solutions in the embodiments of this application, the technical solutions in the embodiments of this application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0025] This application provides a data query method.

[0026] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a data query method provided in this application, which may include the following steps S101 to S104.

[0027] S101. Receive the target query instruction and determine the task identifier of the target query instruction.

[0028] S102. Insert the soft hint vector that matches the task identifier into the target query instruction to obtain the optimized query instruction.

[0029] When a user inputs a target query command, the matching soft suggestion vector is inserted into the target query command to obtain an optimized query command.

[0030] In one embodiment of this application, inserting a soft hint vector into a target query instruction to obtain an optimized query instruction may include: determining the current data query domain based on the target query instruction; and inserting a soft hint vector that matches the current data query domain into the target query instruction to obtain an optimized query instruction.

[0031] Understandably, enterprise environments typically involve multiple different types of data query tasks (such as product knowledge bases, FAQs, technical document retrieval, security rule matching, etc.), and each type of data query task requires independent domain adaptation to effectively ensure the accuracy of data query results.

[0032] Currently, the traditional approach is to deploy a separate model service for each data query task, with resource consumption directly proportional to the number of tasks. To address this, this application proposes a "shared basic model + soft hint registry" implementation, a multi-task hot-swappable inference service architecture that uses soft hint vectors as data query task identifiers and a shared basic model as the unified computing core. Figure 4 As shown, Figure 4 The multi-task hot-switch inference service architecture provided in this application mainly includes: 1. Shared base model (large language model): loaded only once, all data query tasks share the same set of frozen model parameters; 2. Task soft prompt registry: maintains a mapping table from a data query task name to the corresponding soft prompt vector, with each set of soft prompts having a storage size of only about 32 KB; 3. Hot-switch module: when a query instruction for a data query task is received, only the corresponding soft prompt vector in the registry needs to be replaced with the query encoding path of the model, without reloading the model, and the switching overhead is less than 0.1 milliseconds; 4. Document encoding module: document encoding follows the standard path, that is, document encoding requests do not use any soft prompts and are completely consistent with the standard inference of the base model.

[0033] S103. Encode the optimized query command using the target model to obtain the query embedding vector.

[0034] The target model's functionality includes at least converting query commands into query embedding vectors, converting document data into document vectors, and matching query embedding vectors with document vectors. Specifically, the target model can be an embedding text model, a finely tuned LLM large language model, or other model types capable of performing the above functions.

[0035] For example, if the target model can be a large language model, the optimized query command can be encoded using the large language model to obtain the corresponding query embedding vector, which is the embedding vector of the domain-enhanced query command, so as to realize data query based on the query embedding vector.

[0036] S104. Match the query embedding vector with the pre-set document vector index to obtain the document data corresponding to the target document vector index, and use the document data as the query result corresponding to the target query instruction.

[0037] The document vector index is pre-built by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

[0038] This step aims to enable data querying based on query embedding vectors. Specifically, after obtaining the query embedding vector, it can be matched against a pre-configured document vector index. Since no modifications are made on the document side, this pre-configured document vector index can directly reuse the original full document vector index. Furthermore, through vector matching, a target document vector index that highly matches the query embedding vector can be obtained. The document data corresponding to this target document vector index is then the query result corresponding to the target query instruction.

[0039] The process of setting up a document vector index may include: obtaining all document data; encoding each document data using a large language model to obtain document embedding vectors; and constructing the corresponding document vector index based on the document embedding vectors. In other words, the process of building a document vector index is as follows: Figure 4 As shown in the Chinese document encoding module, you can encode the document using the original standard path.

[0040] Furthermore, in one embodiment of this application, a scheme for using an MLP projection head that decouples the training and inference phases is proposed. MLP (Multi-Layer Perceptron) refers to a linear + activation function transformation layer that is additionally connected after the embedding vector during training. It is used only during the training phase to enhance the learning signal and is not enabled during inference.

[0041] Based on this, after encoding each optimized query sample and each document sample using the large language model to obtain multiple sets of corresponding query sample embedding vectors and document sample embedding vectors, it may also include: performing vector transformation processing on the query sample embedding vectors and document sample embedding vectors through the MLP projection layer. Accordingly, loss calculation is performed based on the query sample embedding vector and the document sample embedding vector, and the trainable soft hint vector is iteratively updated using the loss value to obtain the soft hint vector. This may include: calculating loss based on the query sample embedding vector and the document sample embedding vector after vector transformation, and iteratively updating the trainable soft hint vector using the loss value to obtain the soft hint vector. Accordingly, the query embedding vector is matched with the pre-set document vector index to obtain the document data corresponding to the target document vector index as the query result corresponding to the target query instruction. This can include bypassing the MLP projection layer and directly matching the query embedding vector output by the large language model (based on the query embedding vector) with the pre-set document vector index to obtain the document data corresponding to the target document vector index as the query result corresponding to the target query instruction.

[0042] In one specific embodiment of this application, the document vector index setting process includes: Retrieve all document data; The target model is used to encode the document data to obtain document embedding vectors; Construct the corresponding document vector index based on the document embedding vector.

[0043] Therefore, based on the embodiments of this application, during the inference phase, the system automatically identifies the current inference mode, bypasses the MLP projection layer, and directly uses the original embedding vectors for similarity calculation. Clearly, this implementation balances training effectiveness and inference compatibility; that is, it leverages the projection layer to improve learning efficiency during training and reverts to the original embedding space during inference, allowing the established full document index to be directly reused without needing to be reconstructed due to the introduction of the projection layer.

[0044] The data query method provided in this application includes: receiving a target query instruction and determining the task identifier of the target query instruction; inserting a soft hint vector matching the task identifier into the target query instruction to obtain an optimized query instruction; encoding the optimized query instruction using a target model to obtain a query embedding vector; matching the query embedding vector with a pre-set document vector index to obtain the document data corresponding to the target document vector index and using the document data as the query result corresponding to the target query instruction; wherein, the document vector index is pre-constructed by the target model after encoding the full amount of document data according to the original encoding method, and remains unchanged during the data query process.

[0045] As can be seen, the data query method provided in this application, by receiving the target query instruction and determining its task identifier, dynamically inserts a soft hint vector that matches the identifier. This allows the original query to receive semantic guidance specific to the task before encoding, thereby enhancing the target model's encoding representation of the query intent and improving the matching accuracy with document vectors. Simultaneously, since the document vector index is pre-built by the target model according to the original encoding method and remains unchanged throughout the entire query process, this method does not require rebuilding the existing vector index due to adjustments on the query side, significantly reducing the system overhead of index maintenance and updates. In summary, this solution achieves an effective balance between query accuracy and engineering cost by adapting soft hints on the query side while maintaining the stability of the index structure.

[0046] This application provides a data processing method.

[0047] Please refer to Figure 5 , Figure 5 This is a flowchart illustrating a data processing method provided in this application, which may include the following steps S201 to S203.

[0048] S201: Obtain multiple sets of corresponding query sample and document sample embedding vectors, insert trainable soft hint vectors into each query sample, and obtain each optimized query sample.

[0049] Here, the document sample embedding vector is the pre-encoding vector of the corresponding document sample.

[0050] This step aims to acquire and optimize sample data. Understandably, in a retrieval system, queries and documents typically play different semantic roles. Queries are natural language questions from users, while documents represent domain-specific knowledge content; that is, queries are query instructions, and documents are query results, with a one-to-one correspondence. Based on this, multiple sets of corresponding query samples and document samples can be obtained, i.e., query-document sample pairs. For each query sample, a corresponding trainable soft prompt vector can be inserted to optimize the query sample, resulting in optimized query samples for each query sample. It should be noted that the trainable soft prompt vector is the soft prompt data to be trained. Soft prompts (or virtual tokens) are a set of trainable parameters that do not correspond to any real words but exist directly in the vector space. They are concatenated with the query text embedding and input into the model to guide the model's output. Essentially, they guide the data query instructions, facilitating domain-specific enhancement on the query side and achieving more accurate data retrieval. In this way, multiple sets of corresponding optimized query sample and document sample embedding vectors can be obtained, i.e., optimized query-document sample embedding vector pairs. Of course, the document sample embedding vectors on the document side are not modified to avoid the need to rebuild the entire document index due to changes in document-side encoding. This ensures that the original full document index can be reused directly in subsequent data queries, thereby effectively reducing costs.

[0051] In one embodiment of this application, inserting trainable soft cue vectors into each query sample to obtain optimized query samples may include: splitting the query sample into a query instruction segment and a query text segment; inserting trainable soft cue vectors between the query instruction segment and the query text segment to obtain optimized query samples.

[0052] This application provides a method for inserting trainable soft hint vectors into query samples. Currently, embedding models (such as Qwen3-Embedding) employ a query instruction-query text separation input format in their design. The native query encoding format is: [Instruct:] {task_instruction} [\nQuery:] {query_text}, where the Instruct part specifies the query task type (e.g., "generate a representation for this sentence to retrieve related articles", "retrieve semantically similar sentences", "retrieve paper titles based on keywords"), and the Query part is the actual query text. This design allows the model to adjust its encoding behavior according to different query task instructions. However, in vertical domain applications, this implementation method has the following technical drawbacks: 1. Limitations of fixed instructions: Predefined text instructions are trained on general corpora, making it difficult to capture the semantic features of specific domains; 2. Natural boundary between query instructions and query text: There is a clear semantic boundary between Instruction and Query, providing an ideal position for inserting learnable parameters; 3. Asymmetric requirements: In retrieval tasks, there is a gap in the semantic space between queries (short text, question form) and documents (long text, statement form). Furthermore, the document encoding capability of general embedding models is usually sufficient, while query-side Instructions typically represent complex business requirements. Therefore, it is not necessary to change the encoding methods of both queries and documents simultaneously; targeted domain enhancement can be performed only on the query side. Based on this, this application proposes that a set of learnable soft cue vectors can be inserted before the query text. These vectors do not correspond to any real words but are automatically learned during training to provide semantic guidance information most beneficial to domain retrieval; the document side remains completely unchanged, maintaining the encoding method entirely consistent with the original base model.

[0053] In the implementation, the sequence structure of the query input can be: [Instruct: ] [VT0,VT1,...,VTN-1] [\nQuery:querytext], where [Instruct:] is a fixed task prefix text (query instruction), which is converted into a vector and cached once during model loading. All subsequent queries can reuse this vector without repeated computation; it is frozen and not used in training. [VT0,VT1,...,VTN-1] are N trainable soft cue vectors, the only parameters that need to be trained. The number N can be flexibly configured according to the amount of task data. [\nQuery:querytext] is the original query text, which is also frozen and not used in training. Furthermore, for the document side, no soft cue or prefix modification is added, and the standard inference path of the base model is completely consistent.

[0054] Therefore, through the embodiments of this application: 1. Zero-cost reuse of document vector indexes is achieved, that is, the established document vector indexes do not need any reconstruction and can be directly used in conjunction with newly trained query-side soft hints, saving a lot of computing power and time costs for rebuilding the index; 2. Service decoupling is achieved, that is, the document encoding service and the query encoding service are independent of each other, and the updating and iteration of query-side soft hints do not affect the operation of the document side; 3. It is more in line with the natural division of labor in the retrieval system, because the query is a small amount of text entered by the user in real time (which requires a fast response), while the document is a large amount of pre-stored data (which can be processed offline). Therefore, optimizing only on the query side is naturally valid in engineering logic.

[0055] In one embodiment of this application, inserting trainable soft cue vectors into each query sample to obtain each optimized query sample may include: determining the target number of trainable soft cue vectors based on the number of annotations in the query sample; inserting the target number of trainable soft cue vectors into the query sample to obtain the optimized query sample.

[0056] As mentioned above, the number N of trainable soft cue vectors inserted into the query samples is not unique and can be flexibly configured according to the amount of task data. Based on this, this application further proposes a strategy for selecting the number of trainable soft cue vectors based on the amount of training data (the number of annotations in the query samples / document samples). The core principle is: the more trainable parameters there are, the more data is needed to support them; the less data there is, the stronger the constraints should be. For example, please refer to Table 1, which is a data scale adaptive configuration strategy table provided by this application embodiment.

[0057] Table 1. A data scale adaptive configuration strategy.

[0058] In addition, before inserting trainable soft cue vectors into each query sample to obtain each optimized query sample, the process may include: determining the data query domain to which the query sample and document sample belong; obtaining the descriptive text corresponding to the data query domain; and encoding the descriptive text using a large language model to obtain the initial values ​​of the trainable soft cue vectors.

[0059] Currently, traditional soft suggestion methods typically use random initialization for trainable vectors, assigning them a set of meaningless initial values ​​and then adjusting them to appropriate positions using training data. While this approach may converge when there is sufficient data, it presents significant problems in low-resource scenarios (e.g., fewer than 300 labeled data points): 1. Randomly initialized vectors have no semantic meaning, forcing the model to start from a state of "no knowledge" and learn the correct direction using limited training samples, often failing to reach the effective region due to insufficient data; 2. Starting from a random starting point requires a longer optimization path, which is precisely where low-resource scenarios have very few training steps; 3. Random vectors deviate from the semantic system established by the base model during pre-training, potentially triggering abnormal responses within the model.

[0060] Based on this, this application proposes an implementation method that uses the semantic vectors of the original instruction text in the target domain as the initial values ​​for the soft prompts. Specifically, a descriptive text that is semantically closest to the target query task (query sample) can be selected (e.g., for the legal domain, "retrieving paragraphs of judgment documents related to legal issues" can be selected). This text is then converted into a set of vectors through the word embedding layer of a large language model, and these vectors are directly used as the initial parameters for trainable soft prompts. In other words, the initial values ​​of the soft prompts should be in a meaningful semantic region, guiding the model's understanding from the outset rather than interfering with it. Thus, during training, these vectors can start from a reasonable semantic starting point and only require small adjustments to adapt to domain features, thereby significantly reducing the dependence on the amount of training data.

[0061] Therefore, through the embodiments of this application: 1. Semantic hot start is achieved, that is, soft prompts start from semantic points with practical significance, which are highly consistent with the pre-trained semantic system of the basic model; 2. The optimization path is significantly shortened, that is, under low resource conditions, a very small amount of training data can produce significant retrieval performance improvement; 3. Interpretability is greatly improved, that is, the training process can be intuitively understood as "gradually moving closer to domain semantics based on the original task description".

[0062] S202: Encode each optimized query sample using the target model to obtain the query sample embedding vector.

[0063] S203: Calculate the loss based on the query sample embedding vector and the document sample embedding vector, and use the loss value to iteratively update the trainable soft cue vector to obtain the soft cue vector.

[0064] Among them, soft suggestion vectors are used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

[0065] The above steps aim to achieve sample encoding and sample loss calculation based on the target model. Similar to the inference process, the target model's functions include at least converting query instructions into query embedding vectors, converting document data into document vectors, and matching query embedding vectors with document vectors. Specifically, the target model can be an embedding text model, a fine-tuned LLM large language model, or other model types capable of achieving the above functions.

[0066] For example, please refer to... Figure 2 , Figure 2 The sample processing flowchart provided in this application, based on a large language model, sequentially outputs each optimized query sample and each document sample to the large language model. The word embedding layer of the large language model, combined with L2 normalization, converts these samples into embedding vectors, resulting in embedding vectors q for each query sample and d for each document sample. Essentially, these are multiple sets of corresponding query and document embedding vectors. Then, based on cosine similarity matching sim(q, d), the loss is calculated on both vectors, and the loss value is used to iteratively update the trained soft suggestion vectors until the desired soft suggestion vectors are obtained, i.e., the trained soft suggestion vectors. It should be noted that during the soft suggestion training process, all parameters of the large language model remain completely frozen and do not require synchronous iterative updates.

[0067] In one embodiment of this application, loss calculation based on query sample embedding vector and document sample embedding vector may include: calculating a contrastive learning loss based on query sample embedding vector and document sample embedding vector; and superimposing the contrastive learning loss with the mean squared error regularization loss corresponding to the trainable soft cue vector to obtain a loss value.

[0068] Specifically, during training, for a batch of query-document sample pairs, the similarity between the query sample embedding vector (guided by soft cues) and the document sample embedding vector (without soft cues) can be calculated, and optimized using the InfoNCE contrastive loss. The intuitive meaning of this loss function is: for each query sample, make it as similar as possible to the corresponding positive sample document, while making it as dissimilar as possible to other irrelevant document samples in the batch. The formula for calculating the contrastive learning loss is as follows: ; in, Indicates the contrast learning loss. This represents the embedding vector of the i-th query sample. This represents the embedding vector of the j-th document sample. This represents the embedding vector of the i-th positive document sample. This indicates the number of embedding vectors for the positive document samples. This represents the number of explicit negative document sample embedding vectors. This indicates the number of document sample embedding vectors. This is the temperature coefficient.

[0069] Based on this, please refer to Figure 3 , Figure 3 This application provides a schematic diagram of a training optimization principle in low-resource scenarios. It is understood that even though the preceding embodiments employed semantic anchoring initialization, training in low-resource scenarios still faces another risk: overfitting. When training data is extremely limited, the finite gradient signal may push the soft cue vector into an over-specialized region, meaning it performs well on the training set but has extremely poor generalization ability to samples outside the training set. Based on this, this application proposes introducing an additional constraint term in addition to the contrastive learning loss to limit the deviation of the soft cue vector from the initial semantic anchor point during training. This constraint term can be calculated using mean squared error regularization loss, and its meaning is: soft cues are not allowed to go too far; that is, the model can perform domain adaptation within the semantic neighborhood of the original instruction, but cannot completely change the initial semantics due to overfitting of a small amount of training data. The corresponding calculation formula is as follows: ; ; in, Indicates the loss value. This represents the mean square error regularization loss. This represents the initial soft cue values ​​saved before training begins. This indicates the current soft suggestion value. This is the constraint strength coefficient, with a default value of 5000.

[0070] Clearly, when the semantic anchoring initialization scheme and mean squared error regularization loss in the previous embodiments are combined, a complete low-resource optimization strategy can be formed: the former can effectively ensure that the starting point is meaningful (i.e., starting from the semantic space of the original task description), while the latter can effectively ensure that the endpoint does not go astray (i.e., preventing overfitting to a narrow distribution on limited data). Together, they achieve the effect of "making small-step semantic fine-tuning based on the original task description", which is just right for low-resource domain adaptation scenarios.

[0071] Therefore, based on the embodiments of this application: during the training phase, before vector normalization, an additional projection layer of "linear transformation + activation function", namely MLP projection layer, is applied to the query and document embedding respectively to enhance the discriminativeness of the contrastive learning signal and make the training more stable and efficient.

[0072] The data processing method provided in this application includes: obtaining multiple sets of corresponding query samples and document sample embedding vectors; inserting trainable soft cue vectors into each query sample to obtain optimized query samples; the document sample embedding vector is a pre-encoded vector of the corresponding document sample; encoding each optimized query sample using a target model to obtain a query sample embedding vector; calculating a loss based on the query sample embedding vector and the document sample embedding vector, and iteratively updating the trainable soft cue vector using the loss value to obtain a soft cue vector; wherein the soft cue vector is used to insert target query instructions to optimize the instructions, enabling the target model to perform document queries based on the optimized instructions.

[0073] As can be seen, the data processing method provided in this application obtains a soft suggestion vector, which is used to insert the target query instruction to optimize the instruction, enabling the target model to perform document queries based on the optimized instruction. During the generation of this soft suggestion vector, the document sample embedding vector uses a pre-encoded vector, which ensures the complete preservation of the original encoding baseline on the document side. Therefore, the constructed document vector index does not require any reconstruction or update operations after the soft suggestion vector is generated, maintaining its pre-built stable state. Simultaneously, this soft suggestion vector, as an independently configurable parameter, can flexibly integrate the target query instruction as needed during the query phase, adapting to the target model by adjusting the representation of the query input without modifying the model parameters or network structure of the target model. Thus, effective optimization of the query instruction is achieved without altering the existing index and model.

[0074] Based on the above embodiments, this application provides a data query scheme for a specific application scenario, which can be applied to an intelligent retrieval system in the legal field.

[0075] First, the specific application scenario is as follows: A law firm wants to build an intelligent retrieval system for its internal knowledge base, enabling lawyers to quickly find relevant judgments, legal provisions, and case analyses through natural language queries. Existing general embedding models have the following problems: 1. When lawyers ask questions, they use professional terms such as "standards for determining breach of contract" and "conditions for the application of the contributory negligence principle," while the expressions in the document library ("determination of liability for breach of contract", "mixed fault") are semantically different from the search terms, resulting in the relevant documents being ranked lower. 2. There is a lack of labeled data in the legal field, with only about 150 manually labeled query-document relevance pairs; 3. A document vector index containing 500,000 legal documents has been established. Reconstructing it is costly (requiring approximately 8 hours of computation time), and we hope to reuse it as much as possible.

[0076] Furthermore, the specific implementation process of applying this technical solution to solve the above problems is as follows: 1. Prepare training data: Collect 150 labeled samples, each containing: a lawyer's real question (such as "How to determine if one party to a contract has committed a fundamental breach of contract") and the corresponding relevant judgment paragraph (positive sample) and irrelevant documents (negative sample).

[0077] 2. Configure soft suggestion parameters: Based on the data size (150 records, considered small-scale), select the parameters according to the configuration strategy in Table 1: (1) Number of soft cue vectors: 16; (2) Semantic initialization text: Select "Retrieve judgment documents and legal provisions related to legal issues" and convert them into initial soft cue vectors; (3) Constraint strength coefficient: 3000.

[0078] 3. Training soft cueing: With the Qwen3-Embedding-0.6B base model completely frozen, only 16×1024=16384 soft cueing parameters (approximately 64KB) were trained. The InfoNCE contrastive loss and MSE anchoring constraint were jointly optimized. The training took about 5 epochs and the entire training process took about 10 minutes (single GPU). The vector indices of all legal documents did not need to be modified.

[0079] 4. Deployment and Use: After the inference service is deployed: (1) When lawyers search for “how to determine if one party to a contract has committed a fundamental breach of contract”, the search text is guided by soft prompts and automatically moves toward the legal professional semantic space, significantly improving the similarity with the relevant paragraphs in the index on “determination of liability for breach of contract”. (2) The document encoding still follows the standard path, and there is no need to re-encode 500,000 documents; (3) The MRR@10 index of the search results is improved by about 10–14% compared with the general embedding model, which means that lawyers need to look at fewer documents on average to find the target content.

[0080] 5. Expand to multiple business scenarios: Assuming a law firm has three practice teams specializing in contract disputes, intellectual property, and criminal defense, each with different query styles and document library focuses, a multi-task hot-swap inference service architecture can be implemented by simply: (1) Train three sets of soft hints (approximately 32KB each) for the three business teams respectively; (2) Register three sets of soft hints in a unified inference service, sharing the same basic model; (3) Each team attaches its own task identifier when initiating a query, and the service dynamically loads the corresponding soft prompt.

[0081] At this point, the total video memory usage is approximately 1.2GB (base model) + 3 × 0.064MB ≈ 1.2GB, which is almost the same as deploying a single task.

[0082] This application provides a data query device.

[0083] The instruction receiving module 101 is used to receive the target query instruction and determine the task identifier of the target query instruction; The instruction optimization module 102 is used to insert the soft hint vector that matches the task identifier into the target query instruction to obtain the optimized query instruction; Vectorization module 103 is used to encode the optimized query command using the target model to obtain the query embedding vector; The query processing module 104 is used to match the query embedding vector with the pre-set document vector index to obtain the document data corresponding to the target document vector index as the query result corresponding to the target query instruction. The document vector index is pre-built by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

[0084] As can be seen, the data query apparatus provided in this application, by receiving a target query instruction and determining its task identifier, dynamically inserts a soft hint vector matching the identifier. This allows the original query to receive semantic guidance specific to the task before encoding, thereby enhancing the target model's encoding representation of the query intent and improving the matching accuracy with document vectors. Simultaneously, since the document vector index is pre-built by the target model according to the original encoding method and remains unchanged throughout the entire query process, this method does not require rebuilding the existing vector index due to adjustments on the query side, significantly reducing the system overhead of index maintenance and updates. In summary, this solution, while maintaining the stability of the index structure, achieves an effective balance between query accuracy and engineering cost through soft hint adaptation on the query side.

[0085] In one specific embodiment of this application, the document vector index setting process includes: Retrieve all document data; The target model is used to encode the document data to obtain document embedding vectors; Construct the corresponding document vector index based on the document embedding vector.

[0086] This application provides a data processing apparatus.

[0087] Please refer to Figure 7 , Figure 7 This application provides a schematic diagram of the structure of a data processing apparatus, which may include: The sample optimization module 201 is used to obtain multiple sets of corresponding query samples and document sample embedding vectors, insert trainable soft hint vectors into each query sample to obtain each optimized query sample; the document sample embedding vector is the pre-encoded vector of the corresponding document sample. The vector processing module 202 is used to encode each optimized query sample using the target model to obtain the query sample embedding vector. The training module 203 is used to calculate the loss based on the query sample embedding vector and the document sample embedding vector, and to iteratively update the trainable soft cue vector using the loss value to obtain the soft cue vector. Among them, soft suggestion vectors are used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

[0088] As can be seen, the data processing apparatus provided in this application uses the obtained soft suggestion vector to insert the target query instruction to optimize the instruction, enabling the target model to perform document queries based on the optimized instruction. During the generation of this soft suggestion vector, the document sample embedding vector uses a pre-encoded vector, which ensures the complete preservation of the original encoding baseline on the document side. Therefore, the constructed document vector index does not require any reconstruction or update after the soft suggestion vector is generated, maintaining its pre-built stable state. Simultaneously, as an independently configurable parameter, the soft suggestion vector can flexibly access the target query instruction as needed during the query phase, adapting to the target model by adjusting the representation of the query input without modifying the model parameters or network structure of the target model. Thus, effective optimization of the query instruction is achieved without changing the existing index and model.

[0089] In one embodiment of this application, the sample optimization module is specifically used to split the query sample into a query instruction segment and a query text segment; and to insert a trainable soft cue vector between the query instruction segment and the query text segment to obtain an optimized query sample.

[0090] In one embodiment of this application, the sample optimization module is specifically used to determine the target number of trainable soft cue vectors based on the number of annotations in the query sample; and to insert the target number of trainable soft cue vectors into the query sample to obtain an optimized query sample.

[0091] In one embodiment of this application, it further includes an initial value setting module, used to insert trainable soft cue vectors into each query sample and, before obtaining each optimized query sample, determine the data query domain to which the query sample and document sample belong; obtain descriptive text corresponding to the data query domain; and encode the descriptive text using the target model to obtain the initial value of the trainable soft cue vector.

[0092] In one embodiment of this application, the training module is specifically used to calculate the contrastive learning loss based on the query sample embedding vector and the document sample embedding vector; and to superimpose the contrastive learning loss with the loss corresponding to the trainable soft cue vector to obtain the loss value.

[0093] For a description of the apparatus provided in the embodiments of this application, please refer to the above method embodiments; further details will not be repeated here.

[0094] This application provides an electronic device.

[0095] Please refer to Figure 8 , Figure 8 This application provides a schematic diagram of the structure of an electronic device, which may include: Memory 11 is used to store computer programs; The processor 10 is configured to execute computer programs and implement the steps of any of the data query methods or data processing methods described above.

[0096] like Figure 8 The diagram shows the structural composition of an electronic device, which may include a processor 10, a memory 11, a communication interface 12, and a communication bus 13. The processor 10, memory 11, and communication interface 12 all communicate with each other through the communication bus 13.

[0097] In this embodiment, the processor 10 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic devices.

[0098] The processor 10 can call the program stored in the memory 11. Specifically, the processor 10 can execute the operations in the embodiment of the data query method.

[0099] The memory 11 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment, the memory 11 stores at least a program for implementing the following functions: The system receives the target query instruction and determines its task identifier. It inserts a soft hint vector matching the task identifier into the target query instruction to obtain an optimized query instruction. The optimized query instruction is then encoded using the target model to obtain a query embedding vector. This query embedding vector is matched with a pre-set document vector index to obtain the document data corresponding to the target document vector index, which is then used as the query result for the target query instruction. The document vector index is pre-constructed by the target model after encoding all document data using the original encoding method, and remains unchanged during the data query process.

[0100] Alternatively, multiple sets of corresponding query sample and document sample embedding vectors are obtained. A trainable soft cue vector is inserted into each query sample to obtain optimized query samples. The document sample embedding vector is the pre-encoded vector of the corresponding document sample. The target model is used to encode each optimized query sample to obtain the query sample embedding vector. The loss is calculated based on the query sample embedding vector and the document sample embedding vector, and the trainable soft cue vector is iteratively updated using the loss value to obtain the soft cue vector. The soft cue vector is used to insert the target query instruction to optimize the instruction, so that the target model performs document queries based on the optimized instruction.

[0101] In one possible implementation, the memory 11 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; and the data storage area may store data created during use.

[0102] In addition, memory 11 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.

[0103] Communication interface 12 can be an interface for the communication module, used to connect with other devices or systems.

[0104] Of course, it should be noted that, Figure 6 The structure shown does not constitute a limitation on the electronic device in the embodiments of this application. In practical applications, the electronic device may include more than Figure 6 More or fewer components as shown, or combinations of certain components.

[0105] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the steps of any of the data query methods or data processing methods described above.

[0106] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0107] For a description of the computer-readable storage medium provided in this application, please refer to the above method embodiments; further details will not be repeated here.

[0108] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.

[0109] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0110] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0111] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.

Claims

1. A data query method, characterized by, include: Receive the target query instruction and determine the task identifier of the target query instruction; The soft hint vector that matches the task identifier is inserted into the target query instruction to obtain the optimized query instruction; The optimized query command is encoded using the target model to obtain a query embedding vector. The query embedding vector is matched with a pre-set document vector index to obtain the document data corresponding to the target document vector index, and the document data is used as the query result corresponding to the target query instruction. The document vector index is pre-constructed by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

2. The method of claim 1, wherein, The document vector index setup process includes: Retrieve all document data; The target model is used to encode each document data to obtain a document embedding vector. Construct a corresponding document vector index based on the document embedding vector.

3. A data processing method, characterized by, include: Obtain multiple sets of corresponding query sample and document sample embedding vectors, insert trainable soft hint vectors into each query sample, and obtain each optimized query sample; The document sample embedding vector is the pre-encoded vector of the corresponding document sample; The target model is used to encode each of the optimized query samples to obtain the query sample embedding vector; Loss is calculated based on the query sample embedding vector and the document sample embedding vector, and the trainable soft cue vector is iteratively updated using the loss value to obtain the soft cue vector. The soft suggestion vector is used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

4. The method of claim 3, wherein, Trainable soft cue vectors are inserted into each of the aforementioned query samples to obtain optimized query samples, including: The query sample is split into a query command segment and a query text segment; The trainable soft cue vector is inserted between the query instruction segment and the query text segment to obtain the optimized query sample.

5. The method according to claim 3, characterized in that, Trainable soft cue vectors are inserted into each of the aforementioned query samples to obtain optimized query samples, including: The target number of trainable soft cue vectors is determined based on the number of annotations in the query sample. The target number of trainable soft cue vectors are inserted into the query sample to obtain the optimized query sample.

6. The method according to any one of claims 3 to 5, characterized in that, Before inserting trainable soft cue vectors into each of the aforementioned query samples to obtain optimized query samples, the process further includes: Determine the data query domain to which the query sample and the document sample belong; Obtain the descriptive text corresponding to the data query domain; The descriptive text is encoded using the target model to obtain the initial value of the trainable soft cue vector.

7. The method of claim 3, wherein, Loss calculation is performed based on the query sample embedding vector and the document sample embedding vector, including: The contrastive learning loss is calculated based on the query sample embedding vector and the document sample embedding vector. The loss value is obtained by superimposing the contrastive learning loss on the loss corresponding to the trainable soft cue vector.

8. A data query apparatus, characterized by comprising: include: The instruction receiving module is used to receive the target query instruction and determine the task identifier of the target query instruction; The instruction optimization module is used to insert a soft hint vector that matches the task identifier into the target query instruction to obtain the optimized query instruction; The vectorization module is used to encode the optimized query command using the target model to obtain a query embedding vector; The query processing module is used to match the query embedding vector with a pre-set document vector index to obtain the document data corresponding to the target document vector index as the query result corresponding to the target query instruction. The document vector index is pre-constructed by the target model after encoding all document data according to the original encoding method, and remains unchanged during the data query process.

9. A data processing apparatus, characterized by include: The sample optimization module is used to obtain multiple sets of corresponding query samples and document sample embedding vectors, insert trainable soft hint vectors into each query sample, and obtain each optimized query sample; the document sample embedding vector is the pre-encoded vector of the corresponding document sample; The vector processing module is used to encode each of the optimized query samples using the target model to obtain the query sample embedding vector; The training module is used to calculate the loss based on the query sample embedding vector and the document sample embedding vector, and to iteratively update the trainable soft cue vector using the loss value to obtain the soft cue vector. The soft suggestion vector is used to insert target query instructions to optimize the instructions, so that the target model can perform document queries based on the optimized instructions.

10. An electronic device, comprising: include: Memory, used to store computer programs; A processor, configured to implement the steps of the data query method as described in claim 1 or 2 when executing the computer program, and / or to implement the steps of the data processing method as described in any one of claims 3 to 7.

11. A computer readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the data query method as described in claim 1 or 2, and / or the steps of the data processing method as described in any one of claims 3 to 7.