A Question-Answering Method for Engineering Courses Based on LangChain and ChatGLM2

The question-answering system built using LangChain and ChatGLM2 leverages text vector representation and semantic understanding to address the flexibility and interactivity issues of traditional question-answering systems. It enables personalized course-assisted question-answering, thereby improving learning outcomes and user experience.

CN118467685BActive Publication Date: 2026-11-17SHENYANG INSTITUTE OF CHEMICAL TECHNOLOGY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410362709.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-28
Publication Date
2026-11-17
Estimated Expiration
2044-03-28

AI Technical Summary

Technical Problem

Traditional course-assisted question-and-answer systems cannot flexibly handle diverse and complex questions, have limited knowledge base and data support, poor interaction and user experience, and cannot provide personalized and accurate answers.

Method used

A question-answering system based on a knowledge base and a large language model is constructed using LangChain and ChatGLM2. Through text vector representation and semantic understanding, similarity matching is performed using the FAISS retrieval database to generate personalized prompts and use a fine-tuned ChatGLM2 model for reasoning and answering questions.

Benefits of technology

It provides personalized and precise course support Q&A services to improve learning outcomes and user experience, adapt to the characteristics of different subjects, and enhance learning efficiency and self-learning ability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118467685B_ABST
    Figure CN118467685B_ABST
Patent Text Reader

Abstract

This invention discloses an auxiliary question-answering method for engineering courses based on LangChain and ChatGLM2, relating to an artificial intelligence education approach. This method collects engineering course textbooks and exercises, utilizes the engineering course auxiliary dataset, and fine-tunes the ChatGLM2 model using the LoRa method. It also uses an embedding model to vectorize user questions and user documents, constructs a text vector database, and regularly updates the engineering course auxiliary dataset using user-uploaded documents. By combining LangChain's text vector representation technology with the semantic understanding and reasoning capabilities of a large language model, this invention provides students with personalized and accurate course auxiliary question-answering services, helping them overcome difficulties in learning engineering courses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to an artificial intelligence education method, specifically an auxiliary question-and-answer method for engineering courses based on LangChain and ChatGLM2. Background Technology

[0002] Large language models have already demonstrated enormous potential in the field of education. Particularly in intelligent education and personalized learning, breakthroughs have been achieved in building intelligent auxiliary teaching systems using large language models. These systems can provide personalized learning resources and guidance based on students' needs and ability levels, significantly improving learning outcomes and student engagement. However, in engineering courses, students often face the challenge of bridging theoretical learning with practical application. When dealing with complex problems in the course, students may encounter difficulties, requiring considerable time and effort to understand and solve them.

[0003] Traditional course-assisted question-and-answer systems use predefined rules and logic to answer questions, which has the following drawbacks: First, limited by static rules and templates, the system can only provide predefined answers and cannot flexibly adapt to diverse and complex questions. For non-standardized questions or questions involving real-world scenarios, this rigid answering method cannot meet the needs of users. Second, the knowledge base and data support of traditional systems are usually limited, often only able to answer questions related to a few courses. Finally, traditional systems have problems with interaction and user experience. Users usually need to ask questions through specific input formats or keywords, and the system's answers lack flexibility. Summary of the Invention

[0004] This invention provides a course-assisted question-answering method based on LangChain and ChatGLM2. This method employs a question-answering system paradigm based on prompt word engineering, combining a knowledge base and a large language model. Addressing various difficulties students encounter in course learning, it aims to provide personalized and accurate course-assisted question-answering services by combining LangChain's text vector representation technology with the semantic understanding and reasoning capabilities of the large language model, helping students overcome difficulties in course engineering-related learning.

[0005] The technical solution of the present invention is as follows: A course-assisted question-and-answer method based on LangChain and ChatGLM2 includes the following steps: Step 1: Collect textbooks, exercises, and question-and-answer databases for engineering courses, and use these to construct an auxiliary dataset for engineering courses; Step 2: Using the auxiliary dataset from engineering courses, fine-tune the ChatGLM2 model using the LoRa method; Step 3: Preprocess the user document, including document loading and document splitting; Step 4: Vectorize user queries and user documents using the Embedding model; Step 5: Build a text vector database; Step 6: Use the FAISS search library to perform similarity matching between the user's question and the text vector knowledge base, and return k similar text segments to generate the final prompt words; Step 7: Input the prompt words into the fine-tuned ChatGLM2 model for inference and stream the answer. Then, the auxiliary dataset for engineering courses can be updated regularly using user-uploaded documents.

[0006] Furthermore, step 1 of the course-assisted question-answering method based on LangChain and ChatGLM2 specifically includes: We used web crawlers, scripts, and other technologies to collect the exercises from engineering course textbooks and created the corpus needed for fine-tuning the ChatGLM2 model, thus constructing an auxiliary dataset for engineering courses.

[0007] Users can upload documents to the data storage module to supplement course content not yet covered by the auxiliary dataset for engineering courses; The data storage module uses database technology to store important data in the system, such as user questions and ChatGLM2 model answers, as well as user personal information, user-uploaded documents, and ChatGLM2 model configuration information.

