Model accelerated reasoning method in PostgreSQL database based on Mvec vector type

By constructing the Mvec tensor type in the PostgreSQL database, the problem of database extensions being unable to retain shape metadata is solved, achieving efficient storage and querying, avoiding redundant calculations, and improving system performance and data management efficiency.

CN120930780APending Publication Date: 2025-11-11COMPUTER INNOVATION TECH RES INST OF ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510983947.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-11-11

AI Technical Summary

Technical Problem

The existing database extensions cannot retain enough shape metadata, resulting in inefficient data processing, repeated calculation of embedding vectors, and impact on system performance, especially with large-scale data and high-concurrency queries.

Method used

In a PostgreSQL database, an Mvec tensor type is constructed to convert data into Mvec tensors and train an inference model. Data is stored and managed through the Mvec tensor type, supporting efficient storage and querying and avoiding redundant calculations.

Benefits of technology

By applying the Mvec tensor type, direct data reuse is achieved, reducing computational overhead, improving system response speed and throughput, maintaining data integrity, and reducing storage redundancy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120930780A_ABST
    Figure CN120930780A_ABST
Patent Text Reader

Abstract

The invention discloses an accelerated reasoning method for a model in a PostgreSQL (Structured Query Language) database based on an Mvec vector type. The method comprises the following steps: firstly, obtaining a plurality of task data sets, and constructing a plurality of reasoning models in a PostgreSQL database; secondly, constructing an Mvec tensor type in a PostgreSQL database, converting all task data sets into the Mvec tensor type to obtain a corresponding converted Mvec tensor, and training each reasoning model according to the converted Mvec tensor to obtain all trained reasoning models; and finally, acquiring to-be-tested input data and the specific name of the inference model which needs to be trained for the to-be-tested input data in real time, performing query processing on the to-be-tested input data in the PostgreSQL database, and performing inference on the inference model which needs to be trained according to a query result and the specific name of the inference model which needs to be trained for the to-be-tested input data to obtain an inference result. The Mvec tensor type designed by the invention is combined with an efficient storage structure in a database, so that large-scale data can be processed, and meanwhile, the throughput and expandability of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the fields of database systems and deep learning inference acceleration, and specifically relates to a method for accelerating inference based on a Postgres database model using the Mvec vector type. Background Technology

[0002] In traditional multimodal data processing and inference pipelines, whenever the system receives a query request, regardless of whether the query involves images, text, or other modalities of data, the system first needs to perform embedding processing on this data. The embedding process typically uses pre-trained deep learning models (such as BERT, ResNet, etc.) to convert the raw data into high-dimensional vector representations that capture the semantic features of the data. Subsequently, the system inputs these embedded vectors into a specific inference model for further analysis and processing, such as classification, detection, or generation tasks.

[0003] However, this traditional approach suffers from significant efficiency issues. First, the embedding vector needs to be recalculated for each query, even when repeatedly analyzing the same dataset. This repetitive computation not only wastes computational resources but also increases system response time, especially when handling large-scale data or high-concurrency queries, where system performance degrades significantly. Second, as the amount of data and task complexity increase, the embedding computation and inference process may become the bottleneck of the system, leading to overall low processing efficiency.

[0004] Existing database extensions (such as the pgvector extension for PostgreSQL) have some limitations when handling embedded vectors. First, these extensions typically only support simple vector storage and retrieval, without preserving sufficient shape metadata. Shape metadata refers to information describing the dimensions, structure, and other relevant properties of a vector, which is crucial for efficiently storing and processing multidimensional tensors (such as image, video, or complex text embeddings). The lack of shape metadata limits a database's ability to handle complex data structures, potentially leading to inefficient storage and degraded query performance. Summary of the Invention

[0005] To address the problems existing in the background technology, this invention provides a method for accelerating inference of PostgreSQL database models based on Mvec vector types. This method solves the technical problems in the prior art where database expansion cannot retain sufficient shape metadata, thus affecting the speed of data inference in the database model and the repeated calculation of embedded vectors.

[0006] The technical solution adopted in this invention includes:

[0007] I. A method for accelerating inference using PostgreSQL database models based on Mvec vector types:

