API (Application Program Interface) text retrieval method and device and electronic equipment

By using preset models in the API interface document for searching, combining word vectors and position vectors to calculate the similarity, the problem of low retrieval efficiency and accuracy when the number of API interfaces is large, and efficient and accurate API interface retrieval is achieved.

CN119311832APending Publication Date: 2025-01-14CHINA TELECOM CORP LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411434468.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

The prior art cannot effectively solve the problem of low retrieval efficiency and search accuracy when the number of API interfaces is large, especially in enterprise-level information systems, traditional interface classification management and document description systems are difficult to meet advanced retrieval needs.

Method used

The preset model is used to retrieve target interface information in the API interface document. The trained model uses the API interface document as a data set, combining word vectors, segment vectors and position vectors to calculate the similarity between the query text and the interface document, and achieve accurate and efficient API interface search.

Benefits of technology

It improves the efficiency and accuracy of API interface retrieval, can quickly locate specific interfaces in large-scale API collections, and improves user experience and operation and maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119311832A_ABST
    Figure CN119311832A_ABST
Patent Text Reader

Abstract

The invention discloses an API (Application Program Interface) text retrieval method and device and electronic equipment. The method comprises the following steps: receiving a query text which is input by a target object and is used for retrieving an API (Application Program Interface); a preset model is adopted to retrieve target interface information corresponding to the query text in an API interface document, the preset model is obtained by using the API interface document as a data set for training, and the API interface document comprises interface metadata and description information of characteristics of a platform where the API interface is located; and returning the target interface information to the target object. According to the method and the device, the technical problems of low retrieval efficiency and low retrieval accuracy of the retrieval of the APIs when the number of the APIs is large in the related technology are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular, to a method, device and electronic device for retrieving API text. Background Art

[0002] With the rapid development of information, the information services of enterprises are growing faster and faster, and the number of API interfaces of services is also growing rapidly. Since the content of API interfaces is relatively complex, ordinary information retrieval technology cannot meet the advanced retrieval requirements of API interfaces.

[0003] API interface retrieval is required for operations such as interface update and maintenance. However, when the number of API interfaces is large, the retrieval workload is large. Related technologies usually adopt simple interface classification management or use interface document description system and other technical solutions, but such solutions have few retrieval conditions, low retrieval efficiency and low retrieval accuracy.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiments of the present application provide a method, device and electronic device for retrieving API text, so as to at least solve the technical problem in the related art that when searching for API interfaces, there is low retrieval efficiency and low retrieval accuracy when the number of API interfaces is large.

[0006] According to one aspect of an embodiment of the present application, a method for retrieving an API text is provided, comprising: receiving a query text for retrieving an API interface input by a target object; using a preset model to retrieve target interface information corresponding to the query text in an API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of characteristics of the platform where the API interface is located; and returning the target interface information to the target object.

[0007] In some embodiments of the present application, the preset model is trained in the following manner: obtaining preset input information and obtaining a preset API text corresponding to the preset input information; inputting the preset input information and the preset API text as input text into the original model for training, and determining the loss function of the original model; stopping training when the loss value of the loss function is less than a preset threshold to obtain the preset model.

[0008] In some embodiments of the present application, obtaining a preset API text corresponding to preset input information includes: obtaining raw data from an API interface, and generating an API interface document through the raw data, wherein the raw data includes interface metadata and description information of characteristics of the platform where the API interface is located, and the API interface document is in a non-text format; performing data preprocessing on the API interface document to obtain an API text, wherein the API text is in a text format; obtaining the preset API text corresponding to the preset input information from the API text.

[0009] In some embodiments of the present application, after the preset input information and the preset API text are input as input text into the original model, the method also includes: performing word segmentation encoding on the input text to obtain a word vector, a segment vector and a position vector corresponding to each word in the input text, wherein the word vector is used to represent the vector corresponding to the word division of the input text, the segment vector is used to represent the paragraph where the word in the input text is located, and the position vector is used to represent the position information of the word in the input text; based on the word vector, the segment vector and the position vector, determine the feature vector corresponding to each word in the input text.

[0010] In some embodiments of the present application, a preset model is used to retrieve target interface information corresponding to a query text in an API interface document, including: inputting a query vector of the query text and a text vector of the API interface document of each API interface into the preset model; determining the similarity between the query vector and each text vector to obtain a matching score sequence; sorting the matching score sequence in a preset order to obtain a target matching score sequence; determining a document index list based on the target matching score sequence; and obtaining the corresponding target interface information based on the document index list.

