Method and system for the digital management of documents and the automation of searches for obtaining answers relating to a 'documentary database' in a given sector, characterized in that, through a language model integrated with the search and data indexing process, it is capable of providing plausibly correct and always certifiable answers to the searches

RAG with a built-in linguistic model addresses the issues of outdated knowledge and hallucinations in AI systems by using vector databases to ensure accurate and contextually relevant responses.

WO2026104958A1PCT designated stage Publication Date: 2026-05-21SHAKAZAMBA SRL
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
SHAKAZAMBA SRL
Filing Date
2025-11-07
Publication Date
2026-05-21

AI Technical Summary

Technical Problem

Existing artificial intelligence systems, particularly those using large language models (LLM), face issues with outdated knowledge and a tendency to hallucinate due to lack of access to current and specific data, leading to inaccurate responses.

Method used

Implementing Retrieval-Augmented Generation (RAG) with a built-in linguistic model to acquire, normalize, process, and store data in a vector database, ensuring responses are based on up-to-date and relevant information, avoiding hallucinations by using vector databases for rapid encoding and indexing.

Benefits of technology

Provides accurate, contextually relevant responses by leveraging current data sources, enhancing the reliability and precision of AI systems, reducing the risk of errors and misinterpretations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2025061380_21052026_PF_FP_ABST
    Figure IB2025061380_21052026_PF_FP_ABST
Patent Text Reader

Abstract

The claimed method enables the acquisition of data from external sources (such as websites) or internal sources (such as files, documents, or relational databases), their transformation into a uniform format, their subdivision into smaller portions, and subsequent processing. The processed data are then stored in a vector database to allow more efficient searching and are interpreted by a model capable of understanding a human user's request and providing an exhaustive response, even to complex and articulated queries. The method, implemented through the corresponding system, is free from possible hallucinations, as it relies solely on the acquired and processed data. It can be applied to user interfaces designed to submit a request and obtain a response, or it can be integrated within a corporate environment comprising different software systems from which information can be collected, processed, and automatically transmitted to other systems.
Need to check novelty before this filing date? Find Prior Art

Description

Description2.1.- DEFINITIONS PRODROMICHE

[0001] Artificial Intelligence (Al) means all systems that exhibit intelligent behavior in analyzing their environment and in taking actions, with a certain degree of autonomy, to achieve certain objectives.

[0002] 'Al' systems: Can be software-only and act in the virtual domain (voice assistants, image analysis software, search engines, voice and face recognition systems), or can be part of hardware devices (advanced robots, autonomous cars, drones, and the Internet of things).

[0003] Weak artificial intelligence (weak / specialist Al): It encloses systems within it able to simulate some cognitive functionalities of man without however reaching the typical intellectual skills of man; it is, in broad lines, of problem-solving programs able to replicate some logical human reasoning to solve problems, to make decisions, etc.

[0004] Strong artificial intelligence (strong / general Al): Systems capable of becoming wise (or even self-aware) are included in this category; there are theories that urge some scientists and experts to believe that one day machines will have their own, autonomous and probably superior intelligence to that of humans.

[0005] By generative artificial intelligence (Al) is meant a type of artificial intelligence (Al) that is able to produce fluid and relevant texts based on very wide linguistic models (otherwise defined, LLM, large language model). This Al collects and processes the results from a large amount of data and manages to give detailed answers to various questions that are asked by the software, also called PROMPTS.

[0006] By training is meant the rules and patterns on which the Al is trained. Al models and systems are trained on billions of text samples from theInternet (over 175 billion parameters per GPT-3) 30 trillion words from web pages, books, news articles, forums, scientific texts and many other sources of public information. An Al machine learning system is trained rather than explicitly programd.

[0007] Retrieval-Augmented Generation (RAG) means a system that allows to enrich and implement the production of an LLM with more targeted and2 / 44updated information, without having to modify the basic model. This information may be more relevant to organizations and sectors specific toLLM. In this way, the Al generative intelligence system can provide more appropriate responses to prompts, based on very current data. Using vector databases through RAG, the Al can indicate the specific source of the data it uses in its response, which LLM cannot do. This means that, if there is an error in the output of the generative data, the document containing the wrong information can be easily recognized and corrected, and the correct information can then be added to the vector database. In short, RAG offers to the generative promptness, context and precision based on evidence, overcoming the capabilities of the LLM itself. The RAG reproduces these 3 phases of the reasoning:1. understanding the question2. search for relevant information to respond3. Generation of the answer

[0008] The two macro-elements of RAG are:A) an information retrieval system through an embedded linguisticmodel (the text book with its index that can be consulted on the examination); b) a generic LLM model to understand the question and to formulate the answer (the student of the examination).

[0009] Parsing: It consists in analyzing a text from a grammatical point of view to recognize its constituent elements. This process involves dividing the text into smaller components, such as words, phrases, clauses or paragraphs, to better understand its syntactic structure. Through parsing, when we examine a sentence, we can distinguish parts such as the subject, the verb, and the object, facilitating the understanding of the meaning and function of each element within the text.

[0010] Chunking: Consists of dividing text into larger semantic segments than isolated words. These segments, known as chunks, can be phrases, sets of words, or clauses. The main intent of chunking is to improve the intelligibility of the text and make its analysis easier.2.2.- STATE OF THE ART3 / 44

[0011] in relation to the STATE-OF-the-ART generativa there are some criticalities since the responses depend only on the information that the Al has used to train, which is often a generic LLM. LLM data may be weeks, months, or years old and maynot contain information specific to an organization or industry, especially if it is an Al enterprise chatbot. This can lead to incorrect responses that undermine the trust of customers and employees in technology.

[0012] In relation to RAG, the current systems select among the responses obtained with vector system in use the most likely one with the risk of being given for good , flat-wrong results. The machine always tries to give an answer even when it does not know it or knows that it can be wrong.

[0013] In order to understand the potential of the claimed invention it is necessary to deepen the state of the art relating to computer systems of artificial intelligence as well as to the current systems and technologies in use.

[0014] The Al consists of a set of different applications and methods based on various models and algorithms. Among these, the large Language Model(LLM) are among the most popular and powerful, capable of generating natural and realistic texts from an input or demand. Examples of LLM are GPT-4, Bert and T5, which have demonstrated impressive performance in various language understanding and production tasks.

[0015] The RAG is now a known system. He drew the attention of Al Generative developers after the release of "retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks", a 2020 paper signed by Patrick Lewis and a Facebook group AT Research. RAG has received the consent of many academic and industrial scholars, who consider it a way to greatly increase the value of generative artificial intelligence systems.

[0016] RAG differs from the generalized LLM, which takes a lot of time and resources to be trained, because it can update with new data continuously and incrementally. This is done by the embeddings algorithm which transforms the data into vectors and saves it into a vector database, which can be consulted quickly by the Al system. In addition, the responses generated by the Al system can be used to enrich the RAG model, increasing its quality and accuracy, because the model learns from its4 / 44previous interactions.

[0017] RAG is opposed to mere semantic research, which is another technique used to increase the accuracy of the LLM-based generative Al. Semantic research consists in trying to understand the meaning of the words and phrases used in the application, in order to find more relevant results.Semantic search is not limited to keywords, but tries to capture the nuances and contexts of queries.

[0018] Keyword-based search can, in fact, return results that are too wide, too limited or wrong, if it does not understand the meaning of the question well. For example, a simple question about native Spanish flowers could use "flowers" and " Spain" as keywords and find data that both contain, but the system may not know what "flowers in Spain" means and then retrieve irrelevant, insufficient or wrong information. This keyword-based search could also lose information because it is too rigid: The flowers originating in Navarre may not be considered, although they grow in Spain, because that keyword was not there.

[0019] Semantic research is part of the RAG, which combines the meaning of the questions and documents with the updated and contextual data, in order to offer to the generative promptness, precision and evidence, overcoming the capabilities of the LLM alone.

[0020] We think of a sports tournament that wants to offer fans and media the possibility to use a chatbot to consult his data and to have answers on players, teams, history and rules of sport, statistics and current rankings. A generalist LLM could give answers on the story and rules or perhaps provide a player card. However, they would not be able to talk about the game of the evening before or provide up-to- date information about a given athlete's injury because he would not have such information, and since LMs require a considerable computing capacity to retrain, the models cannot be updated continuously.

[0021] In addition to the large, static LLM, the sports tournament has or can access many other sources of information, such as databases, datawarehouse, documents with player information and news feeds detailing each game. RAG allows the general purpose to exploit this5 / 44information. The chatbot can give more up-to-date, more contextual and more correct information.

[0022] In short, RAG allows LLM to provide better responses.

[0023] By making another concrete example we can imagine a customer who wants to know how to return a pair of tennis shoes that he bought online.Without the help of RAG technology, the e-commerce site chatbot wherethe customer made the purchase could give a wrong answer, as a clerk at the first arms, with vague and false statements such as "it is always possible to return the purchased items".