[0008] S1. Obtain several task datasets and build several inference models within a PostgreSQL database.

[0009] S2. Construct the Mvec tensor type in the PostgreSQL database, convert all task datasets into the Mvec tensor type, obtain the corresponding converted Mvec tensors, train each inference model based on the converted Mvec tensors, and obtain all trained inference models.

[0010] S3. In real time, obtain the input data to be tested and the specific name of the inference model that needs to be trained for the input data. Query the input data to be tested in the PostgreSQL database. Based on the query results and the specific name of the inference model required for the input data, perform inference on the inference model that needs to be trained to obtain the inference result.

[0011] The task dataset includes image datasets and text datasets. Each task dataset mainly consists of several input data and a label corresponding to each input data. The inference model is a deep learning model.

[0012] Step S2 specifically involves:

[0013] S21. Construct the Mvec tensor type in the PostgreSQL database.

[0014] S22. Use a pre-trained deep learning model to convert the input data in each task dataset into PyTorch tensor form, and obtain the PyTorch tensor of the input data in each task dataset.

[0015] S23. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data in each task dataset into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data in each task dataset.

[0016] S24. Store the Mvec tensor of the input data in each task dataset and the corresponding labels of the input data in a PostgreSQL database.

[0017] S25. Each inference model selects all the required input data from all task datasets, obtains the Mvec tensor of all input data and the label corresponding to each input data in the PostgreSQL database, and trains the corresponding inference model based on the obtained Mvec tensor of all input data and the label corresponding to each input data, thereby obtaining each trained inference model.

[0018] The Mvec tensor type includes a contiguous shape array and a data array; the shape array stores the dimension information of the PyTorch tensor, and the data array stores the elements of the PyTorch tensor in row-major order.

[0019] Step S3 specifically involves:

[0020] S31. Real-time acquisition of the input data to be tested and the specific name of the inference model that needs to be trained to complete the input data to be tested.

[0021] S32. In the PostgreSQL database, check if the Mvec tensor corresponding to the input data to be tested exists:

[0022] If it exists, the Mvec tensor corresponding to the input data to be tested will be input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested.

[0023] If it does not exist, the Mvec tensor transformation is performed on the input data to be tested to obtain the Mvec tensor corresponding to the input data to be tested. Then, the obtained Mvec tensor corresponding to the input data to be tested is input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested.

[0024] The Mvec tensor transformation process specifically includes the following steps:

[0025] D1. Use a pre-trained deep learning model to convert the input data to be tested into PyTorch tensor form to obtain the PyTorch tensor of the input data to be tested.

[0026] D2. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data to be tested into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data to be tested, and store it in the PostgreSQL database.

[0027] II. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described method.

[0028] 3. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described method.

[0029] IV. A computer program product, comprising a computer program / instructions, characterized in that the computer program / instructions, when executed by a processor, implement the steps of the above-described method.

[0030] The beneficial effects of this invention are:

[0031] 1. The generated Mvec tensor is stored in the database, which can be directly reused in subsequent queries, thereby avoiding repeated calculations. This not only significantly reduces computational overhead but also improves the system's response speed.

[0032] 2. By storing data using the Mvec tensor type, not only is sufficient shape metadata preserved, but multidimensional tensor data can also be managed efficiently, thus maintaining data integrity while reducing storage redundancy.

[0033] 3. The Mvec tensor type designed in this invention, combined with the efficient storage structure within the database, enables the processing of large-scale data while improving the system's throughput and scalability. Attached Figure Description

[0034] Figure 1 This is a flowchart of the method of the present invention.

[0035] Figure 2 The flowchart shows how to input the Mvec tensor into the inference model that needs to be trained for inference. Detailed Implementation

[0036] The present invention will now be described in more detail with reference to the accompanying drawings and embodiments. However, the present invention is not limited thereto. For those skilled in the art, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention. Contents not described in detail in this specification are prior art known to those skilled in the art.

[0037] like Figure 1 As shown in the figure, the method for accelerating inference based on the Mvec vector type in a PostgreSQL database includes the following steps:

[0038] S1. Obtain several task datasets and build several inference models in a PostgreSQL database on the computer.

