Text processing method and device, electronic equipment, storage medium and program product
Patent Information
- Application Number
- CN202510463791.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2026-10-20
AI Technical Summary
[0004]本公开提供了一种文本处理方法、装置、电子设备、存储介质和程序产品,用以在一定程度上解决召回方式固定,系统生成应答文本的时延增大、准确性低的问题
[0019]本公开提供了一种文本处理方法、装置、电子设备、存储介质和程序产品。本公开通过获取问题向量;利用树形索引结构对问题向量进行相似度检索,确定第一序列;树形索引结构由至少两个节点构成,任意一个节点对应一个文本向量;第一序列包括至少一个节点;基于第一节点的相似度和相似度阈值,确定第一数目;第一节点为在第一序列中与问题向量相似度最高的节点;第一数目用于调整第一序列中的节点数目;基于第一序列中第一数目的多个节点对应的字数限制信息,确定第二数目;在第一序列中选取第二数目的节点并构造目标向量;目标向量用于生成问题向量的应答文本。这样,采用树形索引结构对问题向量进行相似度检索,能快速定位与问题相关的节点形成第一序列,减少了不必要的相似度计算。同时,可以基于第一节点的相似度动态确定第一数目,避免固定阈值下召回数量不合理的问题。同时结合各节点对应的字数限制信息,则进一步限制了文本召回的范围,以此综合考虑了相似度和字数的限制,动态调整召回文本的数量,确保在满足字数上限的同时最大程度保留有效信息。综上,本公开提供的方案,可以减少计算相似度的次数,动态确定召回数量,提高效率,使得时延减小,准确性提高。
Smart Images