[0024] Return policies, which vary depending on product, purchasing methods, and local regulations, show the ineffectiveness of a chatbot based only on a standard LLM model. RAG, on the other hand, allows the system to use reliable sources, generating correct answers and avoiding errors.

[0025] These examples, though simple, show the two main problems of the large Language Model: 1. the tendency to fantasize, that is to respond without checking the information (in technical terms hallucinations)

[0026] The limitation of knowledge to the training date, without access to subsequent or private data

[0027] , currently the retrieval Augmented Generation is the only effective and efficient solution for these two problems.

[0028] RAG is therefore an Al technique that can increase the quality of generative artificial intelligence by allowing large language models (LLM) to use additional data resources without the need for retraining (LLM model retraining).

[0029] RAG models create knowledge databases based on data from organizations, and these databases can be constantly updated to help artificial intelligence provide up-to-date, contextual responses.

[0030] Chatbots and other conversational or process automation systems using natural language processing can benefit greatly from RAG and generative artificial intelligence.

[0031] The implementation of RAG requires technologies such as vector databases, which allow the rapid encoding of new data, and searches on the data to be inserted in the LLM.6 / 442.3.- PURPOSE OF THE METHOD

[0032] the method object of the present application is characterized in that it is possible to acquire data from external sources (Internet sites) or internal sources (files, documents, relational databases), to modify them so that their format becomes uniform, to divide them into smaller portions, to process them by means of an embedded linguistic model, place them in a vector database to make them easier to search, interpret them through anLLM model that can understand the human user's request and provide an exhaustive response even to complex and articulated requests, the method is devoid of possible hallucinations because it only considers the data that have been acquired and processed, it can be applied to user interfaces in which to make a request and obtain a response or directly inserted within a business context in which there are different software systems from which information can be collected, processed and sent to other systems in an automated manner.

[0033] With respect to the known RAG systems, the claimed method works in particular on the step preceding the search and, through the indexing of the data, completely solves the technical problem that occurs with RAG.

[0034] More specifically, the innovative component of the invention must be identified in the above-mentioned step or in the BUILT-IN LINGUISTICMODEL which allows to obtain a certifiable database.

[0035] The system that allows to realize the method is able to use both remoteLLM models (ChatGPT of OpenAI. Claude, Perplexity, etc.), how local (Llama. Mistral, Falcon and any other faces on the current scene as a state of the art). The system allows sensitive data to be preserved within a limited and resident environment within the European Community (GDPR compatible) and, in particular, in all cases, in order to preserve the intellectual property present in the learning database, so that this is not part of what mainstream LLM can use for training their models regardless of copyright and intellectual property of data that can also be enjoyed by external users.2.4.- DESCRIPTION OF THE METHOD

[0036] the claimed method is divided into 4 steps. Each step ensures that the7 / 44goal for which it was created is achieved and allows a correct result to be obtained without error. The method in its steps solves the problem that occurs with RAG and avoids the risk of hallucinations.

[0037] Phase 1 - phase

[0038] 2 acquisition - phase

[0039] 3 normalization

[0040] - phase 4 processing - interrogation (retrieval)PHASE 1 - ACQUISITION

[0041] the first phase of the method is that relating to the data acquisition. In the case of external sources, in particular Internet sites, the acquisition is carried out bycrawling web pages, extrapolating textual contents, images, metadata and other structured or semi-structured information present on the site. The acquisition takes place in compliance with the rules in force in the field of intellectual property and privacy. The software is configurable to specify the sites from which to collect the data, the types of data to be acquired and the frequency with which to perform the acquisition. This instrument is also capable of managing the acquisition in a continuous way or at time intervals defined by the user. Schematically, the instrument is able to:A) connect to specified internet sitesb) navigate through the web pages in an automated manner c) identify and extract relevantdata from the HTML pages d) manage different data formats present online (text, tables, images)e) respect the crawling ethical protocols, including the files robots.txt f) temporarily store the extracted data for subsequent processing.instead, a suitable software tool must be provided when it is necessary to acquire from internal sources. These sources include files of various formats (such as PDF, text documents, spreadsheets), digitized documents, relational databases, and other internal systems in a company. This tool securely accesses internal data, ensuring the integrity and confidentiality of the information. In addition, it can handle different file formats and connect to different databases, querying to8 / 44extract the necessary data. The software is configurable to specify the sources from which to collect the data, the access modes and the types of data to be acquired. Schematically, the instrument is able to:A) access local files in various formats (PDF, DOC, XLS, etc.).b) interfacing with relational databases through queries in SQL language c) reading and interpreting structured and unstructured documents d) managing permissions and security for access to internal data e) monitoring and detecting updates in internal sources f) selectively extracting relevant data from the identified internal sourcesSTEP 2 - NORMALIZATION

[0042] once acquired, data from different sources (both external and internal) may have different formats, structures and modes of representation. For this reason, the method provides a step of normalizing the data. This processconsists in harmonizing the data, converting it into a common and uniform format. For example, textual data is transformed into a standard text format, dates converted into a single time format, and numerical values made consistent in terms of units of measurement. This process ensures that the data are easily usable and comparable with each other in the subsequent steps of the method. In detail:(A) identification of the data structures present in the different sources(b) definition of a standard standard standard format for all data (c) conversion of the original data into the standardized format (d) cleaning of the data to remove inconsistencies or errors (e) harmonization of the nomenclatures and coding systems (f) checking the consistency and quality of the uniformed data afternormalization, the method provides for the subdivision of the data into smaller and manageable portions. This process consists of taking a9 / 44large data set or document and dividing it into segments, paragraphs, phrases or even individual words, as needed. The subdivision facilitates syntactic and semantic analysis of the data, making the subsequent processing more efficient. For example, a complex document can be divided into chapters or paragraphs, while a dataset can be divided into sets of records or rows. In detail: A) analysis of the logical structure of the contents b) identification of coherent and autonomous information units c) subdivision of the texts into paragraphs, phrases or chunks semantically relevant d) maintenance of the metadata associated with each portion e) assignment of unique identifiers to each segment f) preservation of the logical connections between the portions createdPHASE 3 - PROCESSING

[0043] in this phase real training takes place by means of a built-in linguistic model. This model is used to refine the abstract semantic representation of the previously pre-processed data in order to optimize the generation of embeddings. The information which in the next step is converted into vectors is thus enriched taking into account the context in which the information is found, evaluating the relations through a neural network.This step allows the model to understand the bi-directional context, that is, how each word interacts with the others within the sentence. In detail:A) contextualization ofthe information b) understanding of the bi-directional context between each word and the otherones c) adding metadata to the information on which to create embeddings d) Native reduction of the dimensions of the vectors e) creating different weights with respect to information not relevant for the context f)10 / 44participation in the subsequent steps of retrieval of thenormalized data, divided and processed through the built-in linguistic model, are subsequently inserted in a vector database. This type of database is designed to store data in a form that facilitates its search and retrieval. The information is represented as vectors, i.e. points in a multidimensional space representing the various semantic aspects of the content. This approach makes the data easily searchable, enabling you to quickly locate relevant information. In detail:G) conversion of the textual data into vector representations h) use of embedding techniques for semantic coding

[0044] I) Organization of the vectors in structures optimized for research j) efficient management of the storage space

[0045] k) Support for the incremental updating of the data

[0046] 1) maintaining the relationships between the vectors and the original data

[0047] after they are inserted into the vector database, the data is indexed.Indexing is to create a reference system that facilitates search within thedatabase with the participation of the built-in language model. In this context, indexing includes the creation of data structures that enable the most similar or relevant vectors to be quickly found than a specific request.This process optimizes the response times of the system, allowing quick and effective searches. In detail:A) creation of multidimensional indexes for vectors b) optimization of index structures for quick searches c) support for similarity and semantic proximity queries d) dynamic updating of indexes following data changes e) implementation of index compression techniques f) balance between research speed and resource consumptionPHASE 4 - INTERROGAZIONE (RETRIEVAL)the heart of the method lies in data processing through the built-in linguistic model with the involvement of an additional LLM model. This model is also able to