[0039] The task datasets include image datasets and text datasets. Each task dataset mainly consists of several input data sets and corresponding labels for each input data set. The inference model is a deep learning model.

[0040] The image dataset includes image datasets from several different scenes; the text dataset includes text datasets from several different scenes.

[0041] In practice, a corresponding inference model is built for each image dataset or text dataset of a specific scenario.

[0042] In practice, the number of task datasets acquired and the number of inference models built are unrelated. An inference model can use all the data from a single task dataset, all the data from multiple task datasets, or a subset of data from multiple datasets. Each inference model can be selected based on the user's needs during training.

[0043] S2. Construct an Mvec (Multi-dimensional Vector) tensor type in the PostgreSQL database, convert all task datasets into Mvec tensor types, obtain the corresponding converted Mvec tensors, train each inference model based on the converted Mvec tensors, and obtain all trained inference models.

[0044] S21. Construct the Mvec tensor type in the PostgreSQL database.

[0045] S22. Use a pre-trained deep learning model to convert the input data in each task dataset into PyTorch tensor form, and obtain the PyTorch tensor of the input data in each task dataset.

[0046] Pre-trained deep learning models include ResNet, VGG, EfficientNet, MobileNet, BERT, GPT, Transformer, LSTM, GRU, Inception, AlexNet, DenseNet, YOLO, Faster R-CNN, UNet, StyleGAN, WaveNet, ResNeXt, SqueezeNet, and Vision Transformer.

[0047] S23. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data in each task dataset into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data in each task dataset.

[0048] S24. Store the Mvec tensor of the input data in each task dataset and the corresponding labels of the input data in a PostgreSQL database.

[0049] S25. Each inference model selects all the required input data from all task datasets, obtains the Mvec tensor of all input data and the label corresponding to each input data in the PostgreSQL database, and trains the corresponding inference model based on the obtained Mvec tensor of all input data and the label corresponding to each input data, thereby obtaining each trained inference model.

[0050] The Mvec tensor type includes contiguous shape arrays and data arrays; the shape array stores the dimensional information of the PyTorch tensor (such as the number of channels, height, and width), and the data array stores the elements of the PyTorch tensor in row-major order (flattened into a one-dimensional array).

[0051] This representation format preserves the dimensional information and data content of PyTorch tensors, supporting efficient storage and fast querying.

[0052] like Figure 2 As shown, S3: Real-time acquisition of the input data to be tested and the specific name of the inference model to be trained for the input data to be tested; querying the input data to be tested in the PostgreSQL database; and performing inference on the inference model to be trained based on the query results and the specific name of the inference model to be trained for the input data to be tested, thereby obtaining the inference result.

[0053] S31. Real-time acquisition of the input data to be tested and the specific name of the inference model that needs to be trained to complete the input data to be tested.

[0054] S32. In the PostgreSQL database, check if the Mvec tensor corresponding to the input data to be tested exists:

[0055] If it exists, the Mvec tensor corresponding to the input data to be tested will be input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested.

[0056] If it does not exist, the Mvec tensor transformation is performed on the input data to be tested to obtain the Mvec tensor corresponding to the input data to be tested. Then, the obtained Mvec tensor corresponding to the input data to be tested is input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested.

[0057] The Mvec tensor transformation process specifically includes the following steps:

[0058] D1. Use a pre-trained deep learning model to convert the input data to be tested into PyTorch tensor form to obtain the PyTorch tensor of the input data to be tested.

[0059] In practice, if the input data to be tested is a 32×32 pixel image, the ResNet network is used to convert the image into a PyTorch tensor with a shape of (3, 224, 224), which is specifically represented as a 3-channel, 224×224 image tensor.

[0060] Pre-trained deep learning models include ResNet, VGG, EfficientNet, MobileNet, BERT, GPT, Transformer, LSTM, GRU, Inception, AlexNet, DenseNet, YOLO, Faster R-CNN, UNet, StyleGAN, WaveNet, ResNeXt, SqueezeNet, and Vision Transformer.

[0061] D2. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data to be tested into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data to be tested, and store it in the PostgreSQL database.