Figure BDA0005357908960000221 
Figure BDA0005357908960000231 
Figure BDA0005357908960000232
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of communication technology, and in particular to a text processing method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] Currently, the method for generating response text in Knowledge Base Question Answering Systems (KBQA) is usually to first determine the similarity between the user's question and the text in the knowledge base, then compare it with a preset similarity threshold, and finally input the knowledge base text and the user's question that meet the similarity threshold into a large language model to obtain the response text.
[0003] However, this method of recalling knowledge base texts related to user questions based on similarity thresholds is relatively fixed, and the large number of recalled texts and the numerous similarity calculations result in significant delays in generating response texts. Furthermore, a large number of recalled texts may exceed the system's character limit, causing the system to discard a large amount of valid information and reducing the accuracy of the generated response text. Summary of the Invention
[0004] This disclosure provides a text processing method, apparatus, electronic device, storage medium, and program product to address, to some extent, the problems of fixed recall methods, increased latency, and low accuracy in generating response text by the system.
[0005] According to one aspect of this disclosure, a text processing method is provided, the method comprising: obtaining a question vector; performing a similarity search on the question vector using a tree index structure to determine a first sequence; the tree index structure consisting of at least two nodes, each node corresponding to a text vector; the first sequence including at least one node; determining a first number based on the similarity of the first node and a similarity threshold; the first node being the node in the first sequence with the highest similarity to the question vector; the first number being used to adjust the number of nodes in the first sequence; determining a second number based on character limit information corresponding to multiple nodes of the first number in the first sequence; selecting the second number of nodes in the first sequence and constructing a target vector; the target vector being used to generate response text for the question vector.
[0006] Furthermore, according to one aspect of the method of this disclosure, a first sequence is determined by performing a similarity search on a question vector using a tree index structure, comprising: recursively searching downwards using the tree index structure until a second node is obtained; the second node is a node in a subvector space containing only one node; starting from the second node, recursively searching upwards based on the similarity between the question vector and each node until a first node is obtained; and determining the first sequence by sorting each node according to the similarity between it and the question vector in the first search path from the second node to the first node.
[0007] Furthermore, according to one aspect of the method of this disclosure, a recursive downward search is performed using a tree index structure until a second node is obtained, comprising: starting from the root node of the tree index structure, recursively searching downwards until a second node is obtained; for the root node, determining the relationship between the first eigenvalue of the problem vector and the second eigenvalue of the split point; the split point is used to divide the first sub-vector space and the second sub-vector space; when the first eigenvalue is greater than or equal to the second eigenvalue, searching downwards from the first sub-vector space; when the first eigenvalue is less than the second eigenvalue, searching downwards from the second sub-vector space.
[0008] Furthermore, according to one aspect of the method of this disclosure, starting from the second node, a recursive upward search is performed based on the similarity between the question vector and each node until the first node is obtained, including: for any node in the second search path, determining the third node with the highest similarity to the question vector in the sub-vector space corresponding to the parent node of the node; the second search path is the path from the second node to the root node; using the third node as the reference point, the search is recursively performed upwards until the root node is reached; and the third node in the sub-vector space corresponding to the root node is determined as the first node.
[0009] Furthermore, according to one aspect of the method of this disclosure, for any node in the first path, in the sub-vector space corresponding to the node's parent node, the third node with the highest similarity to the problem vector is determined, including: using the node as a reference point, determining whether the node's parent node is a node with a higher similarity to the problem vector; when the node has a higher similarity to the problem vector, determining the node as the third node; when the node's parent node has a higher similarity to the problem vector, determining whether there exists a fourth node with a higher similarity to the problem vector in another sub-vector space of the parent node; when a fourth node exists, determining the fourth node as the third node; when a fourth node does not exist, determining the parent node as the third node.
[0010] Furthermore, according to one aspect of the method of this disclosure, determining a first number based on the similarity of a first node and a similarity threshold includes: selecting a third number of nodes with higher similarity ranking in a first sequence based on the similarity between the first node and the question vector; determining the similarity between each of the third number of nodes and the question vector, and comparing it with the similarity threshold respectively; and determining the number of nodes that satisfy the similarity threshold among the third number of nodes as the first number.
[0011] Furthermore, according to one aspect of the method of this disclosure, determining a second number based on word count restriction information corresponding to a first number of nodes in a first sequence includes: selecting a first number of nodes with higher similarity ranking in the first sequence; obtaining word count restriction information corresponding to each of the first number of nodes; the word count restriction information includes at least one of the following: the number of characters in the node, the number of characters in the question vector, and the number of characters in the response text; and determining the second number based on the word count restriction information corresponding to each node.
[0012] Furthermore, according to one aspect of the method disclosed herein, the method further includes: constructing a tree index structure; constructing the tree index structure includes: for any vector space, determining the text vector with the largest feature variance value in the vector space as the root node of the vector space; based on the feature value relationship between the features of each text vector, dividing each text vector into a first sub-vector space and a second sub-vector space corresponding to the root node; repeating the division until there is only one text vector in each sub-vector space.
[0013] Furthermore, according to one aspect of the method disclosed herein, based on the eigenvalue relationship between the features of each text vector, each text vector is divided into a first sub-vector space and a second sub-vector space corresponding to the root node, including: determining a segmentation point; the segmentation point is the node corresponding to the median of the eigenvalues of each text vector; when the eigenvalue of any text vector is greater than or equal to the second eigenvalue of the segmentation point, the text vector corresponding to the eigenvalue of the text vector is divided into the first sub-vector space; when the eigenvalue of any text vector is less than the second eigenvalue of the segmentation point, the text vector corresponding to the eigenvalue of the text vector is divided into the second sub-vector space.
[0014] Furthermore, according to one aspect of the method disclosed herein, obtaining a question vector includes: segmenting the question into words; inputting the segmented question into a vector model to obtain a question vector; and using the vector model to transform the question into an embedding vector.
[0015] According to another aspect of this disclosure, a text processing apparatus is provided, comprising: an acquisition unit for acquiring a question vector; a first determination unit for performing a similarity retrieval on the question vector using a tree index structure to determine a first sequence; the tree index structure consists of at least two nodes, each node corresponding to a text vector; the first sequence includes at least one node; a second determination unit for determining a first number based on the similarity of the first node and a similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence; a third determination unit for determining a second number based on character count restriction information corresponding to multiple nodes of the first number in the first sequence; and a construction unit for selecting the second number of nodes in the first sequence and constructing a target vector; the target vector is used to generate response text for the question vector.
[0016] According to another aspect of this disclosure, an electronic device is provided, comprising: a memory for storing computer-readable instructions; and a processor for executing the computer-readable instructions, causing the electronic device to perform the method as described in any embodiment of one aspect.
[0017] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided for storing computer-readable instructions that, when executed by a processor, cause the processor to perform the method as described in any embodiment of one aspect.
[0018] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the method as described in any embodiment of one aspect.
[0019] This disclosure provides a text processing method, apparatus, electronic device, storage medium, and program product. The disclosure involves: obtaining a question vector; performing similarity retrieval on the question vector using a tree index structure to determine a first sequence; the tree index structure consists of at least two nodes, each node corresponding to a text vector; the first sequence includes at least one node; determining a first number based on the similarity of the first node and a similarity threshold; the first node being the node in the first sequence with the highest similarity to the question vector; the first number being used to adjust the number of nodes in the first sequence; determining a second number based on character count restrictions corresponding to multiple nodes of the first number in the first sequence; selecting the second number of nodes in the first sequence and constructing a target vector; and using the target vector to generate the response text for the question vector. Thus, by using a tree index structure to perform similarity retrieval on the question vector, nodes related to the question can be quickly located to form a first sequence, reducing unnecessary similarity calculations. Simultaneously, the first number can be dynamically determined based on the similarity of the first nodes, avoiding the problem of unreasonable recall numbers under a fixed threshold. Furthermore, by incorporating the character count limits for each node, the scope of text recall is further limited. This comprehensively considers both similarity and character count limitations, dynamically adjusting the number of recalled texts to ensure that the maximum amount of valid information is retained while meeting the character count limit. In summary, the solution provided in this disclosure reduces the number of similarity calculations, dynamically determines the number of texts to be recalled, improves efficiency, reduces latency, and increases accuracy.
[0020] It should be understood that both the foregoing general description and the following detailed description are exemplary and intended to provide further illustration of the claimed technology. Attached Figure Description
[0021] The above and other objects, features, and advantages of this disclosure will become more apparent from the more detailed description of the embodiments thereof in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of this disclosure and form part of the specification. They are used together with the embodiments of this disclosure to explain the disclosure and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.
[0022] Figure 1 A flowchart for generating response text for an existing knowledge base question-answering system;
[0023] Figure 2 A flowchart illustrating a text processing method provided in an embodiment of this disclosure;
[0024] Figure 3 A schematic diagram of a text processing process provided for embodiments of this disclosure;
[0025] Figure 4A flowchart for similarity retrieval based on a tree index structure provided in this embodiment of the disclosure;
[0026] Figure 5 This is a schematic diagram illustrating the establishment of a tree-like index structure provided in an embodiment of this disclosure;
[0027] Figure 6 A schematic diagram of the overall text processing flow provided for embodiments of this disclosure;
[0028] Figure 7 A schematic diagram of a preferred embodiment of the constructed index provided in this disclosure;
[0029] Figure 8 A schematic diagram illustrating a preferred embodiment of similarity retrieval provided in this disclosure;
[0030] Figure 9 A structural block diagram of a text processing apparatus provided in an embodiment of this disclosure;
[0031] Figure 10 A hardware block diagram of an electronic device provided in an embodiment of this disclosure;
[0032] Figure 11 This is a schematic diagram of a computer-readable storage medium provided in an embodiment of this disclosure. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of this disclosure more apparent, exemplary embodiments according to this disclosure will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this disclosure, and not all embodiments of this disclosure. It should be understood that this disclosure is not limited to the exemplary embodiments described herein.
[0034] Currently, the method for generating response text in Knowledge Base Question Answering Systems (KBQA) is usually to first determine the similarity between the user's question and the text in the knowledge base, then compare it with a preset similarity threshold, and finally input the knowledge base text and the user's question that meet the similarity threshold into a large language model to obtain the response text.
[0035] However, this method of recalling knowledge base texts related to user questions based on similarity thresholds is relatively fixed, and the large number of recalled texts and the numerous similarity calculations result in significant delays in generating response texts. Furthermore, a large number of recalled texts may exceed the system's character limit, causing the system to discard a large amount of valid information and reducing the accuracy of the generated response text.
[0036] For example, Figure 1A flowchart for generating response text for an existing knowledge base question-answering system. From... Figure 1 It can be seen that the existing process for generating response text is as follows: 1. First, segment the document. 2. Vectorize the segmented text. 3. Build a vector index for the text vectors and store them in a vector database. 4. When the user inputs a question, the question text is also vectorized to obtain the user question vector. The similarity between the question text and each text in the vector database is determined based on the vector index. The text vectors in the vector database with similarity greater than or equal to a preset fixed threshold are sorted and filtered to obtain filtered text vectors. The filtered text vectors are combined with the user's input question text to form prompt words. The prompt words are input into a large language model to generate the corresponding response text, which is then returned to the user.
[0037] Therefore, this disclosure proposes a text processing method that uses a tree-based index structure to perform similarity retrieval on question vectors. This method can quickly locate nodes related to the question to form a first sequence, reducing unnecessary similarity calculations. Simultaneously, the first number can be dynamically determined based on the similarity of the first node, avoiding the problem of unreasonable recall quantity under a fixed threshold. Furthermore, combining the word count limit information corresponding to each node further restricts the scope of text recall. This comprehensively considers both similarity and word count limitations, dynamically adjusting the number of recalled texts to ensure that the maximum amount of effective information is retained while meeting the word count limit. Please refer to [reference needed]. Figure 2 , Figure 2 This is a flowchart illustrating a text processing method provided in an embodiment of this disclosure. Figure 2 As shown, the method includes:
[0038] In step S201, the problem vector is obtained.
[0039] In this disclosure, user-input text can be converted into a vector form that a computer can understand and process, thus obtaining a question vector, through models or algorithms. No specific models or algorithms are limited.
[0040] In step S202, a similarity search is performed on the question vector using a tree index structure to determine the first sequence; the tree index structure consists of at least two nodes, and any node corresponds to a text vector; the first sequence includes at least one node.
[0041] In this disclosure, the tree-structured index consists of nodes corresponding to at least two text vectors. Each node in the tree structure corresponds to one text vector. The hierarchical organization of the tree structure clearly presents the relationships between text vectors. Starting from the root node, branches can be established based on at least one of the following: the category, subject, or feature value of the content represented by the text vector. This organization greatly improves the orderliness of data storage and avoids the chaotic accumulation of text vectors. When performing similarity retrieval, the hierarchical tree structure can quickly narrow down the search scope.
[0042] In this disclosure, the first sequence is a sorted sequence of nodes with high similarity to the question vector. In the embodiments of this disclosure, similarity can be understood as the Euclidean distance between the text vector of a node and the question vector; the closer the Euclidean distance, the higher the similarity.
[0043] In this disclosure, when performing similarity retrieval, a tree structure can be used to quickly and accurately determine sequences with high similarity based on at least one field or feature related to the question vector, thereby reducing unnecessary similarity calculations.
[0044] In step S203, a first number is determined based on the similarity of the first node and the similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence.
[0045] In this disclosure, the first number can be understood as being determined jointly based on the first node with the highest similarity to the question vector and a similarity threshold. The similarity of the first node relates to the number of nodes that need to be selected in the first sequence. For example, the higher the similarity of the first node, the wider its semantic range may be, and the richer the potential information associated with the question vector. In order to fully obtain this relevant information, more nodes need to be selected. Conversely, if the similarity of the first node is low, it means that its matching degree with the question vector is limited, and only a small number of closely related nodes need to be selected. In this way, the approximate range of the number of nodes required in the first sequence can be initially estimated based on the similarity of the first node. Furthermore, by comparing each node with the similarity threshold after narrowing down the range, nodes that are truly related to the question vector can be screened more accurately and efficiently. Compared with direct comparison in the entire first sequence, this method of first estimating the range based on the similarity of the first node and then comparing the threshold to narrow down the range can reduce a lot of unnecessary calculation and screening work and improve screening efficiency. Thus, the set of nodes corresponding to the determined first number has both high relevance to the question vector and can be processed within limited system resources and time. The similarity threshold is preset and can be set by the user or the system. It can be changed flexibly and is not restricted here.
[0046] In step S204, a second number is determined based on the word count restriction information corresponding to a first number of nodes in the first sequence.
[0047] In this disclosure, the second number can be understood as determining the second information based on multiple nodes of the first number within a narrowed scope, taking into account the word count limitations of the actual application scenario. The word count limitations can be configured by the system, and the word count limitations can differ for different application scenarios.
[0048] In this disclosure, the process of determining the second number is a crucial step in further optimizing the nodes selected in the preceding steps. It closely integrates text processing with practical application scenarios, ensuring the usability of the generated text from the perspective of word count. By accurately grasping the word count limit, the entire text processing workflow not only focuses on semantic relevance but also adapts to different applications in terms of format and length, thereby improving the practicality and versatility of the processing results.
[0049] In step S205, a second number of nodes are selected in the first sequence and a target vector is constructed; the target vector is used to generate the response text of the question vector.
[0050] In this disclosure, after determining the second number, a corresponding number can be selected from the first sequence to determine the text vector corresponding to the second number of nodes. The target vector is determined by combining the text vector and the question vector. The target vector is then input into a large language model to obtain the response text to the question vector. In this way, by inputting the carefully constructed target vector into the large language model, the model can leverage its powerful semantic understanding and generation capabilities to deeply analyze the multi-node key information integrated in the target vector and the core demands contained in the question vector. Because the target vector accurately integrates node text vectors that are highly relevant to the question and meet the word limit, the large language model can avoid interference from irrelevant information during processing and focus on generating high-quality response text that fits the question.
[0051] By employing a tree-structured index to perform similarity retrieval on the question vector, the system can quickly locate nodes related to the question to form a first sequence, reducing unnecessary similarity calculations. Simultaneously, the first number of retrieved texts can be dynamically determined based on the similarity of the first node, avoiding the problem of unreasonable recall numbers under a fixed threshold. Furthermore, combining the word count limitations corresponding to each node further restricts the scope of text recall. This comprehensively considers both similarity and word count limitations, dynamically adjusting the number of recalled texts to ensure that the maximum amount of effective information is retained while meeting the word count limit. In summary, the solution provided in this disclosure reduces the number of similarity calculations, dynamically determines the recall number, improves efficiency, reduces latency, and increases accuracy.
[0052] For example, Figure 3This is a schematic flowchart illustrating text processing provided for embodiments of this disclosure. Figure 3 It can be seen from this:
[0053] Compared to the above Figure 2 The existing system, Figure 3 The text processing system disclosed herein includes two improvements: improvement 1 is a retrieval module; improvement 2 is a module for dynamically setting similarity scores and recall. Improvement 1, the retrieval module, can perform fast retrieval using a tree-structured index. Improvement 2, the module for dynamically setting similarity scores and recall, allows for flexible setting of the recall number based on similarity scores ranked by similarity.
[0054] Figure 3 The overall process of this disclosure is as follows: 1. First, the document is segmented. 2. The segmented text is vectorized. 3. A vector index, i.e., a tree-like index structure, is built from the text vectors and stored in a vector database. 4. When the user inputs a question, the question text is also vectorized to obtain the user question vector. Using the newly added retrieval module, the similarity and similarity ranking sequence between the question text and each text in the vector database are determined based on the vector index of the tree-like index structure. Next, using the similarity score and recall dynamic setting module, the number of texts to be filtered is determined based on the similarity score, similarity threshold, and character limit information of the ranked texts in the vector database. That is, the number of texts in the vector database to be filtered in the similarity ranking sequence. Finally, the filtered texts in the vector database are combined with the question text input by the user to form a prompt word. The prompt word is input into the large language model to generate the corresponding response text, which is then returned to the user.
[0055] The following will explain in detail how to use a tree-structured index for similarity retrieval, including the following methods:
[0056] The tree index structure is used to recursively search downwards until the second node is obtained; the second node is a node in a subvector space that contains only one node.
[0057] Starting from the second node, based on the similarity between the question vector and each node, the process is recursively searched upwards until the first node is obtained;
[0058] In the first retrieval path from the second node to the first node, the first sequence is determined by sorting each node according to its similarity to the question vector.
[0059] In this disclosure, the first sequence is a sequence with a high similarity to the question vector, and may include all nodes in the first retrieval path, namely the second node, all historical nodes from the second node to the first node, and the second node itself. The second node is a node with only one node in the sub-vector space. This second node can represent the most granular text vector in the tree structure, that is, the node at the lowest level of the tree structure.
[0060] In this embodiment of the disclosure, when using a tree index structure for similarity retrieval, the search first proceeds downwards. It can start from the root node and determine the sub-vector space layer by layer, recursively until it reaches the node in the sub-vector space that has only one node, namely the second node.
[0061] Next, after reaching the second node, a recursive upward search can be performed based on the similarity between the question vector and each node. Specifically, the process can be as follows: Backtrack from the second node to its parent node, calculate the similarity between the question vector and the parent node of the second node and all its sibling nodes, select the node with the highest similarity as the new search node, and record this node as a historical node. Repeat this process until returning to the root node; the node with the highest similarity to the question vector is the first node.
[0062] Ultimately, the first sequence is determined by the second node in the first retrieval path, the historical nodes from which the first node is derived (i.e., historical nodes on the path with higher similarity to the second node), and the first node itself. The nodes in this sequence are then sorted from high to low similarity to the question vector, forming a set with high similarity to the question vector.
[0063] This retrieval method, through a hierarchical recursive strategy, transforms the computational workload of traversing the entire vector space into a smaller search, significantly improving retrieval efficiency. Simultaneously, by comparing sibling nodes during backtracking, it ensures that potential highly similar nodes are not overlooked during path selection, balancing accuracy and comprehensiveness in the retrieval process.
[0064] When using a tree structure for retrieval, it is necessary to recursively search downwards before searching upwards. The following explains in detail how to recursively search downwards:
[0065] Starting from the root node of the tree index structure, the search proceeds recursively downwards until the second node is reached:
[0066] For the root node, determine the relationship between the first eigenvalue of the problem vector and the second eigenvalue of the split point; the split point is used to divide the first sub-vector space and the second sub-vector space.
[0067] If the first eigenvalue is greater than or equal to the second eigenvalue, search downwards from the first sub-vector space;
[0068] If the first eigenvalue is less than the second eigenvalue, search downwards from the second sub-vector space.
[0069] In this disclosure, the second node is a node with only one node in the subvector space. This second node can represent the most granular text vector in the tree structure, that is, the node at the lowest level of the tree structure.
[0070] In this embodiment, the recursive downward search starts from the root node and continues until the second node is reached. The specific process is as follows: Starting from the root node, determine the relationship between the first feature value of the question vector and the second feature value of the root node's split point. The split point of the root node is the basis for dividing all nodes into the first sub-vector space and the second sub-vector space, relative to the root node. Based on this, determine the relationship between the first feature value of the question vector and the second feature value of the root node's split point. If the first feature value is greater than or equal to the second feature value, the node with a higher similarity to the question vector is located in the first sub-vector space; if the first feature value is less than the second feature value, the node with a higher similarity to the question vector is located in the second sub-vector space. This process continues. After entering the first or second sub-vector space, the root node of that sub-space is considered the new current node, and the operation of determining the relationship between the first feature value of the question vector and the second feature value of the current node's split point is repeated. The comparison result is used to select which sub-vector space to enter in the next layer. Each recursion continuously narrows the search range based on the feature value comparison result, continuously delving deeper into the next layer of the tree structure.
[0071] In this way, by recursively searching downwards, nodes with high similarity to the question vector can be efficiently located from the massive tree-like index structure. As the recursion progresses, the vector subspace is continuously subdivided, eventually reaching a point where there is only one node in the subspace, i.e., the second node. This method, based on feature value comparison and recursive retrieval, avoids blindly traversing the entire tree structure, greatly improving retrieval efficiency. It also accurately identifies the most subdivided text vector in the tree structure that best matches the question vector, laying a solid foundation for generating accurate response text.
[0072] For example, the specific steps of recursive downward retrieval can be as follows:
[0073] Assuming the problem vector is the target point t, we recursively search downwards starting from the root node.
[0074] In each recursive step, the coordinates of t are compared with the value of the split point. If the coordinates of t are less than the value of the split point, the next step is to search downwards from the left subspace (i.e., the second vector space). Otherwise, the search continues downwards from the right subspace (i.e., the first vector space) until a subspace containing a unique vector is found.
[0075] The following explains in detail how to recursively search upwards:
[0076] For any node in the second search path, in the child vector space corresponding to the parent node of the node, determine the third node with the highest similarity to the question vector; the second search path is the path from the second node to the root node;
[0077] Using the third node as the reference point, the search proceeds recursively upwards until the root node is reached.
[0078] The third node in the subvector space corresponding to the root node is determined as the first node.
[0079] In this disclosure, the third node can be understood as the node with the highest similarity to the question vector within the sub-vector space covered by the parent node of the currently retrieved node. It is the optimal node selected from all child nodes under the parent node at each level of recursive upward retrieval, providing direction for further upward searching for more suitable nodes.
[0080] In this disclosure, the second retrieval path is the path from the second node to the root node, which is the reverse path of the path obtained by the above recursive downward retrieval.
[0081] In this embodiment, the recursive upward retrieval is a further optimization and expansion of the previous downward retrieval results to ensure that the node with the highest similarity to the question vector is found. The specific process can be as follows: Starting from the second node obtained through downward retrieval, which is at the bottom level of the tree structure and is the only single node in the sub-vector space. First, determine the parent node of this second node. The sub-vector space corresponding to this parent node can contain multiple child nodes (including the second node). Then, calculate the similarity between the question vector and all child nodes under this parent node, find the node with the highest similarity, and determine it as the third node. Next, using this third node as the new reference point, repeat the above steps. That is, determine the parent node of the third node, and recalculate the similarity between each child node and the question vector in its corresponding sub-vector space to find a new third node. This process continues recursively upwards, with each level filtering out the node with the highest similarity to the question vector in the sub-vector space of the parent node, gradually progressing towards the root node. When the recursion reaches the root node, the third node in the sub-vector space corresponding to the root node is the final first node to be determined. The similarity between this first node and the question vector in the entire tree index structure is the optimal result obtained after filtering from bottom to top.
[0082] In this way, by recursively searching upwards, the hierarchical information of the tree index structure can be fully utilized. Based on the initial positioning by searching downwards, nodes with higher similarity to the question vector can be searched in a wider vector space. This avoids the situation where the global optimum may be missed due to local optima during the downward search process, and improves the matching degree between the first node found and the question vector. This provides a more accurate basis for generating high-quality response text.
[0083] It's important to note that during recursive upward retrieval, the first node can be determined based on the third node. The third node can have two different cases:
[0084] Using a node as a reference point, determine whether the node's parent node is a node with a higher similarity to the question vector;
[0085] When a node has a higher similarity to the question vector, it is determined to be the third node;
[0086] When the parent node of a node has a higher similarity to the problem vector, determine whether there exists a fourth node in the other child vector space of the parent node that has a higher similarity to the problem vector; if there is a fourth node, determine the fourth node as the third node; if there is no fourth node, determine the parent node as the third node.
[0087] In one embodiment of this disclosure, when determining whether the parent node of the second node is a node with a higher similarity to the question vector, if the second node has a higher similarity to the question vector, then the second node is the third node under the parent node.
[0088] In another embodiment of this disclosure, after determining that the parent node of the second node has a higher similarity to the question vector, it is then necessary to determine whether a fourth node with a higher similarity to the question vector exists in the other sub-vector space of that parent node. This can be determined by calculating the similarity between all nodes in the other sub-vector space of the parent node and the question vector. If such a fourth node does exist, then that fourth node is identified as the third node.
[0089] For example, the following details how to perform a recursive search:
[0090] The specific steps are as follows:
[0091] 1) Recursive Downward Search: Assuming the problem vector is the target point t (i.e., the problem vector of this disclosure), in the constructed index, starting from the root node, a recursive downward search is performed. At each recursive step, the coordinates of t are compared with the value of the split point (i.e., the split point of this disclosure). If the coordinates of t are less than the value of the split point, the search continues downward from the left subspace; otherwise, it continues downward from the right subspace, until a subspace containing a unique vector is found. Alternatively, at each node in the recursion, the distance between the node and the target point t can be calculated and inserted into a sorted queue. This queue only stores the K closest nodes in ascending order. Once the number of elements in the queue exceeds K, the node with the largest distance in the queue is deleted. The range of values for K is specified in the configuration file.
[0092] 2) Recursive upward retrieval: Taking the unique vector found in step 1) as the "current nearest point" (i.e., the second node of this disclosure), recursively backtrack upwards. The backtracking path is the path from the second node to the root node. At each node, the following operations are performed:
[0093] ① If the node is closer to the target point than the "current nearest point", then update the "current nearest point" to the node.
[0094] Specifically, determining the distance between nodes involves comparing the values of their Euclidean distances (d). Euclidean distance is used to calculate the distance between two points.
[0095] ② Check if there is a point closer to the target point in the region corresponding to the other child node of the parent node of the "current nearest point". If so, update the "current nearest point" to that other child node (i.e., the third node in this disclosure). Specifically, check if the region corresponding to the other child node intersects with the "hypersphere with the target point as the center and the distance between the target point and the "current nearest point" as the radius". If they intersect, there may be a point closer to the target point in the region corresponding to the other child node, so continue the nearest neighbor search recursively from the other child node; if they do not intersect, backtrack upwards.
[0096] 3) When the search reaches the root node, the search ends, and the final "current nearest point" is the nearest neighbor of the target point t. At this point, the first K vectors can be read from the sorted queue.
[0097] For example, Figure 4 This is a flowchart illustrating similarity retrieval based on a tree index structure, provided as an embodiment of this disclosure. From Figure 4It can be seen that the entire similarity retrieval process includes: for each vector space, comparing the target point's coordinates with the segmentation point's values along the spatial segmentation dimension. Specifically, the coordinates of the target point's segmentation dimension ki are compared with the values v of the segmentation points. When the value of ki is less than v, the search proceeds downwards from the left subspace to determine if the number of vectors in the space is 1. If it is 1, the unique vector space found is set as the "current nearest point." If it is greater than 1, the search continues until the "current nearest point" is obtained. Similarly, when the value of ki is greater than v, the search proceeds downwards from the right subspace to determine if the number of vectors in the space is 1. If it is 1, the unique vector space found is set as the "current nearest point" (i.e., the second node of this disclosure). If it is greater than 1, the search continues until the "current nearest point" is obtained. After determining the "current nearest point", the system recursively backtracks upwards to determine if the node reached is closer to the target point than the "current nearest point". If it is determined to be closer, the "current nearest point" is updated to that node, and the system checks if the region corresponding to the other child node of the "current nearest point"'s parent node has a point closer to the target point. That is, it determines whether the region corresponding to the other child node intersects with the "hypersphere". If it is determined to intersect, the recursive search continues from the other child node to further determine if it has backtracked to the root node. If it is determined to have, the final "current nearest point" is determined as the nearest neighbor of the target point t (i.e., the first node of this disclosure). Correspondingly, if it is determined that the region corresponding to the other child node does not intersect with the "hypersphere", the system continues backtracking upwards to further determine if it has backtracked to the root node. If it is determined to have, the final "current nearest point" is determined as the nearest neighbor of the target point t.
[0098] The following details how to determine the first number using the similarity of the first node and a similarity threshold. The method includes:
[0099] Based on the similarity between the first node and the question vector, select the third number of nodes with higher similarity ranking in the first sequence;
[0100] For each node in the third number, determine the similarity between each node and the question vector, and compare it with the similarity threshold respectively;
[0101] Among the third number of nodes, the number of nodes that meet the similarity threshold is determined as the first number.
[0102] In this disclosure, the similarity between the first node and the question vector can be understood as a similarity score determined based on the Euclidean distance between the first node and the question vector. The similarity score can be calculated using the following formula: Similarity score = 1 / (1 + 2 * Euclidean distance). In this disclosure, the similarity threshold can be set by the system or the user and can be flexibly adjusted without specific limitations.
[0103] In this disclosure, firstly, the first node is the node with the highest similarity to the question vector. Based on its similarity score, a third number can be determined, and nodes with a higher similarity ranking in the first sequence are selected from the third number. This allows for dynamic adjustment of the filtering range based on the association strength of the head nodes, balancing filtering accuracy and computational cost. The third number can be determined using the following formula: Third number = 20 + (Similarity score of the first node - 0.825) * 200, rounded down. For example, if the similarity score of the first node is 0.88, substituting into the formula, we get: Third number = 20 + (0.88 - 0.825) × 200 = 20 + 11 = 31, rounded down to 31. Next, each node in the third number is compared with a similarity threshold. When a node's similarity score reaches or exceeds the threshold, the node is deemed to meet the filtering criteria. Finally, the number of nodes in the third number that meet the similarity threshold is counted and determined as the first number. By dynamically calculating the third number, the selection range can be adaptively adjusted according to the similarity fluctuations of the head nodes: if the similarity of the first node is significantly higher than the benchmark value (0.85), the selection range is expanded to discover more potential related nodes; if the similarity is close to the benchmark value, the range is narrowed to focus on the core nodes, ultimately ensuring that the first number nodes have a high semantic correlation with the question vector.
[0104] It should be noted that this disclosure can also restrict the range of the first number. When the determined first number is greater than or equal to 50, the first number can be set to 50; when the determined first number is less than 0, the first number can be set to 0. This ensures reasonable allocation of system resources and avoids computational overload due to too many nodes or information loss due to too few nodes. The specific threshold for restricting the range of the first number can be flexibly set and is not limited.
[0105] In this embodiment, a practical application scenario is used as an example: Assume that in the system, the first sequence contains 50 nodes. For the first node of this sequence, the similarity score is calculated as 0.88 using the formula: similarity score = 1 / (1 + 2 * Euclidean distance). Substituting this into the formula for the third number, we get: third number = 20 + (0.88 - 0.825) × 200 = 20 + 11 = 31, rounded down to 31. Therefore, the first 31 nodes can be selected from the first sequence. Then, for these 31 nodes, their similarity scores are compared one by one with a preset similarity threshold (e.g., 0.7). If the similarity scores of 7 nodes are ≥ 0.7, then these 7 nodes that meet the condition are determined as the first number.
[0106] The following will explain in detail how to obtain the second number by considering the corresponding numerical constraints for multiple nodes of the first number. The method includes:
[0107] Select the first number of nodes with the highest similarity ranking in the first sequence;
[0108] Obtain the word count limit information corresponding to each of the first number of nodes; the word count limit information includes at least one of the following: the number of words in the node, the number of words in the question vector, and the number of words in the response text;
[0109] The second number is determined based on the character limit information corresponding to each node.
[0110] In this disclosure, each node corresponds to a text vector, and the text content corresponding to that text vector has a different number of characters.
[0111] In this disclosure, word count limits can be understood as including, but not limited to, at least one of the following: the word count of a node: which can represent the number of characters in the node's text content and reflect the level of detail of the node's content; the word count of the question vector, which is the word count of the text corresponding to the user's input question after processing, reflecting the complexity of the question; and the word count of the response text, which is the system's preset word count limit for the answer (e.g., requiring the final answer to not exceed 800 words), used to control the scale of the output content. Word count limits can be system-set and are not restricted here.
[0112] In this disclosure, after determining the word count and word limit information for each of the first number of nodes, the average word count of all nodes is calculated, and a second number is determined in conjunction with the word limit of the response text, so that the final generated response text can meet the word limit requirement, thus determining the final number of nodes selected in the first sequence. In this way, by quantitatively analyzing the matching relationship between the level of detail of the node content and the system output requirements, a balance is achieved between information completeness and conciseness of expression.
[0113] In this embodiment of the disclosure, the specific method for determining the second number can satisfy the following formula: Second number = (number of words in the response text - number of words in the node - number of words in the question text) / average number of words corresponding to the node, rounded down.
[0114] It should be noted that this disclosure can also restrict the range of the second number. When the determined second number is greater than or equal to 5, the first number can be set to 5; when the determined second number is less than 1, the second number can be set to 1. This ensures reasonable allocation of system resources and avoids computational overload due to too many nodes or information loss due to too few nodes. The specific threshold for restricting the range of the second number can be flexibly set and is not limited.
[0115] The following will explain in detail how this disclosure establishes a tree-like index structure:
[0116] Text processing methods also include: constructing a tree-like index structure;
[0117] Constructing a tree-structured index includes:
[0118] For any vector space, the text vector with the largest feature variance value in the vector space is determined as the root node of the vector space;
[0119] Based on the feature value relationship between the features of each text vector, each text vector is divided into the first sub-vector space and the second sub-vector space corresponding to the root node;
[0120] Repeat the partitioning until each sub-vector space contains only one text vector.
[0121] In this disclosure, a tree-based index structure needs to be constructed before retrieval using this structure. First, when constructing the tree-based index structure, for any vector space, the text vector with the largest feature variance value among the vectors is identified as the root node. For example, in a vector space, a text vector has two features: X and Y. For all text vectors, the variance of their X and Y values is calculated. If the variance of X is greater than the variance of Y, the root node is indexed as the X value. If the variance of Y is greater than the variance of X, the root node is indexed as the Y value. Next, based on the relationship between the features of each text vector, a partition is determined, and all text vectors are divided into two sub-vector spaces according to this feature value. This partitioning can be performed by determining the split point, as detailed later in the embodiments. The above process is repeated: in the first sub-vector space, the variance values of the remaining features are recalculated, the feature with the largest variance is selected as the new root node, and the partitioning is repeated; the second sub-vector space also recursively performs feature variance selection and partitioning operations until each sub-vector space contains only one text vector.
[0122] The following section will elaborate on how to divide the nodes as mentioned above. The methods include:
[0123] Determine the segmentation point; the segmentation point is the node corresponding to the median of the feature values of each text vector.
[0124] When the feature value of any text vector is greater than or equal to the second feature value of the segmentation point, the text vector corresponding to the feature value of the text vector is assigned to the first sub-vector space;
[0125] When the eigenvalue of any text vector is less than the second eigenvalue of the split point, the text vector corresponding to the eigenvalue of the text vector is assigned to the second sub-vector space.
[0126] In this disclosure, when partitioning text vectors, a split point can be determined. The split point can be the median of the eigenvalues of each text vector under the current root text vector feature. To determine the split point, the eigenvalues of all text vectors under that feature are first sorted, and then the eigenvalue at the middle position is selected as the split point; if the number of text vectors is even, the average of the two middle eigenvalues is usually taken. When the eigenvalue of any text vector is greater than or equal to the second eigenvalue of the split point, the text vector can be partitioned into the first vector subspace. When the eigenvalue of any text vector is less than the second eigenvalue of the split point, the text vector can be partitioned into the second vector subspace. In this way, by clearly defining the split point and partitioning the text vectors into different sub-vector spaces according to the relationship between the eigenvalues and the split point, a hierarchical tree-like index structure can be constructed.
[0127] For example, methods for building a tree-structured index include:
[0128] 1) Determine the dimension of the segmentation index structure: Calculate the variance of the values of each of the d features from all N vectors, and use the ki-th feature with the largest variance as the root node of the index structure.
[0129] 2) Determine the segmentation data points: For the ki-th dimension feature in step 1), select the sample corresponding to the median v of the values in the ki-th dimension of the entire vector as the segmentation data points.
[0130] 3) Segmentation vector: For all vectors whose ki-th feature value is less than v, they are assigned to the left sub-vector space; for vectors whose ki-th feature value is greater than or equal to v, they are assigned to the right sub-vector space.
[0131] 4) Recursively iterate the left and right subspaces respectively: For the left and right subspaces, use the same method as in step 1) to find the feature with the largest variance to make the root node of the next level. Use the same method as in steps 2) and 3) to further divide each subspace and vector set. Continue in this way until each vector is assigned to a unique subspace that contains it.
[0132] For example, Figure 5 This is a schematic diagram illustrating the establishment of a tree-like index structure provided in an embodiment of this disclosure. From... Figure 5It can be seen that the entire process of establishing the index structure can be as follows: For any vector space, calculate the variance of the d-dimensional feature values of all vectors in the vector space, and select the dimension ki with the maximum variance. Select the median v of the values in the ki-th dimension of all vectors. And determine the magnitude of the value of the ki-th dimension of each vector relative to v. When the value of the ki-th dimension is less than v, the vector belongs to the left sub-vector space. And determine whether the number of vectors in the space is 1. If it is greater than 1, then redetermine the partition. When it is equal to 1, the index structure establishment ends. Correspondingly, when the value of the ki-th dimension is greater than or equal to v, the vector belongs to the right sub-vector space. And determine whether the number of vectors in the space is 1. If it is greater than 1, then redetermine the partition. When it is equal to 1, the index structure establishment ends.
[0133] The following will explain in detail how to obtain the problem vector, including the following methods:
[0134] The question is processed by word segmentation;
[0135] The segmented questions are input into a vector model to obtain question vectors; the vector model is used to transform questions into embedding vectors.
[0136] In this disclosure, before obtaining the question vector, the user-input question needs to be segmented. This can be done using at least one of a word segmenter, natural language processing tools, or similar methods. Next, the segmented text can be input into a vector model to obtain the embedding vector. The vector model can include, but is not limited to, at least one of the following: bag-of-words model, term frequency-inverse document frequency model, global word vector model, etc., which can be used in combination or individually to obtain the question vector.
[0137] For example, Figure 6 This is a schematic diagram of the overall text processing flow provided for embodiments of this disclosure.
[0138] from Figure 6 It can be seen that the entire text processing flow is as follows:
[0139] Step 1: Vectorization of external documents.
[0140] 1) Use a word segmenter to segment external document text. You can segment the text at punctuation marks or (and) segment the text with a certain character limit.
[0141] 2) Vectorization is performed on each segmented text using a vector model. During vectorization, the vector dimension is typically standardized using a fixed-size word embedding matrix or a specific model, such as word embedding techniques like the bag-of-words algorithm. This model can convert each word in a sentence of any length into a vector of the same dimension. The result is an embedding vector.
[0142] 3) Output: The set of embedding vectors for each segmented text in the document.
[0143] Step 2: Construct an index structure from the embedding vectors of the document text and store it in the vector database.
[0144] 1) Determine the dimension of the segmentation index structure: Calculate the variance of the values of each of the d features from all N vectors, and use the ki-th feature with the largest variance as the root node of the index structure.
[0145] 2) Determine the segmentation data points: For the ki-th dimension feature in step 1), select the sample corresponding to the median v of the values in the ki-th dimension of the entire vector as the segmentation data points.
[0146] 3) Segmentation vector: For all vectors whose ki-th feature value is less than v, they are assigned to the left sub-vector space; for vectors whose ki-th feature value is greater than or equal to v, they are assigned to the right sub-vector space.
[0147] 4) Recursively iterate the left and right subspaces respectively: For the left and right subspaces, use the same method as in step 1) to find the feature with the largest variance to make the root node of the next level. Use the same method as in steps 2) and 3) to further divide each subspace and vector set. Continue in this way until each vector is assigned to a unique subspace that contains it.
[0148] Step 3: Perform vector retrieval and sorting on the user question text vector and the text vector of all documents. The retrieval and sorting algorithm here is based on the vector index structure output in Step 2 above.
[0149] 1) Vectorize the user's question text.
[0150] The user question text is vectorized using the same tokenizer and vector model as in step one. The embedded vector of the user question text is then output.
[0151] 2) Index-based vector retrieval.
[0152] Based on a vector-based indexing structure, the question text vector is compared with all document text vectors to calculate their similarity. The document text vector with the highest similarity score to the question text vector, along with its similarity score, is then obtained. The specific retrieval process is described above and will not be repeated here.
[0153] 3) Dynamically determine the number of items to be recalled.
[0154] The adjusted value K of the recall K is calculated based on the similarity score of the top-ranked vector in the search results. Adj (i.e., the third number disclosed herein), to select the top K AdjOne vector is selected, and the rest are discarded. Then, starting from the top K... Adj Of the vectors, those with similarity scores below the similarity score threshold are discarded. Vectors with similarity scores above the threshold (i.e., the second number disclosed herein) are further adjusted for recall based on the number of characters in the corpus, and the final recall number N (i.e., the first number disclosed herein) is calculated. Output: The document text vectors with the highest similarity scores to the question text vectors, topN∈[1,5], and their similarity scores. See above for details, which will not be repeated here.
[0155] Step 4: Combine the text vectors of the top N most similar documents retrieved with the user's question text and the knowledge base's question-and-answer prompt text to form prompt words. This combination is then fed into the large model, which generates the answer and returns it to the user. Specifically:
[0156] The program takes the text corresponding to the top N document text vectors as input and concatenates it with the user's question text and the knowledge base's question-and-answer prompt text. This concatenated text is then fed into a large model, which generates the final answer text. The answer text is then output to the user.
[0157] Here is an example of a complete text processing implementation:
[0158] Step 1: Vectorization of external documents.
[0159] For example, the input text is: "A relatively intuitive encoding method is to use the dictionary sequence mentioned above. For example, for a problem with three categories, we can use 1, 2, and 3 to represent these three categories respectively. However, this encoding method has a problem: the model may incorrectly assume that there are some order or distance relationships between different categories, when in fact these relationships may not exist or have no practical meaning. To avoid this problem, one-hot encoding (also known as one-hot coding) is introduced. The basic idea of one-hot encoding is to map each category to a vector, where only one element has a value of 1, and the rest have values of 0. In this way, each category is independent of each other, and there is no order or distance relationship between them."
[0160] The jieba word segmenter, using a character limit of 128 characters and a period, yielded the following 6 groups of word segments:
[0161] The more intuitive encoding method is to use the dictionary sequence mentioned above. For example, for a problem with three categories, these three categories can be represented by 1, 2, and 3 respectively. However, this encoding method has a problem: the model might incorrectly assume that there are some order or distance relationships between different categories, when in fact these relationships may not exist or have no practical meaning. To avoid this problem, one-hot encoding (also known as one-hot encoding) was introduced. The basic idea of one-hot encoding is to map each category to a vector where only one element has a value of 1, and the rest have values of 0. This ensures that each category is independent of the others, with no order or distance relationship.
[0162] Next, we construct the vocabulary, which is a complete list of all words in the input text and their index values:
[0163] {'For example':0,'、':1,'Introduced':2,'Encoding method':3,'The':4,'Exists':5,'Indicates':6,'Problem':7,'That':8,'This':9,'Not':10,'Unique hot':11,'For':12,'Mentioned':13,'But':14,')':15,'Or':16,'Compare':17,'one':18,'2':19,'And':20,'Order Column ':21,'-':22,' is ':23,' hot':24,' adopts ':25,' 3':26,' where ':27,' or ':28,' for ':29,' has ':30,' such ':31,' mutual ':32,' can ':33,' is ':34,', ':35,' and ':36,' basic ':37,' distance ':38,' also ':39,' has ':40,' each ':41,' Error':42,'separately':43,'only':44,'above':45,'this':46,'category':47,'between':48,'element':49,'relationship':50,'mapping':51,'will':52,'called':53,'the rest':54,'avoid':55,'independent':56,'0':57,'model':58,'think':59,'practical meaning':60,'encoding':61,'value ':62,'(':63,'Different':64,'Land':65,'Will':66,'One':67,'1':68,'These':69,'Three':70,'Order':71,'Of':72,'To':73,'Actually':74,'Intuitive':75,'Use':76,'Some':77,'。':78,'Vector':79,'Thought':80,'Dictionary':81,'Possible':82}.
[0164] Next, the word segmentation results are converted into a list of integer sequences based on the vocabulary. The list contains 6 sets of integer sequences, each corresponding to one of the 6 word groups:
[0165] [[17,75,72,3,34,25,45,13,72,81,21,78],[0,35,12,67,40,70,47,72,7,35,33,76,68,1,19,36,26,43,6,46,70,47,78],[14,35,9,3,5,67,7,35,8,58,82,66,42,65,59,64,47,48,5,77,71,28,38,50,35,20,74,69,50,82,34,10,5,72,16,10,30,6 [0,72,78],[29,55,9,7,35,2,4,18,22,24,61,63,39,53,11,61,15,78],[18,22,24,61,72,37,80,34,52,41,47,51,73,67,79,35,27,44,67,49,72,62,23,68,35,54,49,72,62,23,57,78],[31,35,41,47,48,8,32,56,72,35,10,5,71,28,38,50,78]].
[0166] Next, we create the following offset vector, where the offset represents the position of each word group in the text:
[0167] tensor([0,12,35,75,93,125]).
[0168] Finally, the bag-of-words embedding algorithm from the torch library is used to convert the above integer sequence and offset vector into word embedding vectors. For the sake of simplicity in subsequent analysis, the dimension of the word embedding vector is defined as 2. After the algorithm is executed, the word embedding vectors corresponding to each group of words are as follows:
[0169] tensor([[0.4856,0.1595],[-0.2255,-0.5206],[-0.0113,-0.4032].
[0170] [-0.4064,-0.1177],[0.0668,-0.2612],[-0.1056,-0.3639]]).
[0171] Step 2: Construct an index structure from the embedding vectors of the document text and store it in the vector database.
[0172] Taking the word embedding vectors output by the aforementioned document segmentation as an example:
[0173] [[0.4856,0.1595],[-0.2255,-0.5206],[-0.0113,-0.4032].
[0174] [-0.4064,-0.1177],[0.0668,-0.2612],[-0.1056,-0.3639]]. The specific steps for building the index are as follows:
[0175] 1) Determine the splitting dimension: The variances of the 6 vectors in the x and y dimensions are 0.07686 and 0.04916, respectively. The variance in the x-axis is larger, so the splitting dimension is x.
[0176] 2) Determine the data segmentation point: Sort the data according to the values of each vector in the x-dimensional plane. The median of the 6 data points is -0.0113, so the segmentation vector is (-0.0113, -0.4032). Thus, this data point divides the coordinate plane with the line x = -0.0113.
[0177] 3) Save the information in Table 1 below to the vector database:
[0178]
[0179] Table 1
[0180] As can be seen from Table 1 above, the segmentation dimension is X, the node vector of the segmentation point is (-0.0113, -0.4032), and there is only one subspace.
[0181] 4) Recursively process the left and right subspaces: Divide the coordinate system into two parts by the line x = -0.0113: the part where x < -0.0113 is the left subspace, containing 3 vectors = {(-0.2255, -0.5206), (-0.4064, -0.1177), (-0.1056, -0.3639)}; the other part is the right subspace, containing 2 vectors = {(0.4856, 0.1595), (0.0668, -0.2612)}; then repeat the above process for the left and right subspaces respectively, that is, repeatedly execute steps 1) to 3) until each vector is assigned to its own unique subspace. The final vector space index structure is as follows. Figure 7 As shown, Figure 7 A schematic diagram of a preferred embodiment of the constructed index provided for embodiments of this disclosure. From Figure 7 It can be seen that each layer has its corresponding partitioning dimension and the final six subspaces.
[0182] Correspondingly, the data stored in the vector database for this vector index structure can be as shown in Table 2 below:
[0183]
[0184] Table 2
[0185] The node vectors and partition dimensions of each subspace can be found in Table 2 above.
[0186] In addition, the vector database can also store the correspondence between the original text and vectors, as shown in Table 3 below:
[0187]
[0188] Table 3
[0189] The text corresponding to each vector space can be found in Table 3 above.
[0190] Step 3. Perform vector retrieval and sorting on the user question text vector and the text vector of all documents. The retrieval and sorting algorithm here is based on the vector index structure output in Step 2 above.
[0191] 1) Vectorize the user's question text.
[0192] Input: User question text, e.g., "How can a question with three categories be represented?".
[0193] Processing: Vectorize the user question text using the same tokenizer and vector model as in step one.
[0194] Output: The embedding vector tensor of the user's question text ((-0.3544,-0.4081)).
[0195] 2) Index-based vector retrieval.
[0196] For each problem vector, find the top K vectors that are most similar to it (i.e., have the smallest distance metric):
[0197] The target point is the input question text embedding vector (-0.3544, -0.4081) (see [link]). Figure 8 , Figure 8 (A schematic diagram of a preferred embodiment of similarity retrieval provided in this disclosure) shows the following steps for finding the nearest neighbor:
[0198] 2.1). Recursive search to find the unique vector subspace: From the root node (-0.0113, -0.4032), the node (-0.1056, -0.3639) is found. During the search, the coordinate plane is divided by the line y = -0.3639. Since the search point has a y value of -0.4081, the right subspace is entered to find (-0.4064, -0.1177), forming the search path <(-0.0113, -0.4032), (-0.1056, -0.3639), (-0.4064, -0.1177)>. The "current closest point" is (-0.4064, -0.1177). The Euclidean distance between (-0.4064, -0.1177) and the target point is calculated to be 0.29502.
[0199] At this point, the data in the sorted queue is as shown in Table 4 below (K is set to 20):
[0200] Sort (K=20) Vector nodes distance 1 (-0.4064,-0.1177) 0.29502
[0201] Table 4
[0202] The vector nodes of the unique vector space found can be found in Table 4 above.
[0203] 2.2). Recursive upward backtracking search path: A circle is defined with the target point as the center and the Euclidean distance of 0.29502 from the target search point to the current nearest point as the radius (see...). Figure 8 Then, following the search path <(-0.0113,-0.4032),(-0.1056,-0.3639),(-0.4064,-0.1177)>, backtracking to (-0.1056,-0.3639), the Euclidean distance between this node and the target point is 0.2527. Therefore, this node is closer to the target point than the current nearest point, so (-0.1056,-0.3639) is updated to "current nearest point".
[0204] At this point, the updated sorted queue contains the data shown in Table 5 below:
[0205] Sort (K=20) Vector nodes distance 1 (-0.1056,-0.3639) 0.2527 2 (-0.4064,-0.1177) 0.29502
[0206] Table 5
[0207] The nodes that are closer to the vector nodes in the unique vector space can be found in Table 5 above.
[0208] 2.2.1). Check if there is a closer one in the other child node region: Use the same method to determine another green circle, centered on the target point with a radius of 0.2527. This circle intersects the line y = -0.3639 (see...). Figure 7Therefore, it is necessary to enter the left subspace of (-0.1056,-0.3639) for searching, which means adding the node (-0.2255,-0.5206) to the search path to get <(-0.0113,-0.4032),(-0.2255,-0.5206)>.
[0209] 2.2.2). Searching another subspace: The search continues to the node (-0.2255, -0.5206). The Euclidean distance between (-0.2255, -0.5206) and (-0.3544, -0.4081) is 0.17109, which is closer than (-0.1056, -0.3639). Therefore, the "current nearest point" is updated to (-0.2255, -0.5206), and the nearest distance is updated to 0.17109.
[0210] At this point, the updated sorted queue contains the data shown in Table 6 below:
[0211] Sort (K=20) Vector nodes distance 1 (-0.2255,-0.5206) 0.17109 2 (-0.1056,-0.3639) 0.2527 3 (-0.4064,-0.1177) 0.29502
[0212] Table 6
[0213] Nodes closer to the vector node that is empty than the unique vector, and nodes in another subspace that are closer to the found node, can all be found in Table 6 above.
[0214] 2.3). Backtracking to the root node: When backtracking to (-0.0113, -0.4032), a blue circle can also be determined, with (-0.3544, -0.4081) as the center and 0.17109 as the radius. This circle does not intersect the line x = -0.0113 (see...). Figure 7 At this point, the search path backtracking is complete, and the final "current nearest point" (-0.2255, -0.5206) is the nearest neighbor of the target point (-0.3544, -0.4081), with a nearest distance of 0.17109.
[0215] 2.4) Convert the distance value into a similarity score according to the similarity score formula:
[0216] Similarity score = 1 / (1+2*distance).
[0217] Finally, output Table 7 below:
[0218] Sort (K=20) Vector nodes Similarity score 1 (-0.2255,-0.5206) 0.745 2 (-0.1056,-0.3639) 0.664 3 (-0.4064,-0.1177) 0.629
[0219] Table 7
[0220] The vector nodes of the final first sequence and their corresponding similarity scores can be found in Table 7 above.
[0221] Output: The document text vectors with the highest similarity scores to the question text vectors in the top K ∈ [20, 50] and their similarity scores.
[0222] 3) Dynamically adjust the number of recalls.
[0223] Input: The top K vectors with the highest similarity scores obtained from the search results, along with their similarity scores.
[0224] 3.1) Adjust the recall based on the top-1 similarity score of the search result vector;
[0225] Specific algorithm:
[0226] First, the recall adjustment value = 20 + (top1 similarity score - 0.825) * 200, rounded down;
[0227] Then, if the recall adjustment value is greater than 50, then set the recall adjustment value to 50;
[0228] Finally, if the recall adjustment value is less than 0, then set the recall adjustment value to 0.
[0229] The similarity score of the top 1 vector is 0.745. Substituting this into the recall adjustment formula, we get:
[0230] The recall adjustment value = 20 + (0.745 - 0.825) * 200 = 4.011, which is rounded down to 4.
[0231] Furthermore, the recall adjustment value does not satisfy the two assumptions of this sub-step; therefore, the recall adjustment value in this example is 4. The final output is shown in Table 8 below:
[0232] Sort (4) Vector nodes Similarity score 1 (-0.2255,-0.5206) 0.745 2 (-0.1056,-0.3639) 0.664 3 (-0.4064,-0.1177) 0.629
[0233] Table 8
[0234] Table 8 shows the first sequence obtained after adjusting for the recall number.
[0235] 3.2) Entries with similarity scores below the threshold are directly discarded; if the number of remaining recall vectors after discarding is less than the set recall number, the smaller actual number is used for recall.
[0236] For example, if the similarity score threshold is set to 0.65, then the vector ranked 3rd in the example (-0.4064, -0.1177) has a score of 0.629, which is lower than this threshold, and is therefore discarded. The final output is shown in Table 9 below:
[0237] Sort (4) Vector nodes Similarity score 1 (-0.2255,-0.5206) 0.745 2 (-0.1056,-0.3639) 0.664
[0238] Table 9
[0239] The satisfied similarity threshold can be found in Table 9 above.
[0240] In the example, the text ranked 3 is: [To avoid this problem, one-hot encoding (also called one-hot encoding) is introduced].
[0241] It can be seen that for the user question: "How can a problem with three categories be represented", the text ranked 3 is indeed not suitable as answer corpus due to its excessively low score.
[0242] 3.3) Adjust the recall quantity according to the corpus word count of the vector;
[0243] Specific algorithm:
[0244] First, the recall quantity = (the maximum word count of the one-time prompt for the large model - the word count of the knowledge base question-answering prompt text - the word count of the user question text) / the average word count of the recalled corpus, rounded down;
[0245] Then, if the recall quantity is less than 1, set the recall quantity to 1;
[0246] Finally, if the recall quantity is greater than 5, set the recall quantity to 5.
[0247] For example, assume that the maximum word count of the one-time prompt for the large model is 128:
[0248] The knowledge base question-answering prompt text "<Instruction> Answer the question based on known information. < / Instruction><Known information>{{context}}< / Known information>, <Question>{{question}}< / Question>" has 70 words.
[0249] The user question text "How can a problem with three categories be represented" has 18 words.
[0250] The corpus text corresponding to the vector ranked 1st is "For example, for a problem with three categories, the three categories can be represented by 1, 2 and 3 respectively.", which has 34 words.
[0251] The corpus text corresponding to the vector ranked 2nd is "In this way, each category is independent of each other, with no order or distance relationship.", which has 28 words.
[0252] Substitute into the recall quantity formula of sub-step 3.1 in this section, we get:
[0253] Recall quantity = (128-70-18) / ((34+28) / 2) = 1.29, rounded down to 1.
[0254] And this recall quantity does not meet the two assumptions of this sub-step, so the recall quantity N in the example is 1. Finally, Table 10 below is output:
[0255] Sort (N=1) Vector nodes Similarity score 1 (-0.2255,-0.5206) 0.745
[0256] Table 10
[0257] It can be seen from the above Table 10 that the finally determined number of vector nodes of the first sequence is as shown in Table 10.
[0258] Meanwhile, query the corresponding text in the vector data according to the result vector, which is shown in the following Table 11:
[0259]
[0260] Table 11
[0261] It can be seen from the above Table 11: The corpus text corresponding to the output vector is "For example, for a problem with three categories, the three categories can be represented by 1, 2 and 3 respectively".
[0262] Step 4: Combine the retrieved corpora corresponding to the topN most similar document text vectors together with the user question text and the knowledge base question-answering prompt text into a prompt, which is transmitted to the large model, so that the large model generates a response and returns it to the user.
[0263] Input: the text corresponding to the topN document text vectors, as shown in Table 10.
[0264] Query the corresponding text in the vector data according to the vector, as shown in Table 11.
[0265] The corpus text corresponding to the output vector is "For example, for a problem with three categories, the three categories can be represented by 1, 2 and 3 respectively".
[0266] Spliced with the user question text and the knowledge base question-answering prompt text.
[0267] User question text: "How can a problem with three categories be represented".
[0268] With the knowledge base question-answering prompt text: "<Instruction> Answer the question based on the known information. < / Instruction><Known information>{{context}}< / Known information>, <Question>{{question}}< / Question>".
[0269] Spliced together to form: "<Instruction> Answer the question based on the known information. < / Instruction><Known information> For example, for a problem with three categories, the three categories can be represented by 1, 2 and 3 respectively. < / Known information>, <Question> How can a problem with three categories be represented < / Question>".
[0270] Input the spliced text into the large model, and the large model generates the final response text.
[0271] Output: The response text generated by the large model is given to the user.
[0272] This disclosure also provides a text processing apparatus. Figure 9 This is a structural block diagram of a text processing apparatus provided in an embodiment of the present disclosure, such as... Figure 9 As shown, the text processing device 900 includes:
[0273] Unit 901 is used to obtain the problem vector;
[0274] The first determining unit 902 is used to perform similarity retrieval on the question vector using a tree index structure to determine the first sequence; the tree index structure consists of at least two nodes, and any node corresponds to a text vector; the first sequence includes at least one node;
[0275] The second determining unit 903 is used to determine a first number based on the similarity of the first node and a similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence.
[0276] The third determining unit 904 is used to determine the second number based on the word count restriction information corresponding to the first number of nodes in the first sequence;
[0277] Construction unit 905 is used to select a second number of nodes in the first sequence and construct a target vector; the target vector is used to generate the response text of the question vector.
[0278] In one exemplary embodiment, the first determining unit 902 is specifically used to: recursively search downwards using a tree index structure until a second node is obtained; the second node is a node in a subvector space that includes only one node; starting from the second node, recursively search upwards based on the similarity between the question vector and each node until a first node is obtained; and determine the second node, the historical node from which the first node is obtained, and the first node as a first sequence.
[0279] In one exemplary embodiment, the first determining unit 902 is specifically used to: start from the root node of the tree index structure and recursively search downwards until the second node is obtained; for any node in the tree index structure, determine the relationship between the first feature value of the problem vector and the second feature value of the split point; the split point is used to divide the first sub-vector space and the second sub-vector space; when the first feature value is greater than or equal to the second feature value, search downwards from the first sub-vector space; when the first feature value is less than the second feature value, search downwards from the second sub-vector space; until the second node is obtained and the similarity between the second node and the problem vector is determined.
[0280] In one exemplary embodiment, the first determining unit 902 is specifically used to: for any node in the retrieval path, determine the third node with the highest similarity to the question vector in the sub-vector space corresponding to the parent node of the node; the retrieval path is the path from the second node to the root node; using the third node as the reference point, recursively search upwards until the root node is reached; and determine the third node in the sub-vector space corresponding to the root node as the first node.
[0281] In one exemplary embodiment, the first determining unit 902 is specifically configured to: use a node as a reference point to determine whether the parent node of the node is a node with a higher similarity to the problem vector; when the node has a higher similarity to the problem vector, determine the node as a third node; when the parent node of the node has a higher similarity to the problem vector, determine whether there is a fourth node with a higher similarity to the problem vector in another sub-vector space of the parent node; when a fourth node exists, determine the fourth node as a third node; when a fourth node does not exist, determine the parent node as a third node.
[0282] In one exemplary embodiment, the second determining unit 903 is specifically configured to: select a third number of nodes with higher similarity ranking in the first sequence based on the similarity between the first node and the question vector; the similarity ranking is based on the similarity to the question vector; for each of the third number of nodes, determine the similarity between each node and the question vector, and compare it with a similarity threshold respectively; among the third number of nodes, determine the number of nodes that meet the similarity threshold as the first number.
[0283] In one exemplary embodiment, the third determining unit 904 is specifically used to: select a first number of nodes with higher similarity ranking in the first sequence; obtain the number of characters and character limit information corresponding to each of the first number of nodes; the character limit information includes at least one of the following: the number of characters of the node, the number of characters of the question vector, and the number of characters of the response text; and determine a second number based on the number of characters and character limit information corresponding to each node.
[0284] In one exemplary embodiment, the first determining unit 902 is specifically used to: construct a tree index structure, including: for any vector space, determining the node with the largest feature variance value in the vector space as the root node of the vector space; any node corresponds to at least one feature; based on the feature value relationship between the features of each node, dividing each node into the first sub-vector space and the second sub-vector space corresponding to the root node; repeating the division until there is only one node in each sub-vector space.
[0285] In one exemplary embodiment, the first determining unit 902 is specifically used to: determine a segmentation point; the segmentation point is the node corresponding to the median of the feature values of each node; when the feature value of any node is greater than or equal to the second feature value of the segmentation point, the node corresponding to the feature value of the node is assigned to the first sub-vector space; when the feature value of any node is less than the second feature value of the segmentation point, the node corresponding to the feature value of the node is assigned to the second sub-vector space.
[0286] In one exemplary embodiment, the acquisition unit 901 is specifically used for: performing word segmentation on the question; inputting the segmented question into a vector model to obtain a question vector; and using the vector model to convert the question into an embedding vector.
[0287] Figure 10 This is a hardware block diagram of an electronic device provided according to an embodiment of the present disclosure. The electronic device 1000 according to an embodiment of the present disclosure includes at least a processor and a memory for storing computer-readable instructions. When the computer-readable instructions are loaded and executed by the processor, the processor performs the text processing method described in any of the preceding embodiments of the present disclosure.
[0288] Figure 10 The illustrated electronic device 1000 specifically includes a central processing unit (CPU) 1001, a graphics processing unit (GPU) 1002, and a memory 1003. These units are interconnected via a bus 1004. The CPU 1001 and / or GPU 1002 can function as the aforementioned processor, and the memory 1003 can function as the aforementioned memory storing computer-readable instructions. Furthermore, the electronic device 1000 may also include a communication unit 1005, a storage unit 1006, an output unit 1007, an input unit 1008, and an external device 1009, all of which are also connected to the bus 1004.
[0289] Figure 11 This is a schematic diagram of a computer-readable storage medium provided in an embodiment of this disclosure. (As shown...) Figure 11 As shown, a computer-readable storage medium 1100 according to an embodiment of the present disclosure stores computer-readable instructions 1101 thereon. When the computer-readable instructions 1101 are executed by a processor, the text processing method described with reference to the above figures according to any embodiment of the present disclosure is performed. The computer-readable storage medium includes, but is not limited to, volatile memory and / or non-volatile memory. Volatile memory may include, for example, random access memory (RAM) and / or cache memory. Non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, optical disk, magnetic disk, etc.
[0290] This disclosure further provides a computer program product, including a computer program that, when executed by a processor, implements the text processing method described in any of the preceding embodiments of this disclosure.
[0291] The present disclosure provides a text processing method, apparatus, electronic device, storage medium, and program product. The present disclosure obtains a question vector; performs similarity retrieval on the question vector using a tree index structure to determine a first sequence; the tree index structure consists of at least two nodes, each node corresponding to a text vector; the first sequence includes at least one node; a first number is determined based on the similarity of the first node and a similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence; a second number is determined based on the character count limit information corresponding to multiple nodes of the first number in the first sequence; the second number of nodes are selected in the first sequence and a target vector is constructed; the target vector is used to generate the response text for the question vector. Thus, by using a tree index structure to perform similarity retrieval on the question vector, nodes related to the question can be quickly located to form a first sequence, reducing unnecessary similarity calculations. Simultaneously, the first number can be dynamically determined based on the similarity of the first nodes, avoiding the problem of unreasonable recall numbers under a fixed threshold. Furthermore, by incorporating the character count limits for each node, the scope of text recall is further limited. This comprehensively considers both similarity and character count limitations, dynamically adjusting the number of recalled texts to ensure that the maximum amount of valid information is retained while meeting the character count limit. In summary, the solution provided in this disclosure reduces the number of similarity calculations, dynamically determines the number of texts to be recalled, improves efficiency, reduces latency, and increases accuracy.
[0292] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.
[0293] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.
[0294] The block diagrams of devices, apparatuses, devices, and systems disclosed herein are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.
[0295] Additionally, as used herein, the “or” used in a list of items beginning with “at least one” indicates a separate list, such that a list of, for example, “at least one of A, B, or C” means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word “exemplary” does not imply that the described example is preferred or better than other examples.
[0296] It should also be noted that in the systems and methods of this disclosure, the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered as equivalent solutions to this disclosure.
[0297] Various changes, substitutions, and modifications can be made to the technology described herein without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of this disclosure is not limited to the specific aspects of the processes, machines, manufactures, events, means, methods, and actions described above. Currently existing or later-developed processes, machines, manufactures, events, means, methods, or actions that perform substantially the same function or achieve substantially the same result as the corresponding aspects described herein can be utilized. Therefore, the appended claims include such processes, machines, manufactures, events, means, methods, or actions within their scope.
[0298] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of this disclosure. Therefore, this disclosure is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.
[0299] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.
Claims
1. A text processing method, characterized in that, The method includes: Obtain the problem vector; A similarity search is performed on the question vector using a tree index structure to determine a first sequence; the tree index structure consists of at least two nodes, and each node corresponds to a text vector; the first sequence includes at least one node; A first number is determined based on the similarity of the first node and a similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence. Based on the word count limit information corresponding to the first number of nodes in the first sequence, the second number is determined; Select the second number of nodes in the first sequence and construct a target vector; the target vector is used to generate the response text of the question vector.
2. The method according to claim 1, characterized in that, The step of using a tree index structure to perform similarity retrieval on the question vector to determine the first sequence includes: The tree index structure is used to recursively search downwards until the second node is obtained; the second node is a node in a subvector space that contains only one node. Starting from the second node, based on the similarity between the question vector and each node, the search is recursively performed upwards until the first node is obtained; In the first retrieval path from the second node to the first node, the first sequence is determined by sorting each node according to its similarity to the question vector.
3. The method according to claim 2, characterized in that, The recursive downward retrieval using the tree index structure until the second node is obtained includes: Starting from the root node of the tree index structure, the search proceeds recursively downwards in the following manner until the second node is obtained: For the root node, determine the relationship between the first feature value of the problem vector and the second feature value of the split point; the split point is used to divide the first vector subspace and the second vector subspace corresponding to the node; When the first feature value is greater than or equal to the second feature value, the search proceeds downwards from the root node in the first sub-vector space of the node. When the first feature value is less than the second feature value, the search proceeds downwards from the root node in the second sub-vector space of the node.
4. The method according to claim 2, characterized in that, Starting from the second node, and recursively searching upwards based on the similarity between the question vector and each node until the first node is obtained, includes: For any node in the second retrieval path, in the child vector space corresponding to the parent node of the node, determine the third node with the highest similarity to the question vector; the second retrieval path is the path from the second node to the root node; Using the third node as the reference point corresponding to the parent node, the search is recursively performed upwards until the root node is reached. The third node in the sub-vector space corresponding to the root node is determined as the first node.
5. The method according to claim 4, characterized in that, For any node in the second retrieval path, in the child vector space corresponding to the parent node of the node, determine the third node with the highest similarity to the question vector, including: Using the node as a reference point, determine whether the parent node of the node is a node with a higher similarity to the question vector; When the node has a higher similarity to the question vector, the node is determined to be the third node; When the parent node of the node has a higher similarity to the question vector, determine whether there exists a fourth node with a higher similarity to the question vector in the other child vector space of the parent node; if the fourth node exists, determine the fourth node as the third node; if the fourth node does not exist, determine the parent node as the third node.
6. The method according to claim 1, characterized in that, Determining the first number based on the similarity of the first node and a similarity threshold includes: Based on the similarity between the first node and the question vector, select the third number of nodes with higher similarity ranking in the first sequence; For each node of the third number, determine the similarity between each node and the question vector, and compare it with the similarity threshold respectively; Among the third number of nodes, the number of nodes that satisfy the similarity threshold is determined as the first number.
7. The method according to claim 1, characterized in that, Determining the second number based on the word count restriction information corresponding to the first number of nodes in the first sequence includes: Select the first number of nodes with the highest similarity ranking from the first sequence; Obtain the character count limit information corresponding to each of the first number of nodes; the character count limit information includes at least one of the following: the number of characters in the node, the number of characters in the question vector, and the number of characters in the response text; The second number is determined based on the character count limit information corresponding to each node.
8. The method according to claim 1, characterized in that, The method further includes: constructing a tree index structure; The construction of the tree index structure includes: For any vector space, the text vector with the largest feature variance value in the vector space is determined as the root node of the vector space; Based on the feature value relationship between each text vector, each text vector is divided into the first sub-vector space and the second sub-vector space corresponding to the root node; Repeat the partitioning until each sub-vector space contains only one text vector.
9. The method according to claim 8, characterized in that, The step of dividing each text vector into a first sub-vector space and a second sub-vector space corresponding to the root node based on the feature value relationship between the features of each text vector includes: Determine the segmentation point; the segmentation point is the node corresponding to the median of the feature values of each text vector. When the feature value of any of the text vectors is greater than or equal to the second feature value of the segmentation point, the text vector corresponding to the feature value of the text vector is divided into the first sub-vector space; When the feature value of any of the text vectors is less than the second feature value of the segmentation point, the text vector corresponding to the feature value of the text vector is divided into the second sub-vector space.
10. The method according to claim 1, characterized in that, The process of obtaining the problem vector includes: The problem is then processed by word segmentation. The segmented questions are input into a vector model to obtain the question vector; the vector model is used to transform the questions into embedding vectors.
11. A text processing device, characterized in that, The device includes: The acquisition unit is used to acquire the question vector; The first determining unit is used to perform similarity retrieval on the question vector using a tree index structure to determine a first sequence; the tree index structure consists of at least two nodes, and any one of the nodes corresponds to a text vector; the first sequence includes at least one node; The second determining unit is used to determine a first number based on the similarity of the first node and a similarity threshold; the first node is the node in the first sequence with the highest similarity to the question vector; the first number is used to adjust the number of nodes in the first sequence. The third determining unit is used to determine the second number based on the word count restriction information corresponding to the first number of nodes in the first sequence; A construction unit is used to select the second number of nodes in the first sequence and construct a target vector; the target vector is used to generate the response text of the question vector.
12. An electronic device, characterized in that, include: Memory, used to store computer-readable instructions; as well as A processor for executing the computer-readable instructions, causing the electronic device to perform the method as described in any one of claims 1-10.
13. A non-transitory computer-readable storage medium for storing computer-readable instructions, characterized in that, When the computer-readable instructions are executed by a processor, the processor performs the method as described in any one of claims 1-10.
14. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method as described in any one of claims 1-10.