[0011] In some embodiments of the present application, determining the similarity between a query vector and each text vector includes: obtaining the number of times a first interface is used, wherein the first interface is any one of all API interfaces; and determining the similarity between the query vector and each text vector based on the query vector, the text vector, and the number of times used.

[0012] In some embodiments of the present application, before using a preset model to retrieve target interface information corresponding to the query text in the API interface document, the method also includes: obtaining the API interface document and obtaining key information in the API interface document; and segmenting the API interface document according to the paragraphs where the key information is located.

[0013] According to another aspect of an embodiment of the present application, a device for retrieving an API text is also provided, including: a receiving module for receiving a query text input by a target object for searching an API interface; a retrieval module for retrieving target interface information corresponding to the query text in an API interface document using a preset model, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of the characteristics of the platform where the API interface is located; and a return module for returning the target interface information to the target object.

[0014] According to another aspect of the embodiment of the present application, there is also provided an electronic device, including: a memory and a processor, the memory being used to store program instructions; the processor being connected to the memory and being used to execute the retrieval method for implementing the above-mentioned API text.

[0015] According to another aspect of the embodiments of the present application, a non-volatile storage medium is provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the above-mentioned API text retrieval method by running the computer program.

[0016] According to another aspect of the embodiments of the present application, a computer program product is provided, including computer instructions, which implement the above-mentioned API text retrieval method when executed by a processor.

[0017] In an embodiment of the present application, a model is used to retrieve the target interface information corresponding to the query text for searching the API interface input by the target object. By training the model with the API interface document as a training data set, the purpose of improving the model retrieval capability is achieved, thereby achieving the technical effect of accurately and efficiently searching the API interface through natural language, and further solving the technical problem of low retrieval efficiency and low retrieval accuracy in the related technology for searching the API interface when the number of API interfaces is large. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 It is a hardware structure block diagram of a computer terminal of an API text retrieval method according to an embodiment of the present application;

[0020] Figure 2 is a flowchart of a method for retrieving an API text according to an embodiment of the present application;

[0021] Figure 3It is a schematic diagram of an API interface document of a method for retrieving an API text according to an embodiment of the present application;

[0022] Figure 4 A schematic diagram of the structure of an API text retrieval device according to an embodiment of the present application. DETAILED DESCRIPTION

[0023] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0025] The information collected in the embodiments of the present application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or reject automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered.

[0026] In order to better understand the embodiments of the present application, the technical terms involved in the embodiments of the present application are explained as follows:

[0027] Application Programming Interface (API): A method for defining how software components communicate with each other, allowing different software applications to exchange data and call functions. API interfaces usually include call rules, data formats, return results and other information, and are an important means of achieving interaction between software systems.

[0028] Bidirectional Encoder Representations from Transformers (BERT): A deep learning model based on the Transformer architecture for natural language processing tasks. The BERT model is characterized by bidirectional processing of input text, the ability to understand the context, and the generation of high-quality text embedding vectors. It is widely used in scenarios such as text classification, sentiment analysis, and question-answering systems.

[0029] Transformer architecture: A neural network architecture for natural language processing that abandons the sequential processing method of traditional recurrent neural networks (RNNs) and adopts a self-attention mechanism that can process input sequences in parallel, effectively capturing global dependencies in the input sequences and improving training speed and model effects.

[0030] Self-Attention Mechanism: In the Transformer architecture, the relationship between the vector of each position in the sequence and the vectors of all other positions is calculated to generate a representation vector for that position. This mechanism enables the model to focus on the key information associated with the current position in the input sequence, improving the model's ability to process long sequence data.