[0008] Furthermore, step 4 of the course-assisted question-answering method based on LangChain and ChatGLM2 specifically includes: Through steps such as word segmentation, word mapping, vector combination, and normalization, the text block is transformed into a dense vector representation, where each dimension represents a certain semantic or feature of the text block.

[0009] Furthermore, steps 5 and 6 of the described course-assisted question-answering method based on LangChain and ChatGLM2 specifically include: Generate prompt words using the following steps: (1) Construct the set of vectors to be matched into a FAISS index structure; (2) Convert the vector to be queried (the vector representation of the user's query or query) into the same vector representation as the vector in the index; (3) Use the transformed query vector to perform a similarity search in the FAISS index; (4) Based on the results of the similarity search, return similar vectors or text blocks as the results of relevance matching; (5) Generate prompt words by taking the k most relevant texts with the highest relevance, along with the context of the relevant texts and the user's question.

[0010] A system architecture for a course-assisted question-and-answer method based on LangChain and ChatGLM2 is presented, consisting of a client and a server. The client sends user-uploaded documents and user questions to the server. The server integrates user documents and user questions through the LangChain framework to generate prompt words, which are then input into a finely tuned ChatGLM2 model. The answer text generated by the ChatGLM2 model is returned to the client and displayed to the user.

[0011] The advantages of this invention are: 1. This invention combines LangChain and large language model technology, and adopts a question-answering system paradigm based on prompt word engineering using a knowledge base and a large language model. By accurately understanding the questions raised by students and providing personalized and accurate answers and explanations, it helps students overcome learning difficulties and improve learning outcomes.

[0012] 2. This invention can be customized and expanded according to different course areas and disciplines. By connecting LangChain to external knowledge bases and leveraging the semantic understanding and reasoning capabilities of large language models, it can adapt to the characteristics and semantic rules of different disciplines, providing more professional and domain-specific question-answering services. Attached Figure Description

[0013] Figure 1 This is a flowchart illustrating the present invention; Figure 2 This is a system framework diagram of the present invention. Detailed Implementation

[0014] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.

[0015] Combined with appendix Figure 1 This embodiment proposes an auxiliary question-and-answer method for the "Signals and Systems" course based on LangChain and ChatGLM2, including the following steps: Step 1: Collect textbooks, exercises, and question-and-answer databases for engineering courses, including "Signals and Systems," and use these to construct an auxiliary dataset for engineering courses; By using Python web crawlers to collect textbook exercises for engineering courses, filtering them, and then using Python scripts to create the corpus needed for fine-tuning the ChatGLM2 model, a supplementary dataset for engineering courses was constructed. The use of web crawlers, scripts, and other tools greatly shortened the dataset creation cycle and covered a wide range of courses, resulting in a high-quality and diverse dataset.

[0016] Users can upload documents to the data storage module to supplement course content not yet covered by the auxiliary dataset for engineering courses. Uploaded documents support multiple file formats such as txt, docx, md, and pdf. The data storage module uses database technology to store user questions and ChatGLM2 model answers, including the question text, question time, and related information, so that they can be retrieved and displayed to users when needed. In addition, user personal information, user-uploaded documents, and ChatGLM2 model configuration information are also stored in the database to ensure the effective operation of the ChatGLM2 model in the system, as well as the personalized services and user experience provided by the system.

[0017] Step 2: Using engineering course auxiliary datasets, fine-tune ChatGLM2 using LoRa's method; LoRa is a low-resource fine-tuning method for large models. The basic principle of LoRa is to freeze the pre-trained model parameters, then add a trainable side-path matrix (low-rank separable matrix) to each layer of the Transformer. The side-path output is then added to the initial path output and input into the network, and only these newly added side-path matrix parameters are trained. The low-rank separable matrix consists of two matrices: the first is used for dimensionality reduction, and the second for dimensionality increase. The intermediate layer has a dimension of r, thus simulating the intrinsic rank. These two low-rank matrices significantly reduce the number of parameters. Through LoRa fine-tuning, large language models can be further learned and optimized based on domain-specific corpora to improve their performance in engineering-related fields.

[0018] Step 3: Preprocess the user document, including document loading and document splitting; The document is loaded using LangChain's loading tools, which include loader, UnstructuredFileLoader, TextLoader, UnstructuredMarkdownLoader, and PyPDFLoader. Then, LangChain's TextSplitter method is used to split the text according to characters, length, or semantics, dividing long texts into smaller units so that the system can better process and understand them.

[0019] Step 4: Vectorize user queries and user documents using the Embedding model; Through steps such as word segmentation, word mapping, vector combination, and normalization, the text block is transformed into a dense vector representation, where each dimension represents a certain semantic or feature of the text block. This vector representation can perform similarity calculation, relevance matching, and other operations in subsequent calculations, thereby achieving semantic understanding and semantic association analysis of the text block.

[0020] Step 5: Build a text vector database; The vector database chosen is Facebook's FAISS vector database. FAISS can quickly process large-scale datasets. By encapsulating the vector database into an index database, search efficiency is improved. Algorithms on GPUs are used to accelerate the retrieval of similar vectors, which helps to speed up the query process.

[0021] Step 6: Use the FAISS search library to perform similarity matching between the user's question and the text vector knowledge base, and return k similar text segments to generate the final prompt words; Using FAISS for relevance matching involves first constructing a FAISS index structure from the set of vectors to be matched; then, converting the query vector (the vector representation of the user's question or query) into the same vector representation as the vectors in the index; next, performing a similarity search on the FAISS index using the converted query vector; finally, returning similar vectors or text blocks as the relevance matching results based on the similarity search results. FAISS relevance matching helps the system perform similarity searches in the knowledge base to find the k most relevant pieces of information, along with the context of related text segments. This helps the system generate more comprehensive prompts, enabling the ChatGLM2 model to fully understand the user's question and related information in the knowledge base, thus contributing to providing accurate, comprehensive, and personalized answers and improving the effectiveness and user experience of the question-answering system.