[0062] In practice, the PyTorch tensor is converted to the Mvec tensor type. The resulting Mvec tensor of the input data to be tested is a shape array [3, 224, 224] and a data array [0.1, 0.2, 0.3, ..., 0.9] (assuming that the elements of the tensor are floating-point numbers).

[0063] This invention uses the generated Mvec tensor stored in the database, enabling direct reuse in subsequent queries, thereby avoiding redundant calculations. This not only significantly reduces computational overhead but also improves the system's response speed.

[0064] This invention stores data using the Mvec tensor type, which not only preserves sufficient shape metadata but also efficiently manages multidimensional tensor data, thus maintaining data integrity while reducing storage redundancy.

[0065] The above embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention. The scope of protection of the present invention is defined by the claims.

Claims

1. A method for accelerating inference based on Mvec vector type in a PostgreSQL database model, characterized in that, Includes the following steps: S1. Obtain several task datasets and build several inference models within a PostgreSQL database; S2. Construct the Mvec tensor type in the PostgreSQL database, convert all task datasets into the Mvec tensor type, obtain the corresponding converted Mvec tensors, train each inference model based on the converted Mvec tensors, and obtain all trained inference models. S3. In real time, obtain the input data to be tested and the specific name of the inference model that needs to be trained for the input data. Query the input data to be tested in the PostgreSQL database. Based on the query results and the specific name of the inference model required for the input data, perform inference on the inference model that needs to be trained to obtain the inference result.

2. The method for accelerating inference based on the Mvec vector type in a PostgreSQL database model according to claim 1, characterized in that: The task dataset includes image datasets and text datasets. Each task dataset mainly consists of several input data and a label corresponding to each input data. The inference model is a deep learning model.

3. The method for accelerating inference based on the Mvec vector type in a PostgreSQL database model according to claim 1, characterized in that, Step S2 specifically involves: S21. Construct the Mvec tensor type in the PostgreSQL database; S22. Use a pre-trained deep learning model to convert the input data in each task dataset into PyTorch tensor form, and obtain the PyTorch tensor of the input data in each task dataset. S23. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data in each task dataset into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data in each task dataset. S24. Store the Mvec tensor of the input data in each task dataset and the corresponding labels of the input data in a PostgreSQL database; S25. Each inference model selects all the required input data from all task datasets, obtains the Mvec tensor of all input data and the label corresponding to each input data in the PostgreSQL database, and trains the corresponding inference model based on the obtained Mvec tensor of all input data and the label corresponding to each input data, thereby obtaining each trained inference model.

4. The method for accelerating inference based on the Mvec vector type in a PostgreSQL database model according to claim 1, characterized in that: The Mvec tensor type includes a contiguous shape array and a data array; the shape array stores the dimension information of the PyTorch tensor, and the data array stores the elements of the PyTorch tensor in row-major order.

5. The method for accelerating inference based on the Mvec vector type in a PostgreSQL database model according to claim 1, characterized in that, Step S3 specifically involves: S31. Real-time acquisition of the input data to be tested and the specific name of the inference model that needs to be trained to complete the input data to be tested; S32. In the PostgreSQL database, check if the Mvec tensor corresponding to the input data to be tested exists: If it exists, the Mvec tensor corresponding to the input data to be tested will be input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested. If it does not exist, the Mvec tensor transformation is performed on the input data to be tested to obtain the Mvec tensor corresponding to the input data to be tested. Then, the obtained Mvec tensor corresponding to the input data to be tested is input into the inference model that needs to be trained to perform inference and obtain the inference result of the input data to be tested.

6. The method for accelerating inference based on the Mvec vector type in a PostgreSQL database model according to claim 5, characterized in that, The Mvec tensor transformation process specifically includes the following steps: D1. Use a pre-trained deep learning model to convert the input data to be tested into PyTorch tensor form to obtain the PyTorch tensor of the input data to be tested. D2. Based on the constructed Mvec tensor type, convert the PyTorch tensor of the input data to be tested into the Mvec tensor type, thereby obtaining the Mvec tensor of the input data to be tested, and store it in the PostgreSQL database.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method described in any one of claims 1 to 6.