[0031] In the enterprise information system architecture, APIs are the key to inter-service communication, and their number has increased significantly with the increase in business complexity. When searching these API interfaces to implement update, maintenance or integration operations, the limitations of traditional methods become particularly prominent. Specifically, the relevant API retrieval technologies mainly face the following challenges: First, the limitations of classification management. Simple interface classification management is usually organized according to the function or business field of the interface. Although it improves the convenience of retrieval to a certain extent, its classification standards are often too broad and cannot cover the detailed characteristics and complexity of the API, resulting in low efficiency in accurately locating specific interfaces in large-scale API collections; second, inefficient retrieval of document description systems. API document description systems are another common retrieval method that assists retrieval by recording the metadata of the interface (such as name, URL, input parameters, output parameters, etc.). However, this document system often lacks advanced retrieval functions and has few retrieval conditions, making it difficult for users to quickly and accurately find the required interface when facing ambiguous requirements or complex queries. Therefore, with the sharp increase in the number of APIs, traditional retrieval methods will encounter performance bottlenecks when processing large-scale data, and the retrieval response time will be extended, affecting user experience and operation and maintenance efficiency. In order to solve the above technical problems, the embodiments of the present application provide corresponding solutions, which are described in detail below.

[0032] The API text retrieval method embodiment provided in the embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal for implementing an API text retrieval method. Figure 1 As shown, the computer terminal 10 may include one or more (102a, 102b, ..., 102n are used to illustrate) processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions connected via a wired and / or wireless network. In addition, it may also include: a display, a keyboard, a cursor control device, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, and a BUS bus. Those skilled in the art can understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0033] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10. As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0034] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the API text retrieval method in the embodiment of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the above-mentioned API text retrieval method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0035] The transmission module 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission module 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission module 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0036] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 .

[0037] It should be noted that, in some optional embodiments, the above Figure 1 The computer terminal shown may include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of hardware elements and software elements. It should be noted that Figure 1 This is merely one example of a particular embodiment and is intended to illustrate the types of components that may be present in the computer terminal described above.

[0038] In the above-mentioned operating environment, an embodiment of the present application provides an embodiment of a method for retrieving an API text. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0039] Figure 2 is a flowchart of a method for retrieving an API text according to an embodiment of the present application, such as Figure 2 As shown, the method comprises the following steps:

[0040] Step S202: receiving a query text input by a target object for searching an API interface.

[0041] In the above step S202, the target object refers to a user or automated system using the API interface retrieval solution, including any entity that needs to query API interface information through natural language, for example, it can be a monitoring alarm system that automatically queries API information based on preset rules. The query text refers to the natural language description input by the target object into the system for retrieving the API interface, which may include the properties or functional description of the API interface that the target object wishes to obtain, for example, the interface name, functional description, input parameter type or name, output result, etc. In some embodiments, the query text may be expressed as a query in the following form:

[0042] (1) Function description query: for example, “retrieve all APIs related to user authorization”.

[0043] (2) Parameter query: For example, "find APIs that accept a list of identity IDs as input parameters."

[0044] (3) Frequency of use query: For example, “get the top five API interfaces that were called last week”.

[0045] (4) Interface name query: for example, "search for a general authentication interface that provides user information".

[0046] (5) Complex combination query: For example, "query all APIs that require mobile phone number and ID number for user information authentication and whose response type is JSON."

[0047] Step S204, using a preset model to retrieve target interface information corresponding to the query text in the API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of the characteristics of the platform where the API interface is located.

[0048] In the above step S204, the preset model can output the interface information most relevant to the query text according to the input query text, for example, the BERT model, the RoBERTa (Robustly Optimized BERT Pretraining Approach) model, etc.

[0049] The API interface document refers to a document that records the specification information of the API interface in detail. It can include metadata of the interface, that is, data that describes the basic information of the API interface, such as the interface name, address, input parameters, output parameters, reference relationships, etc. In addition, it can also include description information of the characteristics of the platform where the API interface is located, that is, the characteristics and contextual information of the API interface on a specific platform, which is used to more accurately understand the functions and usage scenarios of the API interface. In some embodiments, it can be defined by the user when creating an interface, for example, "a general user information authentication interface queried by mobile phone number or ID number."

[0050] The target interface information refers to the detailed information of the API interface that matches the query intent and is output by the preset model after the query text is retrieved, which may include the interface name, address, parameters, etc. For example, when the user enters "identity id list" as the query condition, the preset model will retrieve all interface information related to "identity id list" from the existing API interface documents, and return the most matching interface as the target interface information to the user.