[0048] ,,,......understand the user s request, interpreting its syntactic and semantic meaning, and to provide a complete and11 / 44exhaustive response based on the data present in the vector database.The model is trained to handle complex requests, interpret articulated questions, and generate answers that fully meet the user's needs. In detail:A) integration of a pre-trained LLM optimized for the specific domain b) ability to interpret queries in natural language c) in-depth semantic analysis of user requests d) in-context search within the vector database e) generation of coherent and relevant responses f) dynamic adaptation to the specificities of the contestAdistinctive element of this method is the ability to avoid hallucinations, i.e. responses which are not based on the data actually collected and processed. The built-in language model is configured to respond only on the basis of data acquired, normalized and stored in the vector database. This approach ensures the accuracy of the responses and reduces the risk of errors or misinterpretations. In detail:A) verification of the correspondence between the generated responses and the source datab) implementation of mechanisms of traceability of the sources c) filtering of the information not supported by the acquired data d) explicit indication of the limits of the available information e) ability to request clarification from the user in case of ambiguityf) continuous updating of the knowledge base with new verified data the method further provides for the provision of a user interface through which the human user can formulate requests and obtain answers from the system. This interface can be realized in the form of a chat, a search form, or integrated in a business application. The interface is intuitive and accessible, allowing users to easily interact with the system and receive responses quickly and easily understood. In detail:A) responsive design adaptable to different devices12 / 44b) support for the insertion of queries in natural language c) clear and structured visualization of the answers d) Options for the interactive refinement of the searches e) Export and sharing of the results f) customized interface according to the user preferences finally, the method is designed to be integrated into a broader business context, where different software systems interact with each other. It can then collect information from other business software, process it, and return an automated processed output. This integration allows the method to operate smoothly within the enterprise ecosystem, improving overall efficiency and automation of document management processes. In detail:A) implementation of standardized APIs for data exchange b) support for secure communication protocolsc) ability to operate in batch mode for automated processing d) management of complex workflows between different systems e) monitoring and logging of interactions between systems f) scalability to adapt to variable data volumes and requests2.5.- DESCRIPTION OF THE SYSTEM

[0049] the system that allows the method to be implemented is contained in the project's src folder in the code repository and uses a series of tools present in the scripts folder to interact with the application infrastructure. perform document parsing, calculate embeddings using the built-in language model, and populate the database initially. The system is designed to manage various data sources such as documents, relational databases and content from the Internet.

[0050] The system comprises several main components. The backend is managed by FastAPI, which deals with API requests and coordinates data processing. The external language model is an LLM such as ChatGPT,Llama or Claude which generates responses based on the retrieval process of information by the embedded language model. In fact, for the generation of embeddings, the system uses an embedded linguistic model13 / 44which feeds the information retrieval process. A parsing system is used to extract and process data from different sources, while the PostgreSQL database and its PgVector extension are used to manage traditional queries and semantic similarity searches. The data flow in the system begins with the collection of data from PDF, DOCX, JSON, etc. files which are then processed by the parsing and chunking system. The processed data is transformed into embeddings thanks to the built-in linguistic model subsystem and stored in the vector database, together with the structured data. When a user queries the system, the input text embeddings are calculated and a semantic similarity search and traditional queries are performed to retrieve the support documents. The generated response is shown to the user, including the original sources.

[0051] Parsing scripts include various source-specific tools. For example, age.py parser is designed to analyze PDF files, extracting questions and answers, while parser doc.py handles internal documents saved as DOCX files, cleaning the text and preparing structured output for later analysis. The ff.py parser script is used to analyze the JSON format, converting theJSON data rows into structured JSON files.

[0052] The System exposes various API endpoints to interact with the system and monitor the health of the application. For example, / API / health-check checks the status of the application, while / API / auth / token handles user authentication by token.System endpoints, such as / chat / interact, manage interactions with the language model, calculating embeddings, and retrieving relevant documents to generate informational responses.

[0053] The system uses SQLAlchemy to interact with the database, with different ORM classes defined to manage users, documents, and impersonationdata. For example, the UserRepository class provides methods for creating, retrieving, and deleting users, while the DocumentRepository handles CRUD operations on documents and searching for relevant documents. TheImpersonationRepository class handles the handling of impersonation data, allowing the creation or updating of impersonation records in the database.

[0054] For deployment, the system can run on a variety of environments,14 / 44including Linux, Windows, and MacOS operating systems, using Docker containers to ensure a consistent execution environment. The detail manual describes possible deployment solutions, both on bare metal and on managed platforms such as the DigitalOcean App Platform. In a development environment, Docker and Docker Compose automate configuration, dependency installation, and database management. For deployment on DigitalOcean, the system can be configured and released via the platform, which manages the necessary infrastructure details and environment variables.2.6.- METHOD And SYSTEM OPERATION

[0055] We consider all the information an organization has: Structured databases, files and other unstructured documents, social channel data, news feeds, e- mails and chats. In the system, this vast amount of dynamic data is converted into a common format and stored in a knowledge library accessible by the generative artificial intelligence system.

[0056] To make the system operational, data from different sources is transformed into a common format and saved in a database to which the generative artificial intelligence system can access. This data is then converted into numerical codes using an algorithm called embeddings, a subsystem of the built-in linguistic model and stored in a vector database, which allows to search and retrieve the information relevant to the context in a fast way.

[0057] In greater detail we analyze the elements that make up the structure of the system in the sequence in which they act: Data acquisition and preparation, understanding of the question, searching for relevant information and generating the answer.

[0058] Acquisition and preparation of the data

[0059] in order for the search engine and the generative model to act and interact with each other in the system, it is necessary to acquire the data that will be subsequently processed. Regardless of their source format (text files, relational databases, e-mails, etc.), the textual data undergoes a decomposition that precedes their vectorization (saving in the vector database) by parsing and chunking.15 / 44

[0060] The parsing is performed by a special module of the system called parser.This module analyzes the syntactic structure of incoming data in continuous form. This process consists of the following aspects:

[0061] Lexi cal analy si s(T okengenerati on)

[0062] the generation of tokens, or lexical analysis (3.1), represents the first stage of the parsing process. A token is a sequence of characters that is treated as a logical unit or symbol. We refer to a word, a number, a punctuation symbol, or other elements that have a specific meaning in the context of the language being analyzed. The process of transforming raw text into tokens is called tokenization. The rules established by the parser determine which characters indicate the start of a new token.

[0063] Tokenization of text is the process of subdividing a text string into smaller components called "tokens". These tokens can be words, phrases, symbols, or other significant units. To illustrate this, we will use the phrase " I love pizza daisy". There are several approaches to tokenization, which can vary by context and application.Methodsoftokenizationofthesystem

[0064] original phrase: " I love pizza daisy"

[0065] methodi -Tokeyzizationby words

[0066] this method divides the text into individual words. It is the most common type of tokenization in the system and useful for subsequent natural language processing (NLP) applications. Result:

[0067] " I", " AMO", " La", "pizza", "daisy"method 2-charactertokenization

[0068] this method divides the text into single characters. Its use in the system is less common than word tokenization, but may be useful in some applications such as natural language processing for languages that do not use spaces between words.

[0069] Result:

[0070] The>nu> the »»"a

[0071] " > > > "h"1’00771 1,,, a, III, O,, 1, a,, p, 1, Z, Z, a,, III, a, L J figif »’’E” ”r” ”1” ”3”16 / 44method 3 -punctuationShift

[0073] in some cases the system maintains punctuation marks as separate tokens. Although the phrase " I love pizza daisy" does not contain punctuation, we can imagine a comma version: " I love pizza, daisy".

[0074] Result:" I", " I love", " La", "pizza", " I love", "la", "pizza", " I love", " ILJlove", "la""margherita"Subtokenization

[0076] the subtokenization is the process of the system of subdividing the tokens into even smaller parts called "subtoken". This process is particularly useful in the subsequent processing steps of natural language (NLP) to manage morphologically rich languages or to treat rare or unknown words.Exampl eof Subtokenizati on

[0077] original phrase: " I love pizza daisy"algorithmsteps

[0078] 1. Initialization: Each character in a word is considered an initial token.For the phrase " I love pizza daisy", we initially have:" I love pizza daisy"2. Frequent pair Merging: The algorithm finds the most frequent token pairs and iteratively j oins them. Suppose that " Pi" and "zz" are the most frequent pairs initially. Iteration 1:" I love pizza daisy"-" I love pizza daisy " iteration 2: " I love pizza daisy " Ilove pizza daisy" this process continues until a certain number of underloken or a minimum desired length is reached.

[0079] Syntactic

[0080] Analysis Syntactic analysis of the system receives the sequence of tokens and verifies that they constitute correct expressions. It uses a formal grammar that recursively describes the components of an expression and the order in which they must occur. System syntactic analysis is a crucial phase of text parsing in natural language processing (NLP). This process consists in examining the grammatical structure of a sentence to determine how words combine to form constituents such as nominal17 / 44phrases, verbal phrases, and so on. Syntactic analysis helps to understand the relationship between words in a sentence, facilitating understanding of the meaning of the text.Step softhesy ntacti canaly si s

[0081] once the text has been tokenized (and subtokenized) the system proceeds with the following steps.1. Identification of the parts of the Discourse (POS Tagging): Each token is classified in a part of the speech, as noun, verb, adjective, etc.For example:" I" (pronoun) " AMO" (verb)" La" (article) "pizza" (noun)"daisy" (noun)2. Construction of the syntactic tree: Using speech part information, the syntactic analyzer constructs a syntactic tree representing the grammatical structure of the sentence. The syntactic tree shows how tokens combine to form grammatical constituents.

[0082] Example of syntactic tree for the phrase " I love pizza daisy"S / ENP VP NP IIA