[0022] Step 7: Generate prompt words by taking the k most relevant passages, their context, and the user's question. Input the prompt words into the fine-tuned ChatGLM2 model for inference and stream the answer. Then, the auxiliary dataset for engineering courses can be updated regularly using user-uploaded documents.

[0023] Appendix Figure 2 An example of a course-assisted question-and-answer system according to an embodiment of the present invention is shown in the appendix. Figure 2 As shown, the system architecture consists of a client and a server. The client sends the user-uploaded documents and user questions to the server. The server uses the LangChain framework to integrate the user documents and user questions to generate prompt words, which are then input into the finely tuned ChatGLM2 model. The answer text generated by the ChatGLM2 model is returned to the client and displayed to the user.

[0024] In summary, the course-assisted question-answering method and system based on LangChain and ChatGLM2 of this invention utilizes the reasoning capabilities of the ChatGLM2 model and integrates a knowledge base through the LangChain framework, making it more suitable for course-assisted question-answering. It provides explanations of learning content, recommendations of learning resources, and guidance on learning techniques to address difficulties encountered by students in their course learning, helping them better understand and master knowledge. Whether in the classroom or during self-study, students can rely on the question-answering system to quickly resolve doubts, overcome learning difficulties, and cultivate self-learning abilities through interaction with the system.

[0025] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-described technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the scope of the present invention.

Claims

1. A course-assisted question-answering method based on LangChain and ChatGLM2, characterized in that, The method includes the following steps: Step 1: Collect textbooks, exercises, and Q&A databases for engineering courses, and use these to construct an auxiliary dataset for engineering courses; Step 2: Using the auxiliary dataset from engineering courses, fine-tune the ChatGLM2 model using the LoRa method; Step 3: Preprocess the user document, including document loading and document splitting; Step 4: Vectorize user queries and user documents using the Embedding model; Step 5: Build a text vector database; Step 6: Use the FAISS search library to perform similarity matching between the user's question and the text vector database, and return k similar text segments to generate the final prompt words; Step 7: Input the prompt words into the fine-tuned ChatGLM2 model for inference and stream the answer. Afterwards, the auxiliary dataset for engineering courses can be updated regularly using user-uploaded documents. Step 1, constructing the auxiliary dataset for engineering courses, involves using web crawling and scripting techniques to collect engineering course textbooks, exercises, and question-and-answer databases, and then creating the corpus needed for fine-tuning the ChatGLM2 model. Users upload documents to the data storage module to supplement course content not yet covered in the auxiliary dataset. The data storage module uses database technology to store user questions and ChatGLM2 model answers, as well as user personal information, uploaded documents, and data from the ChatGLM2 model configuration information system. Step 6 involves similarity matching using a text vector database, which generates prompt words through the following steps: (1) Construct the set of vectors to be matched into a FAISS index structure; (2) Convert the vector to be queried into a vector representation that is the same as the vector in the index; (3) Use the transformed query vector to perform a similarity search in the FAISS index; (4) Based on the results of the similarity search, return similar vectors or text blocks as the results of relevance matching; (5) Generate prompt words by taking the k most relevant texts with the highest relevance, along with the context of the relevant texts and the user's question.

2. The course-assisted question-and-answer method based on LangChain and ChatGLM2 according to claim 1, characterized in that, Step 4 uses the Embedding model to vectorize user questions and user documents. This involves word segmentation, word mapping, vector combination, and normalization to transform text blocks into a dense vector representation, where each dimension represents a certain semantic or feature of the text block.

3. The course-assisted question-and-answer method based on LangChain and ChatGLM2 according to claim 1, characterized in that, The course-assisted question-and-answer system architecture described herein consists of a client and a server. The client sends user-uploaded documents and user questions to the server. The server integrates the user documents and user questions through the LangChain framework to generate prompt words, which are then input into the finely tuned ChatGLM2 model. The answer text generated by the ChatGLM2 model is returned to the client and displayed to the user.

Citation Information

Patent Citations

  • College teaching management system

    CN104318383A

  • Service robot personalized dialogue system and method based on cloud platform

    CN110297887A