[0051] In some embodiments, the retrieval of the target interface information corresponding to the query text can be achieved through the following process: using a preset model (such as BERT) to convert the query text into a semantic vector, comparing the semantic vector with the vector representation of the API interface document, for example, using cosine similarity to calculate the similarity between them, and using the comparison result (such as the interface document with the highest similarity) as the target interface information corresponding to the query text. In some embodiments, in order to improve the accuracy of the retrieval, other dimensions (such as the frequency of use of the interface, etc.) can also be combined for comprehensive sorting. For example, when querying the "user information list", the preset model can calculate the interface document that is most similar to the phrase, and sort it based on the number of times the interface is used.

[0052] Step S206: Return the target interface information to the target object.

[0053] In the above step S206, in some embodiments, the interface information can be returned in the following manner:

[0054] (1) Data encapsulation: encapsulate the target interface information into a response body format, for example, convert the data into JSON, XML or other predefined formats. In an optional embodiment, metadata such as response time and status code may also be added to form a complete interactive feedback;

[0055] (2) Response sending: Use HTTP or other predefined communication protocols to send the encapsulated response to the target object.

[0056] Through the above steps, the model is used to retrieve the target interface information corresponding to the query text for searching the API interface input by the target object, and the model is trained by using the API interface document as the training data set, thereby achieving the purpose of improving the model retrieval capability, thereby achieving the technical effect of accurate and efficient retrieval of the API interface through natural language, and further solving the technical problems of low retrieval efficiency and low retrieval accuracy in the related technology for the retrieval of API interfaces when the number of API interfaces is large.

[0057] In order to ensure the accuracy and reliability of the model when retrieving API text, especially when dealing with complex queries and multi-platform API interfaces, to provide more accurate retrieval results, the preset model can be trained in the following way: obtain preset input information, and obtain the preset API text corresponding to the preset input information; input the preset input information and the preset API text as input text into the original model for training, and determine the loss function of the original model; stop training when the loss value of the loss function is less than the preset threshold to obtain the preset model.

[0058] Preset input information refers to user query examples that are pre-set at the beginning of model training and used for model learning and matching, and may include multiple key areas of the API interface, such as interface name, function description, parameter type, etc., so that the model can fully understand the semantics of the API interface. In some embodiments, the preset input information may be a natural language description for querying the API interface, such as "interface for obtaining user information", "how to authenticate by mobile phone number", or "API for returning a user list".

[0059] The preset API text refers to the API interface description text that has been formatted and generated according to the preset protocol. It is used for the model to learn the matching relationship between input information and API text. It records the API metadata, description information of the platform characteristics of the API interface, etc. For example, the interface name, address, request method, request parameters, response parameters, etc.

[0060] In some embodiments, the preset API text can be obtained in the following manner: obtaining raw data from the API interface and generating an API interface document through the raw data, wherein the raw data includes interface metadata and description information of the platform characteristics of the API interface, and the API interface document is in a non-text format; performing data preprocessing on the API interface document to obtain API text, wherein the API text is in a text format; obtaining the preset API text corresponding to the preset input information from the API text.

[0061] (1) Generate API interface documents from raw data: extract API interface metadata and platform feature description information from the database to build API interface documents.

[0062] In an optional embodiment, the description method of the API interface can be standardized according to a predefined protocol structure. For example, the protocol can include but is not limited to the interface name, address, detailed information of request and response parameters, interface description and reference relationship, etc.; the existing API interface data is processed according to the protocol, for example, all relevant metadata including the interface name, address, parameter type, default value, whether it is required, and description information are obtained from the database, and platform-specific description information (such as the interface usage scenarios, frequency, permission level, etc.) is collected; the obtained raw data is converted into a non-text format (such as JSON) that meets the protocol requirements.

[0063] Figure 3 is a schematic diagram of an API interface document of an API text retrieval method according to an embodiment of the present application, such as Figure 3 As shown in the figure, according to the predefined protocol structure, the API document can include the interface name, interface address, input parameters, output parameters, interface description, and reference relationship:

[0064] 1) Interface name: This is the unique identifier of the API interface. Developers can name it according to the function and purpose of the interface, for example, "general authentication interface for obtaining user information" to facilitate subsequent identification and retrieval.

[0065] 2) Interface address: URL address, which is the specific network address for accessing the API. It can include the protocol (such as HTTP or HTTPS), server address and path. In addition, the request method can also be indicated, such as GET, POST, PUT, DELETE, etc.