[0083] I love Det NPE

[0084] the NI

[0085] pizza daisy

[0086] in this tree:

[0087] S represents the complete sentence.

[0088] NP (nominal sentence) represents the subject " IO" and the object "pizza daisy".

[0089] VP (verbal sentence) represents the " Aamo" predicate.18 / 44

[0090] Det (determinant) represents the article " La".

[0091] N (name) represents the nouns "pizza" and "daisy".

[0092] 3. Grammar rules: The system's syntactic analyzer uses a set of grammatical rules to determine the correct structure of the syntactic tree.These rules define how the parts of the speech can be combined to form grammatically correct sentences.

[0093] Example of grammatical rules

[0094] S -> NP VP: A sentence (S) consists of a nominal sentence (NP) followed by a verbal sentence (VP).., NP -> Det N | N: A nominal sentence (NP) may consist of a determinant(Det) followed by a name (N) or only a name (N).

[0096] VP -> V NP: A verbal sentence (VP) consists of a verb (V) followed by a nominal sentence (NP).

[0097] 4. Verification of Grammaticality: The analyzer checks whether the sentence complies with grammatical rules. If the phrase is grammatically correct, the syntactic tree is accepted. Otherwise, the analyzer reports a syntax error. Syntacticanalyzersusedbythesystem1. Rules-based syntactic analyzers: Use predefined grammatical rules construct syntactic trees. These analyzers are effective for tolanguageswith a well-defined syntax.2. Statistical syntactic analyzers: Use probabilistic models, such as hidden Markov models or grammars without probabilistic context, to determine the syntactic structure based on training data.3. Dipenential syntactic analyzers: Concentrate on word dependencies rather than sentence structure. Each word in the phrase is linked to another word to which it is grammatically subordinate.SemanticanalysisThe last step of the parsing phase is semantic analysis (3.3), which interprets the implications of the expression just validated

[0098] and implements the consequent actions. This is the process by which the meaning of the tokens and syntactic structures identified during lexical and syntactic19 / 44analysis occurs. This step is to ensure that the components of a text respect the semantic rules of the language, such as the proper use of data types, flow control, and correspondence between topics. The aim is to ensure that, in addition to being syntactically correct, the text is also logically coherent.Obj ectivesofsemanticanalysis

[0099] 1. Understand the meaning of words: Interpret words in their specific context, considering polysemy (a word with several meanings) and disambiguation of meaning.2. To represent semantic relations: To identify the relationships between words and phrases, such as synonimia, antonymia, hyperonimia and hyponimia relations.3. To represent the structure of the meaning: To construct formal representations of the meaning that can be used for logical inferences and other elaborations.Componentsofsemanticanalysis

[0100] 1. Representation of the meaning of

[0101] semantic lexical words: Dictionaries which provide information on the meanings of words and their relationships.2. Word sense Disambiguation (WSD):Process of identifying the correct meaning of a word in a specific context. For example, the word "rate" may mean "interest rate" or"animal rate" depending on the context.

[0102] 3.

[0103] Logical formal semantic representations of the first order: Used to represent propositions and their logical relationships. Frame Semantics: Representation of the meaning based on frames or conceptual schemes that describe typical situations in which words are used.

[0104] 4. Representation of semantic relations semantic roles: Identify the role that each entity plays in an action or event described by a sentence. For example, in " Mario has brought a pizza to Peter", " Mario" is the agent, "a pizza" is the theme and " Peter" is the recipient.20 / 44

[0105] Chunking

[0106] this activity is carried out in the system by another module called a chunker which deals with the textual analysis to divide documents or text streams into more manageable and significant portions. Such segments(chunks) may include whole sentences, word groups, or clauses. The aim of this technique is to make the text clearer and to simplify the subsequent analysis.

[0107] For example, in chunking, it is possible to divide a long paragraph into shorter sections to increase readability, or to segment the 16 digits of a credit card number into groups of four to facilitate reading and storage.Textbooks also often use this structure to organize content in thematic paragraphs.

[0108] The operations that make up the chunking are as follows.1. Defining Chunking Rules: Rules are defined based on the patterns of the parts of the speech to identify and segment chunks.2. Applying Chunking Rules: Rules are applied to the token and POS tag sequence to segment text into chunk.DetailedexampleofChunking

[0109] original phrase: " I love pizza daisy"

[0110] the phrase after the previous parsing process comes already processed in this way:

[0111] " IO" (PRP - pronoun

[0112] ) " AMO" (VBP - verb)

[0113]

[0114] " La" (DT - determinative article) "pizza" (

[0115] NN - noun) "daisy" (NN - noun)definitionofChunkingrules

[0116] the system uses regular expressions (RegEx) to define the chunking rules.For example, a nominal sentence (NP) may be defined as an article (DT) followed by one or more nouns (NN).ApplyingtheChunkingRulesthe RegexpParser module is then used to apply the chunking rules to the

[0117] token and POS tag sequence.21 / 44

[0118] Re sultato(S (NP IO / PRP) (VP AMO / VBP (NP La / DT pizza / NN daiheritaINN))) Vectordatabase

[0119] once the data has been processed through parsing and chunking are stored within the vector database according to this sequence:1. Text Vectoring - before saving data to the database, text is transformed into vectors using the embedded language model subsystem (embeddings). This method allows the semantic and syntactic information of words to be encoded in a vector space. Using a body of unannotated text, this technique generates a vector map where the vectors representing the words are closer to each other if the words appear in similar language contexts. These vectors numerically represent text, facilitating analysis and comparison operations.2. Vector map - in the vector database, each text document or chunk is represented as a vector in a multidimensional space. These vectors are saved as records in the database, with each vector corresponding to a chunk or phrase derived from the chunking process.3. Vector Indexing - to improve query efficiency (database queries), vectors are indexed using tree data structures. A tree structure is a type of data organization that allows information to be represented in a hierarchical manner. A tree consists of nodes connected by arcs. The root is the root node and is located at the top of the tree. From here, child nodes depart which may have further subgroups of nodes, called sub-trees. The nodes without children are called leaves or terminals.Tree structures are particularly useful for data search, insertion and deletion operations, thanks to their organization that allows to divide the problem into smaller and manageable sub-problems. Their ability to represent hierarchical relationships and provide efficient access to data makes tree structures critical in data management. These techniques allow to perform quick searches for similarity in the database, facilitating the finding of similar documents or text segments.4. Metadata - in addition to vectors, the database stores metadata about each chunk, such as the location in the original document, syntactic22 / 44information (e.g. phrase type, grammatical dependencies, etc.), and other semantic annotations that help interpret the context of the segment.5. Relations and links - The vectors may then be linked to each other to reflect logical or narrative relationships between different text segments.This is useful in applications such as speech analysis and text content-based applications.

[0120] Saving the parsing and chunking data in a vector database allows the use of advanced search techniques for similarity and clustering (clustering is an unsupervised machine learning technique that aims to organize a set of objects in groups according to their similarity. In other words, clustering tries to group data so that the elements within each cluster are more similar to each other than the elements of other clusters. This technique is used to discover structures and patterns hidden in the data without the use of predefined labels). This makes possible applications such as information retrieval, semantic analysis of text and verticalization in intelligent response systems to questions based on understanding natural language.

[0121] In summary, the steps related to the data flow in the vector database are as follows. DataVettorzzzazioJle(creationofembeddings)

[0122] Vectoring is the process of transforming text into numerical representations called embeddings. These embeddings capture the semantic and syntactic characteristics of words and phrases. The vectorization of the text takes place through the linguistic engine incorporated in the system and which also facilitates the search and recovery operations based on semantic similarity. Here is a detailed description of its components and operation.Creatingthe V ectorMap

[0123] oncethe embedding is created, it is organized into a vector map (5.3). The vector map is a representation of the vectors in an n-dimensional space, where the proximity of the vectors represents the semantic similarity between the words.Creatingvectorindexes23 / 44

[0124] the vector indexes facilitate the rapid search of similar vectors within the database. The system uses k-d tree data structures (k-dimensional tree).

[0125] Vector indexes are organized in a tree structure composed of nodes and arcs, which allows an efficient search. Each node represents a vector or group of vectors. Arcs connect nodes, representing proximity or similarity relationships.Addingmetadata

[0126] inaddition to vectors, the built-in language engine adds metadata about each chunk, such as location in the original document, syntactic information, and other semantic annotations. This additional information is associated with each vector to facilitate understanding of the context.Addingrelationshipsandlinks

[0127] in the system also defines relationships between vectors to represent logical or narrative relationships between text segments.•Relations: Definition of semantic relations between vectors.•Links: Creating explicit links between related vectors.

[0128]

