Data protection method, system, database, equipment, product and storage medium
By vector encryption of text fragments in RAG scenes locally on the client and using a maintainable vector encryption algorithm, the risk of user data leakage in the cloud is solved, and efficient data protection and retrieval functions are achieved.
Patent Information
- Application Number
- CN202411850065.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2044-12-13
AI Technical Summary
In the Retrieval Enhanced Generation (RAG) scenario, how to protect the security of user private data and prevent the risk of data leakage, especially in a multi-tenant cloud environment.
The text fragments of the searched file are encrypted locally on the client, and the insulated vector encryption algorithm is used to ensure that the encrypted vectors still maintain a relative distance, thus supporting vector retrieval and recall in the cloud.
It effectively prevents the risk of user data leakage in the cloud, and supports similarity retrieval, without affecting sorting and recall, reducing implementation costs.
Smart Images

Figure CN119337405B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of large model technology, and in particular to data protection methods, systems, databases, devices, products and storage media. Background Art
[0002] Retrieval-Augmented Generation (RAG) has become one of the hottest directions for large model applications in recent years. Many manufacturers are developing large model applications based on RAG. In the RAG scenario, since the construction requires users to store their private knowledge base in the vector database in the form of document slices, how to protect the security of users' private data has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] To overcome the problems existing in the related art, the embodiments of this specification provide data protection methods, systems, databases, devices, products and storage media.
[0004] According to a first aspect of an embodiment of this specification, a data protection method in a RAG is provided, the method being applied to a client, the method comprising:
[0005] Obtaining a file to be searched, wherein the file to be searched includes a text segment;
[0006] Based on the user key of the user and the order-preserving vector encryption algorithm, encrypt the vector corresponding to the text segment to obtain the encrypted vector and send it to the cloud, so that the cloud stores the encrypted vector in the database of the user;
[0007] In response to receiving a question text of the user to the question-answering model, obtaining a question vector of the question text and encrypting it using the user key and the vector encryption algorithm, obtaining the encrypted question vector and sending it to the cloud, so that the cloud retrieves a similar encrypted vector similar to the encrypted question vector from the database;
[0008] A similar text segment corresponding to the similar encrypted vector is obtained, and the similar text segment is used to enable the question-answering model to generate a reply.
[0009] According to a second aspect of an embodiment of this specification, a data protection method in a RAG is provided, the method comprising:
[0010] Obtaining a file to be searched, wherein the file to be searched includes a text segment;
[0011] Based on the user's user key and an order-preserving vector encryption algorithm, encrypt the vector corresponding to the text segment to obtain an encrypted vector, and store the encrypted vector in the user's database;
[0012] In response to receiving a question text of a user to a question-answering model, obtaining a question vector of the question text and encrypting it using the user key and the vector encryption algorithm to obtain an encrypted question vector, and retrieving a similar encrypted vector similar to the encrypted question vector from the database;
[0013] A similar text segment corresponding to the similar encrypted vector is obtained, and the similar text segment is used to enable the question-answering model to generate a reply.
[0014] According to a third aspect of an embodiment of this specification, a data protection system in a RAG is provided, the system comprising a client and a cloud, the client being used to execute the steps of the method described in the first aspect, the cloud being used to store an encrypted vector sent by the client into a vector database of a user after receiving the encrypted vector, and to retrieve a similar encrypted vector similar to the encrypted question vector after receiving the encrypted question vector.
[0015] According to a fourth aspect of an embodiment of this specification, a database in a RAG is provided, wherein the database stores encryption vectors provided by a user's client, the client is used to execute the steps of the method described in the first aspect, and the database is also used for the cloud to retrieve similar encryption vectors similar to the encrypted question vector after receiving the encrypted question vector.
[0016] According to a fifth aspect of the embodiments of this specification, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method embodiment described in the first aspect are implemented.
[0017] According to a sixth aspect of the embodiments of this specification, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method embodiment described in the first aspect are implemented.
[0018] According to a seventh aspect of the embodiments of this specification, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps of the method embodiment described in the first aspect are implemented.
[0019] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0020] In the embodiment of this specification, it is designed to encrypt the vectors of each text fragment of the file to be retrieved locally on the client, and the encrypted vector is provided to the cloud. The cloud stores the user ciphertext data provided by the client, so there is no risk of leakage of user data in the cloud. The vector encryption is implemented by an order-preserving vector encryption algorithm. In this way, the encrypted encrypted vector still maintains the relative distance between the plaintext vectors, so that the cloud database can be used for vector retrieval and recall in the RAG scenario; when the user asks a question to the question-answering model, the client provides the cloud with an encrypted question vector, and the cloud can retrieve similar encrypted vectors similar to the encrypted question vector from the database. Therefore, the cloud stores the user ciphertext data provided by the client, so there is no risk of leakage of user data in the cloud. While vector encryption is still supported, similarity retrieval will not affect sorting and recall. Under the condition of ensuring data security, for the cloud, the storage and retrieval of vectors are no different from existing solutions. The cloud does not need to use an additional hardware trusted execution environment or code modification, and the implementation cost of the solution is low.
[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1A It is a flowchart of a data protection method in the aforementioned RAG shown in this specification according to an exemplary embodiment.
[0023] Figure 1B It is a schematic diagram of a data protection system in a RAG shown in this specification according to an exemplary embodiment.
[0024] Figure 2A It is a schematic diagram of a client constructing an encryption vector according to an exemplary embodiment of this specification.
[0025] Figure 2B It is a schematic diagram of retrieving similar encrypted vectors according to an exemplary embodiment of the present specification.
[0026] Figure 2C It is a schematic diagram of data protection in RAG according to an exemplary embodiment of this specification.
[0027] Figure 3 It is a schematic diagram of another data protection method in RAG shown in this specification according to an exemplary embodiment.
[0028] Figure 4 It is a hardware structure diagram of a computer device where a data protection device in the aforementioned RAG is located according to an exemplary embodiment shown in this specification.
[0029] Figure 5It is a block diagram of a data protection device in the aforementioned RAG shown in this specification according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0031] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0032] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0033] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0034] Currently, RAG applications generally follow the following process:
[0035] 1. Slice the user's files to be retrieved;
[0036] 2. Each fragment obtained after slicing can be converted into a digital vector by calling the embedding model and stored in the vector database;
[0037] 3. When users use the large model, the questions they ask are also converted into digital vectors using the embedding model;
[0038] 4. In the vector database, based on the user's question vector, retrieve the most relevant set of vectors and corresponding text fragments, which are the context information related to the user's question;
[0039] 5. The retrieved relevant context information and the user's question content are combined into a suitable prompt and the large model is called;
[0040] 6. The large model returns the answer to the question based on the prompt.
[0041] For cloud vendors, if they want to commercialize RAG services, they need to deal with multi-tenant scenarios. Since users need to upload private documents to the cloud platform, the cloud platform executes the above processes 2 to 3 to build the user's vector database. Once the platform has security vulnerabilities such as unauthorized access and privilege escalation, the user's private data is at risk of leakage. In particular, in a multi-tenant scenario, the cloud platform uses the vector databases of each user, which may be stored in the same cluster, and there is a risk that the user's vector database may be accessed by other users without authorization.
[0042] Common data security protection usually uses hardware-level trusted execution environments such as SGX, TDX, and SEV to improve the security level. The introduction of hardware trusted execution environments and frequent encryption and decryption operations will affect the performance of encrypted data storage to a certain extent. In addition, encrypted data storage requires the modification of the code of the data storage service itself. For different data storage services (such as Elasticsearch, MySQL, PostgreSQL, Redis, etc.), adaptation and development are required, which is a large workload.
[0043] Based on this, the embodiment of this specification provides a data protection method in RAG, which can ensure the security of user data and significantly reduce the risk of leakage of user data. Next, the embodiment of this specification is described in detail.
[0044] like Figure 1A As shown, Figure 1A This is a flow chart of a data protection method in a RAG according to an exemplary embodiment of the present specification, comprising the following steps:
[0045] In step 102, a file to be searched is obtained, where the file to be searched includes a plurality of text segments.
[0046] In step 104, based on the user key of the user and the order-preserving vector encryption algorithm, the vector corresponding to the text segment is encrypted, and the obtained encrypted vector is sent to the cloud, so that the cloud stores the encrypted vector in the vector database of the user.
[0047] In step 106, in response to receiving the user's question text for the question-answering model, a question vector of the question text is obtained and encrypted using the user key and the vector encryption algorithm to obtain the encrypted question vector and send it to the cloud, so that the cloud can retrieve a similar encrypted vector similar to the encrypted question vector from the vector database.
[0048] In step 108, similar text segments corresponding to the similar encrypted vectors are obtained. The similar text segments are used to enable the question-answering model to generate a response.
[0049] In the scheme of this embodiment, it is designed to encrypt the vectors of each text fragment of the file to be retrieved locally on the client, and the encrypted vector is provided to the cloud. The cloud stores the user ciphertext data provided by the client, so there is no risk of leakage of user data in the cloud. The vector encryption is implemented by an order-preserving vector encryption algorithm. In this way, the encrypted vector still maintains the relative distance between the plaintext vectors, so that the cloud database can be used for vector retrieval and recall in the RAG scenario; when the user asks a question to the question-answering model, the client provides the cloud with an encrypted question vector, and the cloud can retrieve similar encrypted vectors similar to the encrypted question vector from the database. Therefore, the cloud stores the user ciphertext data provided by the client, so there is no risk of leakage of user data in the cloud. While encrypting the vector, it still supports similarity retrieval, which will not affect sorting and recall. For the cloud, the storage and retrieval of the vector are no different from the existing solutions. The cloud does not need to use an additional hardware trusted execution environment or code modification, and the implementation cost of the solution is low.
[0050] In some examples, the client used in the method of this embodiment can be run on any computer device, including but not limited to a personal computer, a tablet computer, a desktop computer or a mobile device, a server, a server cluster composed of multiple servers, or a cloud server composed of a large number of hosts or servers based on cloud computing, etc. For example, the client can be run on the user's local device, or the client runs the user's device in the cloud, etc. Optionally, in this embodiment, the client can be provided by a cloud vendor, or it can also be a client developed by the user based on the solution of this embodiment.
[0051] In practical applications, users can enhance the knowledge base of large models by building files in corresponding fields. The files to be retrieved contain knowledge in specific fields. The files to be retrieved can be in any format and the number of files can be arbitrary. Text content can be extracted from the files to be retrieved, and different fragmentation strategies can be adopted according to the knowledge characteristics of different fields; for example, semantic segmentation can be adopted to obtain multiple text fragments of the files to be retrieved.
[0052] Each text segment can be converted into a corresponding vector, and there are many specific implementation methods.
[0053] As an example, encrypting the vector corresponding to the text segment based on the user key of the user and the order-preservable vector encryption algorithm may include:
[0054] Inputting the text segment into a preset embedding model to obtain a vector generated by the embedding model for the text segment;
[0055] The vector of the text segment is encrypted based on the user key of the user and an order-preserving vector encryption algorithm.
[0056] For example, an embedding model may be pre-built, and a text segment may be input into the embedding model to obtain a vector of the text segment output by the embedding model.
[0057] In actual applications, in RAG scenarios, users can build their own databases to store encrypted vectors and implement the function of retrieving similar encrypted vectors from the database based on the encrypted question vectors. Alternatively, cloud vendors' search engines and other products can be used to implement vector retrieval and recall, eliminating the need to build databases and develop vector retrieval products. In this case, the vectors need to be provided to the cloud.
[0058] Based on this, this embodiment performs vector encryption of text fragments on the client side. The encryption algorithm adopts an order-preserving vector encryption algorithm. The encrypted vector still maintains the relative distance between the plaintext vectors, so that the vector database stored in the cloud can be used for vector retrieval and recall in the RAG scenario. Among them, the specific algorithm can be seen in the subsequent embodiments, which will not be expanded here for the time being. Based on this, the cloud can obtain the encryption vector corresponding to each text fragment of the file to be retrieved, and store it in the user's database. It can be seen that the cloud obtains the encryption vector, which can prevent the data risk caused by the leakage of the vector corresponding to the text fragment.
[0059] After the database stores the encrypted vectors corresponding to each text segment of the file to be retrieved, the database can be used to implement RAG. For example, the user can input the question text for the question-answering model, and similarly, the vector corresponding to the question can be encrypted on the user side.
[0060] In some examples, obtaining the question vector of the question text and encrypting it using the user key and the vector encryption algorithm may include:
[0061] Inputting the question text into the embedding model to obtain a question vector generated by the embedding model for the question text;
[0062] The question vector is encrypted based on the user key and the vector encryption algorithm.
[0063] In this embodiment, the text segment can be converted into a vector to convert the question text into a vector to obtain a question vector. In addition, the user key and vector encryption algorithm used when encrypting the vector of the text segment are also used to encrypt the text segment, thereby obtaining an encrypted question vector, so that after the question vector is sent to the cloud, the cloud can search and recall similar vectors in the database, and data risks caused by leakage of the question vector can also be prevented.
[0064] As an example, the cloud can calculate the similarity between the encrypted question vector and each vector in the database; the calculation of vector similarity can refer to existing technologies, for example, it can be implemented by calculating cosine similarity, vector distance, etc., which is not limited in this embodiment. The similarity between the encrypted question vector and each vector in the database can be obtained and then sorted, and a group of similar encrypted vectors can be selected. The number of similar encrypted vectors can be set according to actual needs. For example, it can be a set number, and a set number of similar encrypted vectors with the highest similarity are selected, or similar encrypted vectors with a similarity greater than or equal to a set similarity threshold.
[0065] The encrypted vector is obtained by converting a text segment into a vector and then encrypting it. Therefore, each similar encrypted vector has a corresponding similar text segment. There are many ways to retrieve similar encrypted vectors in the cloud and determine the similar text segments corresponding to the similar encrypted vectors.
[0066] In some examples, the method may further include:
[0067] Encrypting each text fragment of the file to be retrieved respectively to obtain an encrypted text of each text fragment;
[0068] The encrypted text of each text segment is sent to the cloud, so that the cloud stores the encrypted text of each text segment and the corresponding relationship between the encryption vector in the database.
[0069] The obtaining of similar text segments corresponding to the similar encrypted vectors may include:
[0070] receiving an encrypted text returned by the cloud corresponding to the similar encryption vector determined based on the corresponding relationship;
[0071] The similar encrypted texts are decrypted to obtain similar text fragments.
[0072] In this embodiment, each text segment can be encrypted separately, and the encryption algorithm can be set according to actual needs, which is not limited in this embodiment. For example, a symmetric key algorithm can be used. The encrypted text of each text segment can be sent to the cloud storage, so that the cloud can determine the encrypted text corresponding to the similar encryption vector after retrieving the similar encryption vector. Since the cloud stores the encrypted text, the risk of data leakage is significantly reduced.
[0073] like Figure 1B Shown is a schematic diagram of a data protection system in a RAG according to an exemplary embodiment of the present specification, which may include a client and a cloud. Figure 1B The process of storing encryption vectors and encrypted text in the user database is shown in FIG.
[0074] For example, the user's to-be-retrieved file may include text segment_1, text segment_2, ... text segment_t; this embodiment uses an encryption algorithm based on AES (Advanced Encryption Standard) to encrypt, and can obtain: encrypted text_1, encrypted text_2, ... encrypted text_t.
[0075] Text fragment_1, text fragment_2...text fragment_t can be converted into corresponding vectors: vector_1, vector_2...vector_t respectively.
[0076] Next, each vector is encrypted using a vector encryption algorithm to obtain: encrypted vector_1, encrypted vector_2, ... encrypted vector_t.
[0077] The "encrypted text_1, encrypted text_2...encrypted text_t" and the corresponding "encrypted vector_1, encrypted vector_2...encrypted vector_t" can be sent to the cloud, and the cloud can build a database and store it.
[0078] In this embodiment, the cloud retrieves similar encrypted vectors from the database. Since the encrypted texts of each text segment and the corresponding relationship between the encrypted vectors are also stored, the cloud can obtain the encrypted text corresponding to the similar encrypted vectors. For example, assuming that the similar encrypted vectors retrieved and recalled are: encrypted vector_8 and encrypted vector_9, the cloud can determine the corresponding encrypted text_8 and encrypted text_9 through the corresponding relationship.
[0079] The cloud can send encrypted text_8 and encrypted text_9 to the client, and the client can decrypt encrypted text_8 and encrypted text_9 respectively to obtain corresponding text fragment_8 and text fragment_9.
[0080] It can be seen that the cloud in this embodiment stores encrypted text, thus significantly reducing the risk of data leakage. The cloud stores the encrypted text of each text segment and the corresponding relationship between the encrypted vectors, so similar encrypted texts similar to the problem vector can be quickly queried through the cloud without deploying a database and vector search engine on the client side.
[0081] In some other examples, the method may further include:
[0082] Encrypting each text segment of the file to be retrieved respectively to obtain an encrypted text of each text segment, and configuring an encrypted text identifier for each encrypted text;
[0083] Sending each encrypted text identifier to the cloud, so that the cloud stores the corresponding relationship between the encrypted text identifier of each text segment and the encryption vector in the database;
[0084] The obtaining of similar text segments corresponding to the similar encrypted vectors includes:
[0085] Receiving a similar encrypted text identifier corresponding to a similar encrypted vector determined based on the corresponding relationship and returned by the cloud;
[0086] The similar encrypted text corresponding to the similar encrypted text identifier is decrypted to obtain a similar text fragment.
[0087] In this embodiment, the client does not need to send the encrypted text to the cloud to reduce the amount of data transmission or prevent the leakage of the encrypted text; in this embodiment, the client sends the corresponding relationship between the identifier of each encrypted text and the encryption vector corresponding to each encrypted text to the cloud; thus, the cloud stores the corresponding relationship between the encryption vector and the encrypted text identifier. For example, encryption vector_1 corresponds to identifier_1 (the identifier of encrypted text_1), encryption vector_2 corresponds to identifier_2 (the identifier of encrypted text_2), ..., encryption vector_t corresponds to identifier n (the identifier of encrypted text_t). After the cloud retrieves similar encryption vectors, it can return the identifiers corresponding to the similar encryption vectors to the client.
[0088] For example, similar encryption vectors are: encryption vector_8 and encryption vector_9, then the cloud can determine the corresponding identifier_8 and identifier_9 through the corresponding relationship; after receiving it, the client determines the encrypted text_8 and encrypted text_9 corresponding to identifier_8 and identifier_9 locally, and then further decrypts them respectively to obtain text fragment_8 and text fragment_9.
[0089] In some examples, the question-answering model may generate a response based on the question text and the similar text segment. For example, obtaining the similar text segment corresponding to the similar encrypted vector may include:
[0090] Prompt content is constructed based on the question text and the similar text fragments, and after the prompt content is input into the question-answering model, a reply generated by the question-answering model based on the prompt content is obtained.
[0091] As an example, a Prompt can be constructed based on the question text and similar text fragments by using a preset Prompt template, etc. The constructed Prompt can be input into the question-answering model, and then the answer generated by the question-answering model can be obtained. Based on this, this embodiment can use the Prompt containing the question text and the retrieved similar text fragments to guide the question-answering model to generate a more accurate answer.
[0092] Next, the order-preserving vector encryption algorithm is described. The order-preserving vector encryption algorithm of this embodiment allows operations to be performed on the encrypted vector to preserve the order, such as comparing and searching the encrypted vector without decryption. That is, the encrypted vector preserves the order characteristics of the original vector.
[0093] A corresponding order-preserving vector encryption algorithm can be selected or designed as needed. As an example, the vector encryption algorithm is used to: use the user key to generate a random perturbation vector within a set deviation range for each input original vector, scale each original vector by the same proportion and then add the perturbation vector to obtain an encrypted vector corresponding to each original vector; wherein the original vector includes the vector corresponding to the text segment or the question vector.
[0094] As an example, in this embodiment, the original vector encrypted using the vector encryption algorithm includes the vector corresponding to the text segment or the problem vector, and these vectors can use the same scaling ratio and user key; the algorithm uses the same key K and ensures that the scaling ratio of all vectors is consistent, so that the distance comparison of each vector in the encrypted state is comparable. In addition, each vector has an independent perturbation vector to ensure that the plaintext vector will not produce a predictable or correlated ciphertext vector, preventing attackers from inferring the plaintext content by analyzing multiple ciphertext vectors; at the same time, the perturbation range of the original vector can be set within the set deviation range, thereby allowing effective distance comparison in the encrypted space after encryption.
[0095] In some examples, encrypting the vector corresponding to the text segment based on the user key of the user and the order-preserving vector encryption algorithm includes:
[0096] Inputting the vector corresponding to the text segment as the original vector, the user key, a scaling factor for scaling the original vector, and an approximation factor representing the set deviation into the vector encryption algorithm, so that the vector encryption algorithm encrypts the vector corresponding to the text segment;
[0097] The step of obtaining the question vector of the question text and encrypting the question text by using the user key and the vector encryption algorithm includes:
[0098] Inputting the question vector of the question text as the original vector, the user key, the scaling factor, and the approximation factor into the vector encryption algorithm, so that the vector encryption algorithm encrypts the question vector of the question text;
[0099] Wherein, the vector encryption algorithm is used for:
[0100] Obtaining an input vector to be encrypted, the user key, the scaling factor, and the approximation factor;
[0101] After the random initial bit string is generated, a first random bit string and a second random bit string are generated based on the user key and the random initial bit string through a pseudorandom function (PRF);
[0102] Using the first random bit string as a seed, generating a random vector from a standard multivariate normal distribution;
[0103] Using the second random bit string as a seed, generating a random scalar from a uniform distribution;
[0104] After generating a disturbance vector according to the random vector, the random scalar and the approximation factor, the original vector is scaled based on the scaling factor, and the disturbance vector is added to the scaled vector to obtain an encrypted vector and then output.
[0105] As an example, the encryption process of the vector encryption algorithm can be:
[0106] 1. Algorithm input parameters:
[0107] The scaling factor s may be a positive number used to linearly scale the plaintext vector to maintain the relative distance relationship between the vectors; the scaling factor s may be uniformly randomly selected from a preset key space S, and the key space S may be a set of candidate values used to generate the scaling factor s.
[0108] The approximation factor β represents the set deviation and can be used to control the allowable deviation in the distance comparison. β can be a non-negative real number.
[0109] The symmetric encryption key K can be generated by the user through a setting method or by the client itself. For example, a random bit string of length k can be generated as K, and k can be 128 bits or 256 bits, etc.
[0110] The original vector m; in this embodiment, it is the vector of the text segment; or it is the question vector.
[0111] 2. Encryption:
[0112] Randomly select a random initial bit string n, the bit string is a binary string, and its length can be l bits; n is a random bit string sequence used to generate the encryption process, which can be selected from all possible lengths l Uniformly randomly selects a bit string from the binary string. This can be achieved through a cryptographically secure random number generator to ensure the unpredictability of n, which will be used as the random component in the encryption process.
[0113] A pseudo-random function PRF(K,n) may be used to generate two random bit strings coins1 and coins2 based on a key K, so that the generated random numbers have high entropy and are unpredictable.
[0114] Using coins1 as the seed, we generate a vector u by sampling from the standard multivariate normal distribution N(0,Id), where I d is the identity matrix. Gaussian noise is introduced here to increase the randomness of the encrypted vector. In the multivariate normal distribution N(0,I d ), I d Represents a d×d unit matrix, indicating that the random variables of each dimension are independent and obey the standard normal distribution, that is, the direction of u is uniformly distributed on the sphere. The unit matrix is characterized by the elements on the diagonal being 1 and the rest being 0; it ensures that the disturbances in the encryption process conform to the expected statistical characteristics, enhancing the randomness and security of the encrypted data.
[0115] Generate a scalar x' from the uniform distribution U(0,1) using coins2 as the seed.
[0116] calculate , where d is the dimension of the vector.
[0117] calculate , where λ m is a perturbation vector used to adjust the offset of the vector. Here, the radius of the perturbation vector is adjusted by sampling x' from the uniform distribution U(0, 1) and taking its dth root; The distribution of ensures that the generated perturbation vector is evenly distributed within the sphere, not just in the direction of the coordinate axis. Finally, multiply by , ensuring that the norm of the disturbance does not exceed the The perturbation vector will be evenly distributed in the radius The d-dimensional sphere has a uniformly distributed direction and controllable length, and also realizes the restriction of the norm of the perturbation vector, ensuring that in the encryption space, the distance between the ciphertext vectors can still approximately reflect the distance between the plaintext vectors.
[0118] Calculate the encrypted vector: c=sm+λ m That is, multiply the vector m to be encrypted by the scaling factor s, and then add the perturbation vector λ m The encrypted vector c retains the relative position and distance relationship of the plaintext vector, while introducing random noise to protect privacy.
[0119] 3. Output:
[0120] The encryption vector c and the random initial bit string n are output, wherein the random initial bit string n can be used for decryption.
[0121] The core goal of the above vector encryption algorithm is to maintain the distance relationship between vectors after encryption. Specifically, the encrypted vector c is calculated by c=sm+λ m , the relative position of the original vector m to be encrypted is retained.
[0122] The scaling factor s linearly scales the vectors, maintaining the relative proportions between the vectors; and the vector λ m Although the introduction of increases the noise, if its calculation method is consistent for all vectors, the relative distance relationship between different vectors can still be compared in the encrypted space.
[0123] Therefore, by performing a linear transformation (scaling and offsetting) on the vectors and introducing random noise, the distance comparison relationship between the vectors is maintained in the encrypted state, thereby allowing operations such as nearest neighbor search to be performed in the encrypted space to obtain the similarity between the vectors, which can be applied to the vector similarity search in the RAG scenario of this embodiment.
[0124] As an example, the original vectors encrypted using the vector encryption algorithm include vectors corresponding to each text segment or question vectors of each question; during the encryption process, in order to effectively compare the distances of multiple vectors in the encrypted state, these vectors can use the same partial algorithm parameters when encrypting; for example, the same symmetric encryption key K can be used to ensure that the random bit string and the perturbation vector λ mThe generation process of can be kept consistent; the same scaling factor can also be used to keep the scaling ratio of the encrypted vectors consistent, so that the distance comparison in the encrypted space can accurately reflect the distance relationship in the plaintext space; the same approximation factor β can also be used to control the consistency of the perturbation amount, ensuring that the approximate error of all encrypted vectors in distance comparison is the same, thereby maintaining the predictability and security of the system. When encrypting, each vector can generate an independent random bit string, such as coins1 and coins2, so that the perturbation vector added to each original vector is independent. The independent perturbation variables ensure that although there is noise between the encrypted vectors, these noises are independent and bounded, allowing the distance comparison to be valid within a certain error range. The independent perturbation vector of each vector ensures that the same plaintext vector will not produce a predictable or correlated ciphertext vector, preventing attackers from inferring the plaintext content by analyzing multiple ciphertext vectors.
[0125] Correspondingly, the decryption process of the vector encryption algorithm can be:
[0126] Receive ciphertext (c,n) and key (s,K).
[0127] Using the same random initial bit string n and key K, the pseudo-random function PRF(K,n) is used to reproduce the random values coins1 and coins2 used in encryption.
[0128] Using coins1 as the seed, we can generate a random number from the standard normal distribution N(0,I d ) generates a vector u.
[0129] Generate a scalar x' from the uniform distribution U(0,1) using coins1 as the seed.
[0130] calculate .
[0131] calculate .
[0132] Calculate the original vector m=(c-λ m ) / s.
[0133] Output the decrypted vector m.
[0134] It can be understood from the foregoing embodiments that, in fact, in the RAG scenario of this embodiment, the encryption vector of the text segment does not need to be decrypted in subsequent applications.
[0135] In some examples, when generating the perturbation vector λ mWhen , a hierarchical perturbation mechanism can be introduced. After uniformly randomly selecting s from the key space S, a key K1 for generating the direction of the perturbation vector and a key K2 for adjusting the perturbation amplitude can be generated to enhance the independence of the perturbation. For example, a random bit string n1 for K1 can be generated, and a random bit string n2 for K2 can be generated; the pseudo-random function PRF mentioned above can be used; the pseudo-random function PRF can be used to generate a bit string coins1 for the perturbation direction with K1 and n1 as input, and coins1 can be used to generate a bit string coins1 for the perturbation direction in the standard multivariate normal distribution N(0,I d ), the disturbance direction vector u is obtained by sampling; the pseudo-random function PRF can be used to generate the bit string coins2 for the disturbance amplitude with K2 and n2 as input, and the scalar x'_0 is generated in the multivariate normal distribution; the disturbance amplitude x is calculated, and the disturbance vector λ is calculated m .
[0136] In other cases, the magnitude of the disturbance ; mask is a masking factor, which can be generated using masking keys M and n, which can be provided by the user. The range of Mask is [a, b], where a and b can be preset constants related to security and distance preservation requirements. A masking function f(k) can be designed to convert the masking key into a real number mask within a suitable range, ensuring that the perturbation amplitude can improve security without significantly affecting the accuracy of distance comparison.
[0137] Next, some examples will be used to illustrate this. Figure 2A As shown in FIG. 1 , it is a schematic diagram of a client constructing an encryption vector according to an exemplary embodiment of this specification; Figure 2B As shown in FIG. 1 , it is a schematic diagram of retrieving similar encrypted vectors according to an exemplary embodiment of the present specification; Figure 2C , which is a schematic diagram of data protection in RAG according to an exemplary embodiment of the present specification.
[0138] exist Figure 2A In the process, the user's to-be-retrieved file can be divided into multiple text segments (i.e. Figure 2C In step 1, each text segment is used as the input of the embedding model, and the embedding model outputs the vector Vector of the text segment (i.e. Figure 2C Step 2 in ); the vector can be encrypted based on the user key to obtain an encrypted vector, which can be stored in the database store. Optionally, in the embodiment of the vector encryption algorithm described above, some parameters required by the vector encryption algorithm will be generated, which are represented by the symbol IV in the figure, such as the random initial vector n required for decryption, etc. These parameters can be stored for use when decryption is required.
[0139] Figure 2B Center left and Figure 2A The process of constructing an encrypted vector on the client side is similar to that in the previous example; the user's question text Query for the question model can be obtained, and the question text can be used as the input of the embedding model (i.e. Figure 2C In step 3 of the above, the question vector of the question text output by the embedding model can be encrypted based on the user key to obtain an encrypted question vector. A set of (one or more) similar encrypted vectors (i.e. Figure 2C Step 4 in ); similar encrypted texts corresponding to similar encrypted vectors can be queried, and similar encrypted texts can be decrypted to obtain corresponding similar text fragments. Prompt content can be constructed based on the question text and similar text fragments (i.e. Figure 2C In step 5 of the above example, the prompt content is input into the question-answering model LLM, and the answer generated by LLM based on the prompt content is obtained. The answer can be returned to the user (i.e. Figure 2C 6 in the previous step).
[0140] like Figure 3 FIG. 1 is a flowchart of another data protection method in a RAG according to an exemplary embodiment of the present specification, wherein the method includes:
[0141] In step 302, a file to be searched is obtained, wherein the file to be searched includes a text segment;
[0142] In step 304, based on the user's user key and an order-preserving vector encryption algorithm, the vector corresponding to the text segment is encrypted to obtain an encrypted vector, and the encrypted vector is stored in the user's database;
[0143] In step 306, in response to receiving a question text of the user to the question-answering model, a question vector of the question text is obtained and encrypted using the user key and the vector encryption algorithm to obtain an encrypted question vector, and a similar encrypted vector similar to the encrypted question vector is retrieved from the database;
[0144] In step 308, similar text segments corresponding to the similar encrypted vectors are obtained, and the similar text segments are used to enable the question-answering model to generate a response.
[0145] The method of this embodiment can be applied to the client or the cloud, and can encrypt the vectors of each text segment of the file to be retrieved, and then store each encrypted vector in the database. The database can be located anywhere, such as on the user side or in the cloud. The vector encryption is implemented using an order-preserving vector encryption algorithm, so that the encrypted encrypted vector still maintains the relative distance between the plaintext vectors, so that the database can be used for vector retrieval and recall in the RAG scenario; when the user asks a question to the question-and-answer model, a similar encrypted vector similar to the encrypted question vector is retrieved from the database. Therefore, there is no risk of leakage of user data. While vector encryption is in progress, similarity retrieval is still supported, which will not affect sorting and recall.
[0146] The specific implementation of the above embodiment can refer to the description of the aforementioned embodiment, which will not be repeated here.
[0147] Corresponding to the embodiments of the data protection method in the aforementioned RAG, this specification also provides embodiments of a data protection device in the RAG and a computer device to which it is applied.
[0148] The data protection device embodiments in the RAG described above in this specification can be applied to computer devices, such as servers or terminal devices. The device embodiments can be implemented through software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Figure 4 The figure is a hardware structure diagram of the computer device where the data protection device in the RAG mentioned in this specification is located, except Figure 4 In addition to the processor 410, network interface 420, memory 430, and non-volatile memory 440 shown, the computer device where the data protection device in the aforementioned RAG in the embodiment is located may also include other hardware, usually according to the actual function of the computer device, which will not be described in detail.
[0149] like Figure 5 As shown, Figure 5 1 is a block diagram of a data protection device in the aforementioned RAG according to an exemplary embodiment of the present specification, the device comprising:
[0150] The acquisition module 51 is used to: acquire a file to be searched, wherein the file to be searched includes a text segment;
[0151] A first encryption module 52 is used to: encrypt the vector corresponding to the text segment based on the user key of the user and the order-preserving vector encryption algorithm, obtain the encrypted vector and send it to the cloud, so that the cloud stores the encrypted vector in the database of the user;
[0152] The second encryption module 53 is used to: in response to receiving a question text of the user to the question-answering model, obtain a question vector of the question text and encrypt it using the user key and the vector encryption algorithm, obtain the encrypted question vector and send it to the cloud, so that the cloud retrieves a similar encrypted vector similar to the encrypted question vector from the database;
[0153] The reply module 54 is used to obtain a similar text segment corresponding to the similar encrypted vector, and generate a reply based on the question text and the similar text segment.
[0154] In some examples, the first sending module is used to:
[0155] Inputting the text segment into a preset embedding model to obtain a vector generated by the embedding model for the text segment;
[0156] Encrypting the vector of the text segment based on the user key of the user and an order-preserving vector encryption algorithm;
[0157] The step of obtaining the question vector of the question text and encrypting the question text by using the user key and the vector encryption algorithm includes:
[0158] Inputting the question text into the embedding model to obtain a question vector generated by the embedding model for the question text;
[0159] The question vector is encrypted based on the user key and the vector encryption algorithm.
[0160] In some examples, the device further includes an encrypted text sending module, configured to:
[0161] Encrypting each text fragment of the file to be retrieved respectively to obtain an encrypted text of each text fragment;
[0162] The encrypted text of each text segment is sent to the cloud, so that the cloud stores the encrypted text of each text segment and the corresponding relationship between the encryption vector in the database.
[0163] In some examples, the encrypted text decryption module is used to:
[0164] receiving an encrypted text returned by the cloud corresponding to the similar encryption vector determined based on the corresponding relationship;
[0165] The similar encrypted texts are decrypted to obtain similar text fragments.
[0166] In some examples, the first encryption module is used to:
[0167] Using the vector corresponding to the text segment as the vector to be encrypted and the user key as the input key, calling a vector encryption algorithm so that the vector encryption algorithm encrypts the vector corresponding to the text segment;
[0168] The second encryption module is used for:
[0169] Using the question vector of the question text as the vector to be encrypted and the user key as the input key, calling a vector encryption algorithm so that the vector encryption algorithm encrypts the question vector of the question text;
[0170] In some examples, the vector encryption algorithm is used to: use the user key to generate a random perturbation vector within a set deviation for each input original vector, scale each original vector by the same proportion and then add the perturbation vector to obtain an encrypted vector corresponding to each original vector; wherein the original vector includes the vector corresponding to the text fragment or the question vector.
[0171] In some examples, the first encryption module is used to:
[0172] Inputting the vector corresponding to the text segment as the original vector, the user key, a scaling factor for scaling the original vector, and an approximation factor representing the set deviation into the vector encryption algorithm, so that the vector encryption algorithm encrypts the vector corresponding to the text segment;
[0173] The second encryption module is used for:
[0174] Inputting the question vector of the question text as the original vector, the user key, the scaling factor, and the approximation factor into the vector encryption algorithm, so that the vector encryption algorithm encrypts the question vector of the question text;
[0175] Wherein, the vector encryption algorithm is used for:
[0176] Obtaining an input vector to be encrypted, the user key, the scaling factor, and the approximation factor;
[0177] After generating the random initial bit string, generating a first random bit string and a second random bit string based on the user key and the random initial bit string through a pseudo-random function;
[0178] Using the first random bit string as a seed, generating a random vector from a standard multivariate normal distribution;
[0179] Using the second random bit string as a seed, generating a random scalar from a uniform distribution;
[0180] After generating a disturbance vector according to the random vector, the random scalar and the approximation factor, the original vector is scaled based on the scaling factor, and the disturbance vector is added to the scaled vector to obtain an encrypted vector and then output.
[0181] Wherein, the vector encryption algorithm is used for:
[0182] Obtaining an input vector to be encrypted, an input key, a scaling factor for scaling the vector to be encrypted, and an approximation factor for controlling a distance comparison deviation;
[0183] After the random initialization vector is generated, a first random string and a second random string are generated based on the symmetric encryption key and the random initialization vector through a pseudo-random function;
[0184] Using the first random string as a seed, generating a random vector from a standard multivariate normal distribution;
[0185] Using the second random string as a seed, generating a random scalar from a uniform distribution;
[0186] After generating a disturbance vector according to the random vector, the random scalar and the approximation factor, the vector to be encrypted is scaled based on the scaling factor, and the disturbance vector is added to the scaled vector to obtain the encrypted vector and then output.
[0187] In some examples, the reply module is used to:
[0188] Prompt content is constructed based on the question text and the similar text fragments, and after the prompt content is input into the question-answering model, a reply generated by the question-answering model based on the prompt content is obtained.
[0189] The implementation process of the functions and effects of each module in the data protection device in the aforementioned RAG is specifically described in the implementation process of the corresponding steps in the data protection method in the aforementioned RAG, which will not be repeated here.
[0190] Accordingly, an embodiment of the present specification also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the data protection method embodiment in the aforementioned RAG.
[0191] Correspondingly, such as Figure 1B As shown, an embodiment of the present specification also provides a data protection system in RAG including a client and a cloud, wherein the client is used to execute the steps of the aforementioned data protection method embodiment in RAG, and the cloud is used to store the encrypted vector sent by the client in the user's vector database after receiving it, and to retrieve a similar encrypted vector similar to the encrypted question vector after receiving the encrypted question vector.
[0192] Correspondingly, an embodiment of the present specification also provides a database in a RAG, wherein the database stores encryption vectors provided by a user's client, the client is used to execute the steps of the aforementioned data protection method embodiment, and the database is also used for the cloud to retrieve similar encryption vectors similar to the encrypted question vector after receiving the encrypted question vector.
[0193] Correspondingly, an embodiment of the present specification also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the data protection method embodiment in the aforementioned RAG when executing the program.
[0194] Correspondingly, an embodiment of the present specification also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the data protection method embodiment in the aforementioned RAG are implemented.
[0195] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.
[0196] The above embodiments can be applied to one or more computer devices, where the computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The hardware of the computer device includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.
[0197] The computer device may be any electronic product that can perform human-computer interaction with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0198] The computer device may also include a network device and / or a user device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.
[0199] The network where the computer device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.
[0200] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0201] The step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the protection scope of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the protection scope of this application.
[0202] Although this specification includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of the specific embodiments of specific inventions. Certain features described in multiple embodiments in this specification may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claim protection, one or more features from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.
[0203] The description of "specific examples" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0204] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention claimed herein. The specification is intended to cover any variations, uses or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not claimed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.
[0205] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
[0206] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
Claims
1. A data protection method in RAG, the method being applied to a user's client, the method comprising: Obtaining a file to be searched, wherein the file to be searched includes a text segment; Based on the user key of the user and the order-preserving vector encryption algorithm, encrypt the vector corresponding to the text segment to obtain the encrypted vector and send it to the cloud, so that the cloud stores the encrypted vector in the database of the user; In response to receiving a question text from a user to a question-answering model, a question vector of the question text is obtained and encrypted using the user key and the vector encryption algorithm, and the encrypted question vector is obtained and sent to the cloud, so that the cloud retrieves a similar encrypted vector similar to the encrypted question vector from the database; the vector encryption algorithm is used to: use the user key to generate a random perturbation vector within a set deviation for each input original vector, scale each original vector by the same proportion, and then add the perturbation vector to obtain an encrypted vector corresponding to each original vector; wherein the original vector includes the vector corresponding to the text segment or the question vector; A similar text segment corresponding to the similar encrypted vector is obtained, and the similar text segment is used to enable the question-answering model to generate a reply.
2. According to the method of claim 1, encrypting the vector corresponding to the text segment based on the user key of the user and the order-preserving vector encryption algorithm comprises: Inputting the text segment into a preset embedding model to obtain a vector generated by the embedding model for the text segment; Encrypting the vector of the text segment based on the user key of the user and an order-preserving vector encryption algorithm; The step of obtaining the question vector of the question text and encrypting the question text by using the user key and the vector encryption algorithm includes: Inputting the question text into the embedding model to obtain a question vector generated by the embedding model for the question text; The question vector is encrypted based on the user key and the vector encryption algorithm.
3. The method according to claim 1, further comprising: Encrypting each text fragment of the file to be retrieved respectively to obtain an encrypted text of each text fragment; Sending the encrypted text of each text segment to the cloud, so that the cloud stores the corresponding relationship between the encrypted text of each text segment and the encryption vector in the database; The obtaining of similar text segments corresponding to the similar encrypted vectors includes: Receiving a similar encrypted text corresponding to the similar encrypted vector determined based on the corresponding relationship and returned by the cloud; The similar encrypted texts are decrypted to obtain similar text fragments.
4. The method according to claim 1, further comprising: Encrypting each text segment of the file to be retrieved respectively to obtain an encrypted text of each text segment, and configuring an encrypted text identifier for each encrypted text; Sending each of the encrypted text identifiers to the cloud, so that the cloud stores the corresponding relationship between the encrypted text identifier of each text segment and the encryption vector in the database; The obtaining of similar text segments corresponding to the similar encrypted vectors includes: Receiving a similar encrypted text identifier corresponding to a similar encrypted vector determined based on the corresponding relationship and returned by the cloud; The similar encrypted text corresponding to the similar encrypted text identifier is decrypted to obtain a similar text fragment.
5. According to the method of claim 1, encrypting the vector corresponding to the text segment based on the user key of the user and the order-preserving vector encryption algorithm comprises: Inputting the vector corresponding to the text segment as the original vector, the user key, a scaling factor for scaling the original vector, and an approximation factor representing the set deviation into the vector encryption algorithm, so that the vector encryption algorithm encrypts the vector corresponding to the text segment; The step of obtaining the question vector of the question text and encrypting the question text by using the user key and the vector encryption algorithm includes: Inputting the question vector of the question text as the original vector, the user key, the scaling factor, and the approximation factor into the vector encryption algorithm, so that the vector encryption algorithm encrypts the question vector of the question text; Wherein, the vector encryption algorithm is used for: Obtaining an input vector to be encrypted, the user key, the scaling factor, and the approximation factor; After generating the random initial bit string, generating a first random bit string and a second random bit string based on the user key and the random initial bit string through a pseudo-random function; Using the first random bit string as a seed, generating a random vector from a standard multivariate normal distribution; Using the second random bit string as a seed, generating a random scalar from a uniform distribution; After generating a disturbance vector according to the random vector, the random scalar and the approximation factor, the original vector is scaled based on the scaling factor, and the disturbance vector is added to the scaled vector to obtain an encrypted vector and then output.
6. The method according to claim 1, wherein obtaining similar text segments corresponding to the similar encrypted vectors so that the question-answering model generates a reply based on the question text and the similar text segments comprises: Prompt content is constructed based on the question text and the similar text fragments, and after the prompt content is input into the question-answering model, a reply generated by the question-answering model based on the prompt content is obtained.
7. A data protection method in RAG, the method comprising: Obtaining a file to be searched, wherein the file to be searched includes a text segment; Based on the user's user key and an order-preserving vector encryption algorithm, encrypt the vector corresponding to the text segment to obtain an encrypted vector, and store the encrypted vector in the user's database; In response to receiving a question text from a user to a question-answering model, a question vector of the question text is obtained and encrypted using the user key and the vector encryption algorithm to obtain an encrypted question vector, and a similar encrypted vector similar to the encrypted question vector is retrieved from the database; the vector encryption algorithm is used to: use the user key to generate a random perturbation vector within a set deviation for each input original vector, scale each original vector by the same proportion, and then add the perturbation vector to obtain an encrypted vector corresponding to each original vector; wherein the original vector includes a vector corresponding to the text segment or the question vector; A similar text segment corresponding to the similar encrypted vector is obtained, and the similar text segment is used to enable the question-answering model to generate a reply.
8. A data protection system in RAG, the system comprising a client and a cloud, the client being used to execute the steps of the method described in any one of claims 1 to 6, the cloud being used to store the encrypted vector sent by the client into a vector database of the user after receiving it, and to retrieve a similar encrypted vector similar to the encrypted question vector after receiving the encrypted question vector.
9. A database in a RAG, wherein the database stores encryption vectors provided by a user's client, the client is used to perform the steps of the method described in any one of claims 1 to 6, and the database is also used for the cloud to retrieve similar encryption vectors similar to the encrypted question vector after receiving the encrypted question vector.
10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
11. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
12. 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 method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-party participation privacy security knowledge base construction method
CN118245565A