[0066] 3) Input parameters: refers to input parameters or request parameters, which are the information that needs to be passed when calling the API. They define the parameters that need to be passed when calling the API, including: request header, which contains communication information between the client and the server, such as authentication information, request type, client type, etc.; request body, which is used to pass complex data structures, such as data in JSON and XML formats; request parameters, which can be URL parameters, that is, a series of parameters directly following the question mark in the URL address, or request parameters in JSON format, which are directly placed in the request body; URL parameters, that is, the part of the URL address that serves as a path parameter or query parameter, are used to specify specific operations or filtering conditions of the API.

[0067] 4) Output parameters: Output parameters are information returned to the client after the API call, including: response header, which contains the status code, content type and other information of the server response; response body, which contains the specific data of the API call result, usually in JSON or XML format.

[0068] In some embodiments, the parameters in the input and output parameters can be uniformly set to json format.

[0069] 5) Interface description: refers to a detailed description of the API functions, purposes, and usage scenarios, which is used to reflect the intent and limitations of the interface. For example, it describes what type of data processing the interface is used for, whether authentication is required, and possible response status.

[0070] 6) Reference relationship: used to describe the hierarchical dependencies between interfaces, including upper-level references (i.e. other services that depend on the API) and lower-level references (i.e. other interfaces or services that the API itself depends on), used to reflect the position and role of the API in the entire system architecture.

[0071] (2) Perform data preprocessing on the API interface document to obtain API text: that is, convert the non-text format API interface document into text format so that the model can understand and process it.

[0072] In order to facilitate understanding of the process, a specific embodiment is described below. Figure 3Based on the processing of the original data by the API interface document shown, the data of an API interface document is specifically manifested as follows:

[0073]

[0074]

[0075] In the above API interface document data, the interface name is "test interface", and its access address is "http: / / test.com / test", which uses HTTP request method; the input parameters of API include two parts: request header and request body. There is a required parameter in the request header, named "header1", of type string, used to identify request header parameter 1, and has no default value. The request body contains a required parameter, named "ids", of type array, with a default value of empty array, used to pass the identity id list, which indicates that a series of identity identification information needs to be provided when calling this interface; the response parameter, that is, the output of the API, is divided into a response header and a response body. The response header of this interface does not define any parameters, while the response body contains a parameter named "users", of type array, with a default value of empty array. This parameter is non-mandatory and described as a user information list, which means that after successfully calling the interface, if the response contains the "users" parameter, it will carry the list data of user information, which may include various attributes of the user, such as name, phone number, etc.; the interface description information is that it is a general authentication interface for obtaining user information, indicating that calling this interface usually requires permission verification and can return user information.

[0076] Convert the above JSON API interface document to text format:

[0077] Interface name: Test interface.

[0078] Interface address: http: / / test.com / test.

[0079] Description: This interface is mainly used to obtain the general authentication interface of user information.

[0080] The request header parameters are: 1. Name: header1; Type: string; Description: request header parameter 1; Required: Yes.

[0081] The request body parameters are: 1. Name: ids; Type: array; Description: identity id list; Required: Yes.

[0082] The response body parameters are: 1. Name: users; Type: array; Description: user information list; Required: Yes.

[0083] (3) Obtaining a preset API text corresponding to the preset input information from the API text. In some embodiments, the above process can be implemented by the following steps:

[0084] For the preprocessed API text, an inverted index is constructed to quickly query the document set containing specific keywords in the document. In an optional embodiment, the inverted index can be constructed based on the keywords in the API text (such as interface name, parameter name, description information, etc.); extract keywords from the preset information, use the keywords to search in the inverted index, and find the API text set containing the keywords. For example, if the user enters "get user information", the system will identify "get" and "user information" as keywords, and search for API text containing these keywords in the index to obtain the preset API text corresponding to the preset input information.

[0085] In some embodiments, the preset input information and the preset API text can be input as input text into the original model for training, and the loss function of the original model is determined. The original model includes a learning model that has not been optimized by any specific data set before training, for example, a BERT model that has not been trained with API documents. The loss function can be a function such as cosine similarity, cross-entropy loss (Cross-Entropy Loss) and mean squared error loss (Mean Squared Error Loss). In some embodiments, the training can be stopped when the loss value of the loss function is less than a preset threshold to obtain a preset model. The preset threshold is a pre-set indicator used to determine whether the model training has achieved a satisfactory effect. Once the loss value during the model training process is reduced to below the preset threshold, it can be considered that the model has learned enough information and can perform the API interface retrieval task better. The preset model is a model obtained through training for API interface retrieval. In some embodiments, the parameters of the original model can also be optimized using an adaptive moment estimation optimizer (Adaptive Moment Estimation, referred to as Adam optimizer), that is, the learning rate is adjusted according to the historical gradient information to adjust the parameters, improve the convergence speed of the original model, and obtain the final preset model.