[0129] ( ' WU "f!ageate” }.(" WQ",lsoggetto'5L1 "pizza”, WargheiW1*,

[0130] ExampleSearchforsimilarityandClustering the tree structure and theindices of vectors allow to perform searches by similarity (5.7) and clustering (5.8) efficiently. Clustering techniques such as K-means can be used to group similar vectors.

[0131] Search by similarity (5.7): Use the tree structure to find similar vectors based on a query.

[0132] Clustering (5.8): Grouping of vectors into semantic clusters.

[0133] Example (Search by similarity):

[0134] # Query to find the nearest vectors

[0135] query = model.wv["pizza"]

[0136] dist, ind = tree.query([query], k=3)24 / 44

[0137] print(ind)

[0138] example (Clustering):

[0139] the application of clustering

[0140] kmeans = KMeans(n_clusters=2)

[0141] kmeans. fit(embeddings)

[0142] labels = kmeans. labels_

[0143] print(labels)linguisticmodelincorporated

[0144] with respect to the preceding point, to generate embeddings which are then saved in the vector database, the built-in linguistic model follows a series of propaedeutic actions, which are essential to transform the textual data into vector representations #. Here are the main steps: Contextencoding

[0145] Number ID Assignment: Tokens are converted to predefined numeric IDs, which represent each token in the template vocabulary. These IDs are the next basis for the vectors.

[0146] Context consideration: The model performs bi-directional processing,including the meaning of a word based on the preceding and subsequent context in the sentence. This step is crucial to generating contextual embeddings.Appli cati onoftheneural

[0147] model passing through neural levels: The numerical tokens are passed through the neural network layers of the linguistic model. During this step, the model applies attention (self-attention) to each token, including its relationship with the others in the sentence. Long-range dependency capture: The built-in language model captures relationships between words even at a long distance, maintaining a global view of the phrase or chunk.Generationofembedding creation of vectors: Each word or phrase is converted into a numeric vector. These vectors (embeddings) are dense representations in a multidimensional space. Each dimension captures an aspect of semantic meaning.25 / 44

[0149] Context-based modification: Embeddings are not static. Each word gets a different embedding depending on the context. For example, the word "bank" will have a different embedding if it refers to a financial bank or a bank of the river.Optimizationandreductionofdimensionalityreduction

[0150] of dimensionality: Techniques such as PCA (Principal Component Analysis) and t-SNE are applied to reduce the number of vector sizes, maintaining semantic meaning but making the data more manageable for archiving and searching in the vector database.Savingtothevectordatabase

[0151] Indexing of the embeddings: The generated embeddings are saved and indexed in the vector database, which allows to quickly perform neural search operations, used to find the nearest vectors and therefore the most semantically similar documents.

[0152] Binding to original data: Each embeddings is saved along with the metadata that links it to the original document, so that during the search phase, the system can retrieve the relevant chunks based on the queries. Usingembeddingsforsubsequentqueries

[0153] semantic search: When a user sends a query, the query text is tokenized and vectorized following the same process already described and the system uses these embeddings to compare the query with those already saved in the vector database.

[0154] Ranking: The results are sorted by the distance between the vectors, with the chunks closest to the query vector presented first.Practicalexample

[0155] if a user asks how to "reset password". This phrase is tokenized, vectorized by the built-in linguistic engine, and the resulting vector is compared with the embeddings saved in the vector database. The most relevant chunks are retrieved and used to generate a response.Interrogati onofthe

[0156] system The interrogation of the system can take place by direct interaction with the end user or in automated mode.

[0157] In the first case, a direct request is considered by a human being through26 / 44a user interface where they can enter their question / query in a text field.The user interface of the system can be web-based (present in a public web page or within an intranet) or application (a software application installable on the user's computer). In the context of direct interaction with the user, the system delivers the response to the request received in textual form. In this case, the original text from which it was extracted (text from the original database) can also be present and, where this text is present in a file (document or spreadsheet), also the link to the file itself.However, when the system is run in automated mode, it is not necessary for the user to interact with an explicit request. In this case the triggering event the execution can be of different types. In the context of integration into existing business processes and software systems, the system has automated reading connectors from relational databases, file folders, e-mail or API (Application Programming Interfaces) that allow different software to interact with each other. They function as intermediaries, allowing access to functionality or data of an application, operating system or other service in a standardized manner. APIs allow integration and interaction between different platforms and services.) Similarly, the system has its own APIs where it is necessary to run it by third- party systems / applications.

[0158] The tasks that the system can perform in automated mode are:

[0159] production of textual responses

[0160] creation of texts

[0161] creation

[0162] of documents compilation of questionnaires

[0163] verification of accuracy of texts with respect to a starting database

[0164] Theoutput can be both the production of physical files created according to specific rules and the supply of third systems (applications, databases, etc.). All possible automated execution of the system takes place after initial configuration on the basis of the context (integration with existing systems) and the task (which output must produce).

[0165] More in detail the process of running the system is as follows:

[0166] Interrogation - in automated mode this can occur with the appearance of a27 / 44new record in a relational database or in an application connected to the system, or of a new file in a specific folder under monitoring. When we talk about direct interaction with the user, it is a specific question placed to the system (query) through the user interface.

[0167] Understandingthequery - the input module processes the request through the built-in linguistic model and then calls the LLM model for a more precise understanding of the query that is then forwarded to the vector database. Retrievalofrelevantdata - the built-in linguistic engine is concerned with transforming the query into its vector form and compares this vector with those present in the vector database through searches for similarity and clustering. From these vectors the chunks with the greatest proximity to the query are selected thanks to their sorting within the indexes, the metadata as well as the relations and the links. Sending relevantdata - the extracted chunks are combined with the query, thus creating a relevant data set that is sent to the LLM model.

[0168] Responsegeneration - the LLM model receives only the relevant data setand produces the response / output in the required format and sends it to the user interface or to the integrated systems (third-party applications, relational databases, folders, etc.).

[0169] Technical documentation

[0170] The web application is contained in the src folder of the project.

[0171] This is designed to extract and respond via chatbot to sources related to document analysis.

[0172] Inside the scripts folder there are tools that allow to interact with the application infrastructure to perform the parsing of the documents, calculate the embeddings and perform the initial population of the database.

[0173] The document parsing tools are specific to the different databases to be processed.SystemarchitectureMaincomponents

[0174] 1. FastAPI backend: Manages API requests and coordinates data28 / 44processing.2. LLM (ChatGPT, Llama, Mistral, Claude, etc.): A language model that is interrogated for the generation of responses.3. Built-in language model: Model for the generation of embeddings also used in the information retrieval step and for providing the knowledge base to the LLM model.4. Parsing system: Extracts and processes data from the different sources.5. PostgreSQL database: Used for traditional queries and as the engine base for vector search.6. Vector database PgVector: PostgreSQL extension used for semantic similarity search via embeddings.7. Docker container: Provides a consistent execution environment and facilitates deployment on Digital Ocean (or general hosting).Dataflow1. Data Collection: Data is extracted from sources such as PDF, DOCX, and JSON files.2. Parsing: The proprietary parsing system, supported in this case by the GPT model, processes the data to extract structured information.3. Storage: Processed data is transformed into embeddings and stored in the vector database along with structured data thanks to the built-in linguistic model.4. Query: Users query the chatbot, the input text embedding is calculated, and a semantic similarity search (cosine similarity) and traditional queries are performed to retrieve the support documents thatwill provide the knowledge base for the generation of the response by the model. The response is generated and shown to the user, including the original sources.Scripts

[0175] parser age. py

[0176] the following Python script is designed to analyze PDF files and extract questions and answers.

[0177] The raw DIR and PROCESSED DIR constants are defined as the29 / 44directories in which the raw and processed files are stored, respectively.

[0178] The -BREAKS and -BREAKS QUERY lists contain phrases that are used to divide the text of PDF files into questions and answers.

[0179] The extract text _from_pdf function takes a PDF file as input and returns the text contained in the file. Use the PdfReader class of the pypdf library to read the PDF file and extract the text from each page.

[0180] The parse opinions age function takes the extracted text from a PDF file and analyzes it to extract the questions and answers. First it cleans the text byreplacing some characters and removing extra spaces. Then check the presence of phrases from the list OF QUESTION BREAKS andOPINION BREAKS in the text. If these sentences are present, the text is divided into questions and answers based on these sentences.

[0181] Te majnfunction is the main entry point of the script. First it gets a list of folders in the raw DIR directory. For each folder, gets a list of files and processes them one by one. Reads the file, extracts the text from the file, and analyzes the text to extract the questions and answers. If an error occurs during analysis, the file path is added to the error list and the error is logged. Otherwise, a ParseResponse object is created with the analyzed text and file path, and this object is saved as a JSON file in thePROCESSED DIR directory. Finally, a list of error files is saved as a text file.

[0182] The script is designed to run as a standalone program. If the script is executed directly (i.e., not imported as a module), the main function is called using the asyncio.run function, which executes the main function as an asynchronous task.

[0183] Parser doc. py

[0184] analyzes internal documents saved as DOCX files, cleaning the text and preparing a structured output for the following analysis.

[0185] Two directory paths are defined: RA W DIR and PROCESSED DIR.

[0186] The function extract text from word document takes a Word document in bytes format, reads the text from it and returns the text as a string.

[0187] The parse doc function takes a string, replaces new line characters with spaces, and removes extra spaces. Then returns the processed string.30 / 44

[0188] The main function is an asynchronous function that processes all internal documents in the raw DIR. Lists all files in the directory, reads each file, extracts the text from it, analyzes the text, and saves the processed text in the PROCESSED -DIR. If an error occurs during text extraction or analysis, the file path is added to an error list and the error is logged. The error list is then saved in a file at the end of the function.

[0189] ff.py

[0190] parser this Python script is designed to analyze the JSON dataset.

[0191] The get file storage function is used to obtain an instance of FileStorage, which can be a local storage file or an Amazon S3 storage file, depending on the configuration. This instance is used to read and write files.

[0192] The script defines a raw DIR constant for the directory containing the raw data files and PROCESSED DIR for the directory where the processed data will be stored.

[0193] The parse ff function is a support function that takes a dictionary representing a line of JSON data. Sanitide the title by replacing the bars with spaces, eliminating the leading and trailing spaces, and then replacing the remaining spaces with dashes. It then returns a tuple containing the sanitized title and a string including the date and text from the JSON data.

[0194] The main function is an asynchronous function that lists all files in the RA W DIR, reads each file and divides it into rows. For each line, it records progress, skips empty lines, analyzes the line using the parse _ff function, creates an instance of ParseResponse, and saves it as a JSON file in the PROCESSED DIR. The name of the JSON file is derived from the title of ParseResponse. The script uses the logging module to record its progress. The logging level is set to info, which means that the script will record all informational messages, warnings, and errors.APIEndpoiiitsWeb Application

[0195] the complete API documentation is present at the url / docs in OpenAPI format / API / health-check

[0196] method: GET

[0197] Description: Check the health status of the application by simply querying31 / 44the database. It is essential to monitor application availability and responsiveness. Answer:

[0198] I

[0199] "status": "healthy"}

[0200] / API / auth / token

[0201] method: POST

[0202] Description: The endpoint performs the login for access token function that takes two parameters: Form data and repository _provider. The form dataparameter is an instance of OAuth2PasswordRequestForm that is expected to contain the user's user name and password. This is annotated with depends(), a FastAPI dependency injection system that ensures that module data is provided when the function is called. The repository _provider parameter is an instance of RepositoryProvider, which is used to interact with the database.

[0203] within the function, the authenticate user function is called with repository_provider, form data.username, and form data.password as arguments. This function is expected to return a user object if authentication is successful, or None otherwise. If the user object is None, an HttpException is raised with a status code 401 (unauthorized), a" Incorrect username or password" detail message, and a header indicating that the authentication scheme is bearer. This exception is defined in the FastAPI framework and is used to return HTTP error responses.

[0204] If the user obj ect is not None, an access token is created with the create accesstoken function. The token is created with the user's user name as the subject and an access TOKEN _expire_ MINUTES expiration time from the current time.

[0205] Finally, a Token object is returned with the access token created and a "bearer" token type. This Token object is a Pydantic model that will automatically be converted to a JSON response by FastAPI.

[0206] / Chat / interact

[0207] method: POST

[0208] Description: Asynchronous endpoint accepting POST requests.32 / 44

[0209] The interact function accepts four parameters: body, chatbot, embedding model, and repository_provider. The body parameter is an instance of the EvaluateBody class, which is expected to be provided in the body of the request. It contains the text to be sent to the chatbot, the name of the database in which to search for relevant documents, the number of documents to be retrieved and the minimum score to consider a relevant document.

[0210] The chatbot, embedding- model, and repository _provider parameters are dependencies that are injected into the function by the FastAPI dependency injection system. The chatbot is an instance of the chatbot class, theembedding model is an instance of the EmbeddingModel class, and the repository _provider is an instance of the RepositoryProvider class.

[0211] The function first computes an embedding for the input text using the embedding model. Next, it retrieves relevant documents from the database using the provider repository. The documents are then formatted in a string and combined with an impersonation string to form the system message for the chatbot.

[0212] The function then attempts to get a response from the chatbot using the system message and input text. If an error occurs during this process, raises an HttpException with a status code 500 and a detail message describing the error. Finally, the function returns an instance of theEvaluateResponse class, which contains the chatbot response andsupporting documents. The EvaluateResponse class is a Pydantic model that includes a text field for chatbot response and a list ofDocumentResponse objects for supporting documents. Each DocumentResponse object includes the title, content, database name, and similarity score of a document.

[0213] / Chat / impersonation method

[0214] : POST, get

[0215] Description:

[0216] The chatbot has a feature called "impersonation", which is the basic prompt injected into each chat request.

[0217] The ImpersonationBody class is a Pydantic model used for data validation.33 / 44It has a single text field of type str. This field represents the new basic prompt for the chatbot. The field function is used to add a description to the text field.

[0218] The current impersonation function is a get endpoint at the " / impersonation" path. Uses dependency injection to obtain an instance of RepositoryProvider through the get_repository_provider function. The function returns the current impersonation of the chatbot by calling the get impersonation method on the repository impersonation of the repository _provider. The update impersonation function is a POST endpoint at the same " / impersonation" path. This also uses dependency injection to obtain an instance of RepositoryProvider. It also takes an instance of ImpersonationBody as input. This instance is created automatically by the request body thanks to the automatic bodyparsing of the FastAPI request. The function updates the current impersonation of the chatbot by calling the create or update impersonation method on the impersonation repository of the repository _provider, passing the text field of the ImpersonationBody instance as an argument. The status_code=201 argument for the decorator @router.post indicates that the endpoint will return a status code 201 at the end of successful execution, which is the standard response for a successful HTTP POST request indicating that a resource has been created.ApplicationORM

[0219] The application interacts with the database using the SQLAlchemy library.

[0220] Several classes are defined for interaction with domain objects:•UserRepositoryDocumentRepository ImpersonationRepository UserRepository

[0221]

[0222] the class has three main methods: Create user, get user, and delete user.

[0223] The create user method takes a user object as an argument and creates a new user record in the database. First, it creates a UserTable object (representing a row in the User table in the database) with the user name and password from the User object. Then opens a new session with the34 / 44database, adds the new UserTable object to the session, and confirms the session. This effectively saves the new user record in the database. The method then returns the original User object.

[0224] The get user method retrieves a user record from the database by user name.Opens a new session with the database, queries the User table for a record with the supplied user name, and returns the first result. If a user with the supplied user name is found, the method creates and returns a new user object with the user name and password from the database record. If no user is found, the method returns None.

[0225] The delete_ user method deletes a user record from the database by user name. Opens a new session with the database, queries the User table for a record with the supplied user name, and deletes the first result from the session. Then confirm the session to save the changes to the database.

[0226] In all three methods, the with self.new_session() as session: Statement is used to create a new session with the database. This is a context manager that ensures thatthe session is closed correctly after the operation, even if an error occurs. This is a good practice as it helps to prevent resource losses.

[0227] DocumentRepository

[0228] this class provides methods for interacting with a database to performCRUD (Create, Read, Update, Delete) operations on documents.

[0229] The get document method retrieves a document from the database based on the document ID provided. Queries the DocumentTable for a document with the specified ID and, if found, returns a Document object. If no document is found, returns None.

[0230] The list, documents method retrieves all documents from the database. It queries the DocumentTable for all documents and returns a dictionary in which the keys are document IDs and the values are document objects.

[0231] The retrieve relevant documents method retrieves a specified number of relevant documents based on the provided embedding and database name. It executes a complex SQL query that merges the DocumentTable and the DocumentEmbeddingTable, filters by the database name, and sorts the distance of document embedding for the cisne. The result is a list35 / 44of tuples, each containing a Document object and its cosine distance.

[0232] The create document method creates a new document in the database.Creates a new DocumentTable object with the document details provided, adds it to the session, and confirms the session to save the changes to the database.

[0233] The update document method updates an existing document in the database. First check whether the document with the provided ID exists. If it exists, updates the document details in the DocumentTable and confirms the session. If the document does not exist, a ValueError is generated.

[0234] The delete document method deletes a document from the database based on the ID of the document provided. Queries the DocumentTable for the document with the specified ID and deletes it from the session. The changes are then confirmed in the database.

[0235] Finally, the delete all documents method deletes all documents from the database.Executes a delete query on the DocumentTable and confirms the session to save the changes to the database.

[0236] ImpersonationRepository

[0237] this class is used to manage impersonation data.

[0238] The get impersonation method retrieves the current impersonation from the database. Opens a new session, queries the ImpersonationTable table for the first record, and returns an Impersonation object built with the retrieved data. If no impersonation data is found, returns None.

[0239] The create or updateimpersonation method creates a new impersonation record or updates an existing one in the database. Opens a new session, queriesthe ImpersonationTable table for the first record, and if no records are found, adds a new ImpersonationTable record with the provided impersonation. If a record is found, updates the impersonation of the existing record. After creating or updating, commits changes to the database.

[0240] The Impersonation class is a simple data model that represents an impersonation entity. It has two attributes: impersonation and timestamp.The impersonation attribute is a string representing the impersonation and timestamp is a datetime object representing the time when the36 / 44impersonation was created or updated.DeploymentApplication

[0241] The application is written in the Python programming language and uses the FastAPI framework to expose rest endpoints that allow the user to interact with the chatbot. In addition to the application code, the data persistence is managed by a PostgresSQL database with PGVector extension for the management and retrieval of the embedding linked to the chatbot knowledge base.

[0242] Both technologies can be installed on Linux, Windows and MacOS operating systems.

[0243] The detailed manual describes the different possible deployment solutions, both on bare metal and on managed systems (such as the DigitalOcean App Platform).

[0244] Basic prerequisite application start (in any environment, dev, staging, prod) is the setup of environment variables that allow the application to be configured at startup. These are within the "src / config / environment" folder and must be present for proper startup. An example of an environment variable file is as follows:

[0245] The values in this case will be set as environment variables on the cloud provider.

[0246] It is also necessary to set up an additional environment variable " APP ENV" that allows the application to load the correct *.env from which to read the configuration (if not provided the default env file will be ".dev.env".

[0247] The possible values are:

[0248] APP_ENV=dev

[0249] APP_ENV=staging

[0250] APP_ENV=production

[0251] APP_ENV=testdevelopmentenvironment

[0252] The development environment allows you to run the application on any Windows, Linux or MacOS machine using Docker container technology, docker compose and devcontainers from VS Code. The use of containers37 / 44allows to automate the configuration, the installation of dependencies and the infrastructure (database).

[0253] The requirements are:

[0254] Docker Installation on Host Machine

[0255] Docker Installation Compose on Host Machine

[0256] VS Code Installation

[0257] Dev Containers Extension Installation

[0258] opening the Application in the container (the command window can be viewed via the button at the bottom left of VS Code)

[0259] once the application is opened in the container, it will be sufficient

[0260]

[0261] to execute the make run command in the VS Code terminal to run the deployapplicationonDigitalOceanApp

[0262] platform (example) for the deployment of the application on DigitalOcean the use of the App Platform allows to abstract the infrastructural details that will be managed entirely by DigitalOcean.

[0263] For configuring the application on DigitalOcean, the steps to follow are as follows: From the account home page click on the " Create" drop down and on the " App Platform".

[0264] Select the code provider (GitHub) and from the drop down

[0265] select the repository then select the reference branch and the folder where the application entry point from which to execute the command to launch the app is present.

[0266] The platform app can automatically understand the programming language used, the framework and the dependencies needed (for python projects it automatically looks for the "requirements.txt" file within the project).

[0267] Going to " Edit" we can see the type of resource that will be created and modify the " Run command" gunicorn src.web.main:app --workers 2 --worker-class uvicorn.workers.UvicornWorker Tornado back and clicking on " Edit Plan" we can change the cost of the machines based on costs and traffic.

[0268] You can then select the environment variables for the application (useful for defining database endpoints, secrets, API keys, etc.).38 / 44

[0269] On info you can choose the region on which to deploy (choose the nearest geographic location where users are located) click on "review" and then " Create Resources" to release the application. The application is now being created and deployment can be monitored on the respective dashboard. Database

[0270] Development environment

[0271] in development environment the database and its configuration are automatically managed through docker File and docker compose. Simply follow the application startup guide for bare metal

[0272] the database installation process on a generic virtual machine running Linux requires the following steps.

[0273] Updating packages and installing postgresql

[0274] sudo apt-get update

[0275] sudo apt install postgresql postgresql-contrib

[0276] Startup of the database

[0277] sudo systemctl start postgresql. service

[0278] Checking the status of the service

[0279] to verify that the database is up and running Run the following command

[0280] sudo systemctl status postgresql. service

[0281] creating user and password PostgreSQL it uses a default user "postgres" that can be used as a basic user for database management.

[0282] We execute on the linux machine the following command to change user

[0283] sudo -I -u postgres

[0284] and we start the terminal Postgres with

[0285] psql

[0286] We follow the

[0287] password update \password creation of the database

[0288] At this point we can initialize our database with the command

[0289] CREATE DATABASE < DATABASE-name>;

[0290] once the database has been created it will be necessary to install the PgVector extension for the management of the vector search for the purposes of the document retrieval by the chatbot Installation PgVector39 / 44PgVector

[0291] is an open source extension of postgres whose source code is available at the following link: https: / / github.com / pgvector / pgvector

[0292] the repository presents the up to date guide for the installation of the extension. At the time of writing this document, the steps for installingPgVector on PostgreSQL 16 are as follows:

[0293] Installing the dependencies for the build

[0294] sudo apt

[0295] install make sudo apt install build-essential

[0296] sudo apt install postgresql-server-dev-16

[0297] cd / tmp

[0298] git clone — branch v0.7.0 https: / / github.com / pgvector / pgvector.git

[0299] cd pgvector

[0300]

[0301] make make install # may need sudo

[0302] adding the extension to the Database

[0303] If necessary, let's switch back to the user postgres:

[0304] sudo -I -u postgres

[0305] psql

[0306] We connect to the previously created database:

[0307] \c <

[0308] database-name> creating the extension

[0309] CREATE extension extension vector;

[0310] networking

[0311] to allow the application to connect to the database, it is necessary to modify some postgresql configuration files.

[0312] Open the file postgresql.

[0313] conf nano / etc / postgresql / * / main / postgresql.conf

[0314] Edit the listen addresses:

[0315] # listen_addresses = 'localhost'

[0316] Remove the comment (#) and specify the IP address of the machine that needs access to the

[0317] listen_addresses database = '*' # * means40 / 44

[0318] Every address Client authentication is controlled by the Pg hba.conf file (https: / / www.postgresql.org / docs / current / auth-pg-hba-conf.html), authentication parameters must be specified for application authentication with the database. Adding this line to the configuration file such as

[0319] Host all all to the md5 host: Specifies that the accepted connection type is TCP / IP all (1asneeded): Indicates that the rule applies to all databases.

[0320] All (2a occurrence): Indicates that the rule applies to all users.

[0321] All (3a occurrence): Indicates that the rule applies to connections from anyIP address. MD5: Specifies that the authentication method to be used is MD5, which means that the password will be hashed using MD5.

[0322] In summary, this line allows any user to connect to any database from anyIP address using MD5 password authentication.

[0323] As a last step it is necessary to expose port 5432

[0324] sudo ufw allow 5432 / tcp

[0325] and to perform the restart of the database

[0326] sudo service postgresql restart

[0327]

[0328] managed services The use of a managed service such as for example the DigitalOcean managed databases allow to avoid this initial configuration and provide an already configured instance of postgresql to which it will be necessary only to install the extension PgVector following the guides of the specific service.

[0329] https: / / docs.digitalocean.com / products / databases / postgresql / details / suppo rted- extensions / chatbotOverview

[0330]

[0331] this backend implements a chatbot with memory functionality (chat history). It uses FastAPI for API endpoints and integrates with an Al model to generate responses.

[0332] Key components

[0333] chatbot: Manages the core functionality of the

[0334] EmbeddingModel chatbot: Calculates embeddings for the

[0335] RepositoryProvider input text: Manages data storage and retrieval

[0336] Endpoint API41 / 44

[0337] POST / API / chatbot / interact

[0338] this endpoint handles chatbot interactions, supporting both history-based and document-based conversations.

[0339] Request Body (EvaluateBody) text: User input text history: List of previous chat entries (optional)

[0340] database name: Name of database to search for relevant documentsnum documents: Number of documents to retrieve (1-3)

[0341] min score

[0342] : Minimum relevance score for documents (0.0-1.0) Response (EvaluateResponse) text: the response of the chatbot

[0343] history: updated chat history

[0344] support documents: list of relevant documents used for the response Chat

[0345] history functionality Chat history is managed by the function'history_interaction':

[0346] Chat history management

[0347] the function ' history_interaction' manages the conversations with memory:1. Takes the history of the existing chat from the request.2. Adds the user's new message to the history.3. Sends the entire conversation context to the Al model.4. Returns the Al response along with the updated history.

[0348] Signing the```pythonasync def _history_interaction( body: EvaluateBody, chatbot: ChatBot,) -> EvaluateResponse:42 / 44ConibhM ta. esssWKfe eon h BWC memggio ddhitente;"'pythwdid entries "■ [chat ^dry W ebat..enfty tn body hidwy] *• IChdfettty(f d e;~st,i ass' ”, cydentdiody ■ text tOwens risposia dal model lo Al''’pythonx xpc I'-.i. «>' t > h'nb’* ut re*-p« ' KSI ih r en nvdRotimsa hi rispom w hi csiMdogiap\ thenrc*un> U a^aseRe^ense(texts?:res|wnge?support jdoeumehts^ hisiwy-'diMVemries}

[0349] Error Handling

[0350] function If an error occurs during interaction with the Al, logs the error and raises an HTTP exception with a status code 500.

[0351] Use

[0352] this feature is called when the incoming request contains a chat history, allowing contextual conversations in which Al can refer to previous messages. This documentation provides an overview of how the chat history functionality is implemented in the backend, focusing on the 'hi story interact! on' function that manages the conversation memory. 2.6.- DESCRIPTION

[0353] of the DRAWINGS the first three steps of the method and the ways in which the system allows them to be realized are shown in TABLE 1.

[0354] In the right column the steps of the method are indicated:Step 1 - Data acquisition, Step 2 - Data normalization, Step 3 - Data processing, in the left column the system is illustrated in its components:a data input module (1) connected to a communication network (2) and configured to be supplied by a data acquisition module from the43 / 44Internet (1.1) or files and folders (1.2) or by third party systems via API dialog (1.3) or relational databases (1.4).a parsing module (3) which processes them through lexical analysis (3.1), syntactic analysis (3.2) and semantic analysis (3.3) in order to standardize the text contained in the starting data.•A chunking module (4) which divides the text into more easily manageable portions from the vector database (5) in which queries are performed in SQL language (5.1). the text is transformed into numerical vectors by the embedded embeddings module or linguistic engine which also creates a vector map (5.3) and subsequent indexing of the vectors (5.4), further providing for the generation of additional metadata (5.5) and the creation of relations and links between vectors (5.7).

[0355] This allows the unsupervised learning of the system (5.7) on which searches for similarity (5.8) and clustering (5.9) are based.

[0356] In TABLE 2 the fourth phase is represented as well as the modalities with the system allows it to be realized.

[0357] In the right column, step 4 - query (retrieval) of the method is deepened.The fourth step involves the generation of accurate and contextual responses, the processing of the information retrieved from the vector database and the generation of responses based on such data in which the built-in linguistic model reduces the risk of hallucinations, provides responses based exclusively on verified and acquired data. It consists of interface, understanding, accuracy and integration.

[0358] In the left column, the system is again depicted, as described in the first table, thus fed and configured, and how it is able to receive an input or query (6) of automatic type if integrated in third party (6.1) or manual (6.2) systems by means of a user interface. The input module sends a signal to the request comprehension module (7) which rests on a large language model LLM (7.1) to understand the exact sense of the request received in natural language. This module (7) sends the correctly interpreted request to the vector database (5) which, by means of the search for similarity(5.8) and clustering (5.9), interrogates the vector map (5.4) considering the44 / 44metadata (5.5) and the relations and links between vectors (5.6) to identify which vectors are most relevant (8) to produce one reply to the initial request (6). Suchrelevant data (8) are sent to the response generation module (9) which is also based on a large LLM (7.1) language model capable of producing textual output (10) which can be used by user interface (10.1) or which can supply third party integrated systems parts(10.2).

Claims

CLAIMS1. - The 'Method' is characterised by the following 4 phases: phase 1 - data acquisition, phase 2 - data normalisation, phase 3 - data processing, phase 4 - data retrieval.

2. - The 'Method', as per claim no.1, in its first phase uses the following steps: a)Connecting to specified websitesb) Navigating through web pages in an automated mannerc) Identifying and extracting relevant data from HTML pagesd) Managing different online data formats (text, tables, images)e) Respecting ethical crawling protocols, including robots.txt filesf) Temporarily storing extracted data for later processing.

3. - The 'Method', as per claim no.1, in its second phase for normalisation and standardisation of the acquired data uses an embedded language model that involves the conversion of heterogeneous data formats into a uniform and standardised format, including the information cleaning and restructuring phase, in order to create a coherent database ready for further processing through the embedded language model.

4. - The 'Method', as per claim no.1, in its second phase uses the following steps:a) Identification of data structures in different sourcesb) Definition of a unified standard format for all datac) Conversion of original data into the standardised formatd) Data cleaning to remove inconsistencies or errorse) Harmonisation of names and coding systemsf) Verification of consistency and quality of standardised data.

5. - The 'Method', as per claim no.1 and 4, in its second phase involves the division of data into smaller, more manageable portions;6. - The 'Method', as per claim no.5, in its second phase takes a large data set or document and breaks it down into segments, paragraphs, sentences or even individual words as required. The division facilitates syntactic and semantic analysis of the data, making further processing more efficient.

7. - The " Method", as per claims 5 and 6, includes the following steps in its subdivision and division of data:a) Analysis of the logical structure of contentsb) Identification of coherent and autonomous information unitsc) Division of texts into semantically relevant paragraphs, sentences or chunksd) Maintaining of the metadata associated with each portione) Assignment of unique identifiers to each segmentf) Preservation of logical links between created portions1. - The 'Method', as per claim no.1, includes the following steps in its third phase:a) Contextualisation of informationb) Understanding of the two-way context between each word and the othersc) Adding metadata to information on which to create embeddingsd) Native vector size reductione) Creating different weights with respect to non-context-relevant informationf) Participation in subsequent data retrieval phases.

2. - The 'Method', as per claim 1 and 8, envisages in its third phase the creation of embeddings that are more accurate than the known technique by means of an embedded linguistic model, comprising the processing phase of data acquired from internal and external sources, where the embedded linguistic model generates vector representations based on a bi-directional understanding of the semantic context, ensuring accurate indexing and retrieval of information in the vector database.

3. - The 'Method', as per claim no.1, 8 and 9, envisaged in its third phase, is characterised by training by means of an embedded language model for the semantic understanding of queries, which refines the abstract semantic representation of the previously pre-processed data in order to optimise the generation of embeddings. Thus, information is enriched, which in the next step is converted into vectors taking into account the context in which the information is located by evaluating the relationships via a neural network.

4. - The 'Method', as per claim 1, 9 and 10, in its third phase allows the model to understand the two- way context, i.e. how each word interacts with the others within the sentence. In detail:a) Contextualisation of informationb) Understanding of the two-way context between each word and the othersc) Adding metadata to information on which to create embeddingsd) Native vector size reductione) Creating different weights with respect to non-context-relevant informationf) Participation in subsequent data retrieval phases12. - The 'Method' as per claim 1 and 8, for integrating of the creation of embeddings and retrieval of information includes the step in which embeddings generated by the embedded language model are compared with those in the vector database during retrieval, thus improving the accuracy and relevance of the answers generated based on the query, again due to the embedded language model.

13. - The 'Method', as per claim no.1, in its fourth phase includes the following steps:a) Integration of a pre-trained and domain-optimised LLMb) Ability to interpret natural language queriesc) In-depth semantic analysis of user requestsd) Contextual search within the vector databasee) The generation of coherent and relevant responsesf) Dynamic adaptation to the specificities of the context.

14. - The 'Method', as per claim no.1 and 13, in its fourth phase involves the generation of accurate and contextual responses, the processing of information retrieved from the vector database and the generation of responses based on such data in which the embedded linguistic model reduces the risk of fabrications, provides responses based solely on verified and acquired data.

15. - The computerised system controls the relevant information to answer the questions, which comprises: a data input module (1) connected to a communication network (2) and configured to be fed by a data acquisition module from the Internet (1.1) or from files and folders (1.2) or from third-party systems via API dialogue (1.3) or from relational databases (1.4). The data received by the input module (1) is sent to the parsing module (3) which processes it through lexical analysis (3.1), syntactic analysis (3.2) and semantic analysis (3.3) in order to standardise the text contained in the source data. The parsing module (3) sends the processed text to a subsequent chunking module (4), which divides the text into portions that are more easily manageable by the vector database (5) where queries in SQL language (5.1) are executed and the text is transformed into numerical vectors by the embeddings module (5.2) or subsystem of the embedded language model (11), which also creates a vector map (5.3) with subsequent indexing of the vectors (5.4), also generating additional metadata (5.5) and creating relations and links between vectors (5.7). This allows unsupervised learning of the system (5.7) on which similarity searches (5.8) and clustering (5.9) are based. The system, thus powered and configured, is capable of receiving an input or query (6) either automatically when integrated into third-party systems (6.1) or manually (6.2) via a user interface. The input module sends a signalto the embedded language model (11) which processes it and sends it to the request comprehension module (7) which relies on a large LLM language model (7.1) to understand the exact meaning of the request received in natural language. This module (7) sends the correctly interpreted request to the vector database (5) which by means of similarity search (5.8) and clustering (5.9) queries the vector map (5.4) considering the metadata (5.5) and the relationships and links between vectors (5.6) to identify which vectors are most relevant (8) to produce a response to the initial request (6). This relevant data (8) is sent to the response generation module (9) which is also based on a large LLM language model (7.1) capable of producing a textual output (10) that can be accessed via a user interface (10.1) or that can feed into third party embedded systems (10.2).