Classification tree matching retrieval method
By establishing a hash table of tree node items and traversing parent and ancestor nodes, the problem of inefficient matching search of traditional classification tree is solved, and a fast and accurate search effect is achieved in large-scale classification trees.
Patent Information
- Application Number
- CN202510303108.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-06-13
AI Technical Summary
In massive data scenarios, the traditional classification tree matching retrieval method is inefficient, especially when the classification tree is very large and has many levels, it is difficult to efficiently extract relevant categories from user's problems, resulting in high retrieval time complexity.
A matching search method for classification trees is adopted, including establishing a tree node item hash table, searching the classification node objects according to user problems, and traversing the parent node and ancestor nodes, calculating the score, and finally selecting the highest-rated category.
It realizes the fast and accurate matching and retrieval of the best classification that best matches user query or data characteristics in a large-scale classification tree, reducing the time complexity of the search.
Smart Images

Figure CN120144838A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an efficient classification tree matching and retrieval method, belonging to the field of information technology. Background Art
[0002] In the current era of AIGC, a large number of application systems have begun to be combined with AI to improve enterprise efficiency. The RAG (Retrieval-Augmented Generation) technology, which enables AI to retrieve data from massive amounts of data, has also seen booming development. The RAG technology enhances the large language model (LLM) by integrating an external knowledge base and improves the performance of the LLM by combining an information retrieval mechanism and in-context learning (ICL). Currently, the RAG technology is usually used for retrieving unstructured text information, and for retrieving massive amounts of accurately classified information, it relies on the implementation of its own retrieval engine.
[0003] Suppose there is a classification tree as Figure 1 shown. This classification tree has a top-level classification of "Food", with a total of four classification levels. Its leaf classifications (such as: Banana X1) are the most detailed classifications (note that the actual node name of "Banana X1" here is "Banana", and X1 only represents a model of banana and is shown above for convenient reading). The most detailed classifications correspond to a set of instance collections, and the specific instances are not shown. For example, it could be a banana numbered "Banana X1-00001". What users usually want to query is generally a single instance or a batch of instances, and the user's question usually contains one or more classifications, thereby restricting the scope of the instances. The classification tree is to enable users to more conveniently find this instance. In actual applications, because the scenarios involved are massive data scenarios, the classifications are very numerous, and the classification levels can also be infinitely subdivided. Therefore, the classifications can be endless and vary according to business requirements.
[0004] When this classification tree is very large, has a very large number of levels, and there may be duplicate classification names at different levels. As shown in the above example, in the classification path of "Food - Fruit - Local - Green - Strawberry X2", there is a classification of "Strawberry", and in the classification path of "Food - Fruit - Local - Genetically Modified - Strawberry Y2", there is also a classification of "Strawberry", only the models of the classifications are different: one is the X2 type of strawberry, and the other is the Y2 type of strawberry. At this time, it is impossible to show the entire classification tree to the target user and let the user select classifications on the tree. Instead, by allowing the user to ask questions in natural language form, then decomposing the questions into classifications of corresponding entities, and then matching and retrieving in the entire classification tree to find a classification that best suits the user's needs, and then further processing other conditions of the user in subsequent questions.
[0005] In traditional retrieval schemes, such asFigure 2 As shown, when the user's question involves "local" and "strawberry", it is necessary to start traversing from the root of the classification tree ("food"):
[0006] Step 1: Using the "depth-first" or "breadth-first" algorithm, exhaustively traverse each finest level of the tree and retain the hierarchical structure. When the traversal path reaches "Food - Fruit - Local - Green - Strawberry X2", according to the principle of matching any one of the classifications, add it to the list of matched items. When the traversal reaches "Food - Fruit - Local - Genetically Modified - Strawberry Y2", also add it to the list of matched items until all sub-classifications are traversed and then end.
[0007] Step 2: After traversing and matching according to the method in Step 1, the final list of matched items will also include items such as "Food - Fruit - Local - Green - Banana X1" (because it matches the "local" classification in the user's question). Therefore, it is necessary to score each matched item. The scoring rule can be to score according to the number of types matched. Each time a classification is matched, 1 point is obtained. The final result is:
[0008] Classification matching path Score "Food - Fruit - Local - Green - Strawberry X2" 2 "Food - Fruit - Local - Genetically Modified - Strawberry Y2" 2 "Food - Fruit - Local" 1
[0009] Step 3: Extract the classification matching path with the highest score ranking. In the above case, finally, it can obtain two correct results of classification matching (with the scores tied at 2), but the time complexity it consumes is O(V), where V is the number of tree nodes.
[0010] If the classification information involved in the user's question is relatively discrete or has no specific order: such as not being limited from the large category, medium category, and small category (for example: "government and enterprise", "northwest region"), or directly requiring the finest classification (such as "self-employed household" without specifying the entity in what region or country), or the question only involves one top-level classification and one middle-level classification (such as: "global enterprises", "strategic emerging industries"), then how to efficiently retrieve the most matching classification from this huge classification tree becomes a problem that needs to be solved. As for how to extract the classifications involved from the user's question, this is another topic and is not within the scope of the present invention's technology, so it will not be elaborated further. Summary of the Invention
[0011] The object of the present invention is: in the case of a particularly large amount of data and particularly strict requirements for data classification, for the accurately classified information, quickly match and retrieve, and perform a more detailed condition retrieval within the pre-determined retrieval range of detailed data to optimize the retrieval efficiency of massive data.
[0012] In order to achieve the above object, the technical solution of the present invention is to disclose a classification tree matching retrieval method, which is characterized by comprising the following steps:
[0013] Step 1, establish a tree node item hash table of the classification tree;
[0014] Step 2: According to the classification involved in the user's question, retrieve all specific classification node objects from the tree node item hash table, arrange them from deep to shallow according to the node matching depth, and put them into the candidate list;
[0015] Step 3: From the matching items in the candidate list, starting from the node matching depth, traverse the parent node and all ancestor nodes of the current node from deep to shallow: if the parent node and all ancestor nodes contain the node with a shallower depth matched in step 2, then remove the node with a shallower depth, increase the score by 1, and execute step 3 again; if not, keep the original node with a shallower depth, add it to the next candidate list, and calculate the score at the same time;
[0016] Step 4: Sort by rating and select the category with the highest rating.
[0017] Preferably, the step 1 specifically includes the following steps: traversing each tree node of the classification tree, and then creating a hash table from each node name to a specific node object.
[0018] Preferably, when traversing each tree node of the classification tree, depth-first traversal is performed.
[0019] Preferably, when traversing each tree node of the classification tree, breadth-first is adopted.
[0020] Preferably, in step 4, if the scores of two categories are equally high, the two categories are returned simultaneously.
[0021] The present invention can quickly and accurately match and retrieve the best classification that best matches the user query or data features from a classification tree data structure containing a large number of classifications and complex hierarchical structures. The complexity of the algorithm disclosed by the present invention is: hash search + parent node traversal of the retrieved node, which is much less complex than the traditional method and can return the best matching chain according to the highest matching score result. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A classification tree is illustrated;
[0023] Figure 2 This is a flow chart of the traditional search solution;
[0024] Figure 3 It is a flow chart of the solution of the present invention. DETAILED DESCRIPTION
[0025] The present invention will be further described below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms fall within the scope limited by the appended claims of the application equally.
[0026] like Figure 3 As shown, a more refined and scientific classification matching retrieval method in a fast tree classification disclosed in an embodiment of the present invention includes the following steps:
[0027] Step 1: This step is the preparatory work before retrieval, which is to establish a hash table of tree node items.
[0028] Traverse each tree node (either depth-first or breadth-first), and then create a hash table from each node name to a specific node object. Figure 1 The classification tree shown: "Fruit"=>"Fruit Node Object", "Strawberry"=>"Strawberry X2 Node Object".
[0029] Step 2: According to the category involved in the user's question, retrieve the specific category node object from the hash table. Figure 1 In the classification tree shown, if the user question involves two categories, "local" and "strawberry", the retrieved classification objects should be:
[0030] The search result of "local" is the actual node of the "local" level, and its node depth is retained, which is 3 here (the depth is 3 from food-fruit-local).
[0031] The search results for “strawberry” are two actual nodes, “strawberry X2” and “strawberry Y2”, and their node depths are retained, which are: both nodes are 5.
[0032] Step 3: Traverse the parent node and all ancestor nodes in the order of node matching depth from deep to shallow. If the parent node and all ancestor nodes contain the node with a shallower depth matched in the second step, remove the node with a shallower depth. If not, retain the original node with a shallower depth as the subsequent traversal object.
[0033] For Figure 1 In the classification tree shown, the order of traversing the parent nodes is: "Strawberry X2" - "Green" - "Local" - "Fruit" - "Food". After traversing to the "Local" parent node, it is found that it is exactly the same as the "Local" node matched in step 2, and the depth of this node is shallower, so the "Local" node is removed from the matching list and the score is increased by 1.
[0034] If the node "Local" is not traversed during the above traversal process, the node "Local" will be used as the subsequent traversal object, and the parent nodes will be traversed and scored in the order of "Local" - "Fruit" - "Food".
[0035] Step 4: Sort according to the scores and select the classification with the highest score. If the scores of two classifications are the same, both classifications will be returned simultaneously. The final scoring results are as follows (exactly the same as the traditional traversal method).
[0036] Classification matching path Score "Food - Fruit - Local - Green - Strawberry X2" 2 "Food - Fruit - Local - Genetically Modified - Strawberry Y2" 2
Claims
1. A classification tree matching retrieval method, characterized in that: The following steps are involved: Step 1, establish a tree node item hash table of the classification tree; Step 2: According to the classification involved in the user's question, retrieve all specific classification node objects from the tree node item hash table, arrange them from deep to shallow according to the node matching depth, and put them into the candidate list; Step 3: From the matching items in the candidate list, starting from the node matching depth, traverse the parent node and all ancestor nodes of the current node from deep to shallow: if the parent node and all ancestor nodes contain the node with a shallower depth matched in step 2, then remove the node with a shallower depth, increase the score by 1, and re-execute step 3; if not, retain the original node with a shallower depth, add it to the next candidate list, and calculate the score at the same time; Step 4: Sort by rating and select the category with the highest rating.
2. A classification tree matching retrieval method as claimed in claim 1, characterized in that: The step 1 specifically includes the following steps: traversing each tree node of the classification tree, and then creating a hash table from each node name to a specific node object.
3. A classification tree matching retrieval method as claimed in claim 2, characterized in that: When traversing each tree node of the classification tree, the depth is first.
4. A classification tree matching retrieval method as claimed in claim 2, characterized in that: When traversing each tree node of the classification tree, breadth first is used.
5. A classification tree matching retrieval method as claimed in claim 1, characterized in that: In step 4, if the scores of two categories are equally high, both categories are returned.