[0086] In order to effectively improve the accuracy and speed of retrieval, after the preset input information and the preset API text are input as input text into the original model, the following steps can be performed: the input text is segmented and encoded to obtain the word vector, segment vector and position vector corresponding to each word in the input text, wherein the word vector is used to represent the vector corresponding to the word division of the input text, the segment vector is used to represent the paragraph where the word in the input text is located, and the position vector is used to represent the position information of the word in the input text; based on the word vector, segment vector and position vector, the feature vector corresponding to each word in the input text is determined.

[0087] In a specific embodiment, the original model used is the BERT model, and the query text input by the user is "API interface for obtaining user information":

[0088] (1) Token Embeddings: The BERT model uses a tokenizer to segment the input text. In this example, the segmentation results are: "get", "user", "information", "of", "API", "interface", and each word will be converted into a corresponding vector, which reflects the meaning of the word itself and its semantics in different contexts. For example, the word "user" may refer to "user", "customer" or "account" in different contexts. BERT will generate a vector for "user" that can distinguish these meanings based on the context in the training data.

[0089] (2) Segment Embeddings: Segment embeddings are used to distinguish the position of input text in two or more segments of text, which is very important when BERT processes two sequences of input (for example, query text and API document text). In this example, since the input query text is a single sequence, the segment embeddings of each word may be the same to mark this sequence.

[0090] (3) Positional Embeddings: Positional embeddings are used to encode the position information of words in the text. Since the order of words in the input sequence processed by the BERT model is crucial for understanding semantics, for example, "get" appears at the beginning of the query, while "interface" appears at the end. Positional embeddings will attach position-related features to these words to help the model understand their role in the sentence.

[0091] (4) Determination of feature vectors: Use the above three vectors to build a complete embedding layer. For example, the above three vectors can be added to obtain the final feature vector of each word. In this example, the feature vector of the word "user" will be the sum of its word vector, segment vector, and position vector. These feature vectors will be input into the BERT model for further semantic understanding and matching. The output of BERT takes the pooled output (pooled_output) as the semantic representation of the entire sentence.

[0092] By calculating the similarity between vectors, the API interface information that best matches the query text can be quickly located. Specifically: the query vector of the query text and the text vector of the API interface document of each API interface are input into the preset model; the similarity between the query vector and each text vector is determined to obtain a matching score sequence; the matching score sequence is sorted in a preset order to obtain a target matching score sequence; based on the target matching score sequence, a document index list is determined; and based on the document index list, the corresponding target interface information is obtained.

[0093] In some embodiments, the similarity between the query vector and each text vector can be calculated by cosine similarity to calculate the matching score, which is calculated as follows:

[0094]

[0095] Where similarity is the cosine similarity matching score, θ is the angle between vector A and vector B, A·B is the dot product of vector A and vector B, ||A|| and ||B|| are the moduli of vector A and vector B, and n is the number of text vectors.

[0096] In some embodiments, the matching scores calculated from all text vectors and the query vector can be arranged into a sequence according to the order of the text vectors to obtain a matching score sequence, and then the matching score sequence can be sorted in a preset order, for example, in descending order, and a matching document index list is returned in descending order according to the matching scores. The server obtains the corresponding API interface information based on the document index and returns it to the user.

[0097] When the user's query conditions are relatively simple, the use of cosine similarity will result in many identical scores, which has certain limitations. Therefore, a dimension of the number of times an interface is used can be added as a consideration to comprehensively calculate the matching score. Specifically: the number of times the first interface is used is obtained, where the first interface is any API interface among all API interfaces; based on the query vector, the text vector and the number of times used, the similarity between the query vector and each text vector is determined.

[0098] In some embodiments, the matching score may be calculated using the following formula:

[0099] similarity=cos(θ)×α×count (1)

[0100]

[0101] Where similarity is the matching score, cos(θ) is the cosine similarity, α is the adjustment coefficient, count is the number of times the interface is used, and k is the adjustment parameter.

[0102] The adjustment coefficient is used to limit the number of times used to prevent the similarity matching score from losing its meaning due to excessive use. The adjustment parameters need to be dynamically adjusted based on the system's usage data statistics, user search habits and other data. Through this adjustment coefficient, the accuracy of the retrieval results can be improved.

[0103] In order to help the model focus more on the key parts of the API document and locate key information more quickly during the retrieval process, before using the preset model to retrieve the target interface information corresponding to the query text in the API interface document, the following process can also be performed: obtain the API interface document and obtain the key information in the API interface document; divide the API interface document according to the paragraphs where the key information is located.

[0104] Since the user's query is a short query, and in general, the queried information is part of the content in the API document, and the API document is a long text, the API document can be further processed first, for example, the paragraphs of the API document are segmented. In some embodiments, the API document is segmented using the Natural Language Toolkit (NLTK) to segment the API document into paragraphs. For example, according to the key information type in the API document, the document content is divided into several parts, and the converted text content is segmented using NLTK to ensure that each key information part is processed separately, and each paragraph is extracted from the segmented text and stored as an independent text unit. An index is built for each paragraph so that the relevant API document paragraphs can be quickly retrieved through the key information.

[0105] Figure 4 is a structural diagram of an API text retrieval device according to an embodiment of the present application, such as Figure 4 As shown, the device comprises:

[0106] The receiving module 40 is used to receive a query text input by a target object for searching an API interface;

[0107] A retrieval module 42 is used to retrieve target interface information corresponding to the query text in the API interface document using a preset model, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of characteristics of the platform where the API interface is located;

[0108] The returning module 44 is used to return the target interface information to the target object.

[0109] The above-mentioned API text retrieval device also includes a training module 46, which is used to obtain preset input information and preset API text corresponding to the preset input information; input the preset input information and the preset API text as input text into the original model for training, and determine the loss function of the original model; stop training when the loss value of the loss function is less than a preset threshold to obtain a preset model.

[0110] In the above-mentioned API text retrieval device, the acquisition module is also used to obtain raw data from the API interface and generate an API interface document through the raw data, wherein the raw data includes interface metadata and description information of the platform characteristics of the API interface, and the API interface document is in a non-text format; perform data preprocessing on the API interface document to obtain API text, wherein the API text is in a text format; obtain a preset API text corresponding to the preset input information from the API text.

[0111] In the above-mentioned API text retrieval device, the training module is also used to perform word segmentation encoding on the input text to obtain the word vector, segment vector and position vector corresponding to each word in the input text, wherein the word vector is used to represent the vector corresponding to the word division of the input text, the segment vector is used to represent the paragraph where the word in the input text is located, and the position vector is used to represent the position information of the word in the input text; based on the word vector, segment vector and position vector, determine the feature vector corresponding to each word in the input text.

[0112] In the above-mentioned API text retrieval device, the training module is also used to input the query vector of the query text and the text vector of the API interface document of each API interface into a preset model; determine the similarity between the query vector and each text vector to obtain a matching score sequence; sort the matching score sequence according to a preset order to obtain a target matching score sequence; determine a document index list based on the target matching score sequence; and obtain corresponding target interface information based on the document index list.

[0113] In the above-mentioned API text retrieval device, the training module is also used to obtain the number of times the first interface is used, wherein the first interface is any one of all API interfaces; based on the query vector, the text vector and the number of times used, the similarity between the query vector and each text vector is determined.

[0114] In the above-mentioned API text retrieval device, the acquisition module is also used to acquire the API interface document and key information in the API interface document; and segment the API interface document according to the paragraphs where the key information is located.

[0115] It should be noted that Figure 4 The retrieval means of the API text shown is used to perform Figure 2 The API text retrieval method shown, therefore Figure 2 The explanations in the retrieval method of the API text in also apply to Figure 4 The retrieval device of the API text shown will not be described in detail here.

[0116] The embodiment of the present application further provides an electronic device, which includes a memory and a processor, wherein the memory is used to store program instructions; the processor is connected to the memory and is used to execute the program instructions to implement the following functions:

[0117] Receive query text for retrieving API interface input by the target object; use a preset model to retrieve target interface information corresponding to the query text in the API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of the characteristics of the platform where the API interface is located; return the target interface information to the target object.

[0118] The embodiment of the present application further provides a non-volatile storage medium, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the following API text retrieval method by running the computer program:

[0119] Receive query text for retrieving API interface input by the target object; use a preset model to retrieve target interface information corresponding to the query text in the API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of the characteristics of the platform where the API interface is located; return the target interface information to the target object.

[0120] An embodiment of the present application also provides a computer program product, including computer instructions, which, when executed by a processor, implement the steps of the API text retrieval method in each embodiment of the present application.

[0121] The embodiments of the present application also provide a computer program, which, when executed by a processor, implements the steps of the API text retrieval method in each embodiment of the present application.

[0122] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0123] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0124] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0125] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0126] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0127] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0128] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for retrieving API text, characterized in that: include: Receive query text input by the target object to search the API interface; Retrieving target interface information corresponding to the query text in the API interface document using a preset model, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of characteristics of the platform where the API interface is located; The target interface information is returned to the target object.

2. The method according to claim 1, characterized in that The preset model is trained in the following way: Obtaining preset input information, and obtaining preset API text corresponding to the preset input information; Inputting the preset input information and the preset API text as input text into the original model for training, and determining the loss function of the original model; When the loss value of the loss function is less than a preset threshold, the training is stopped to obtain the preset model.

3. The method according to claim 2, characterized in that Obtaining a preset API text corresponding to the preset input information includes: Acquire raw data from the API interface, and generate the API interface document through the raw data, wherein the raw data includes the interface metadata and description information of the characteristics of the platform where the API interface is located, and the API interface document is in a non-text format; Performing data preprocessing on the API interface document to obtain an API text, wherein the API text is in a text format; A preset API text corresponding to the preset input information is obtained from the API text.

4. The method according to claim 2, characterized in that: After inputting the preset input information and the preset API text as input text into the original model, the method further includes: Perform word segmentation encoding on the input text to obtain a word vector, a segment vector and a position vector corresponding to each word in the input text, wherein the word vector is used to represent the vector corresponding to the word segmentation of the input text, the segment vector is used to represent the paragraph where the word in the input text is located, and the position vector is used to represent the position information of the word in the input text; A feature vector corresponding to each word in the input text is determined based on the word vector, the segment vector and the position vector.

5. The method according to claim 2, characterized in that: Retrieving target interface information corresponding to the query text in the API interface document using a preset model, including: Inputting the query vector of the query text and the text vector of the API interface document of each API interface into the preset model; Determine the similarity between the query vector and each text vector to obtain a matching score sequence; After sorting the matching score sequence according to a preset order, a target matching score sequence is obtained; Determining a document index list according to the target matching score sequence; The corresponding target interface information is obtained according to the document index list.

6. The method according to claim 5, characterized in that Determining the similarity between the query vector and each text vector includes: Obtain the number of times a first interface is used, wherein the first interface is any one of all API interfaces; The similarity between the query vector and each text vector is determined according to the query vector, the text vector and the number of times used.

7. The method according to claim 1, characterized in that Before using the preset model to retrieve the target interface information corresponding to the query text in the API interface document, the method further includes: Obtain the API interface document and obtain key information in the API interface document; The API interface document is segmented according to the paragraphs where the key information is located.

8. A device for retrieving API text, characterized in that: include: A receiving module, used to receive a query text input by a target object for searching an API interface; A retrieval module, used to use a preset model to retrieve target interface information corresponding to the query text in the API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of characteristics of the platform where the API interface is located; The returning module is used to return the target interface information to the target object.

9. An electronic device, characterized in that: include: A memory for storing program instructions; A processor, connected to the memory, is used to execute program instructions to implement the following functions: receiving a query text input by a target object for retrieving an API interface; A preset model is used to retrieve target interface information corresponding to the query text in the API interface document, wherein the preset model is trained using the API interface document as a data set, and the API interface document includes interface metadata and description information of the characteristics of the platform where the API interface is located; and the target interface information is returned to the target object.

10. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the API text retrieval method described in any one of claims 1 to 7 by running the computer program.

11. A computer program product comprising computer instructions, characterized in that: When the computer instructions are executed by a processor, the API text retrieval method described in any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Method and device for calling API (Application Program Interface) in question answering system, computer equipment and medium

    CN120653747A