Nohena Insights · Engineering
How RAG classification assigns an accurate HS code
Retrieval-augmented generation (RAG) is an AI method that assigns an HS code by finding relevant rules from a specific knowledge base, like the customs tariff, and then reasoning over those rules to propose a defensible classification.
Nohena · 14 October 2026 · 9 min read

What is RAG classification for HS codes?
Retrieval-augmented generation, or RAG, is an artificial intelligence method that assigns an HS code by first finding relevant rules from a specific knowledge base, like the customs tariff, and then using a language model to reason over those rules to propose a classification and its justification. This approach combines the contextual understanding of modern AI with the factual accuracy of a curated, authoritative document set, making it a powerful tool for preparing defensible customs declarations.
For any licensed agent or importer in Nigeria, the Harmonized System (HS) code is the single most important data point on a Single Goods Declaration (SGD). It determines the customs duty rate, which can range from 0% to 35% under the ECOWAS Common External Tariff (CET), and dictates whether other government agency interventions, such as from SONCAP or NAFDAC, are required. An incorrect HS code can lead to Pre-Arrival Assessment Report (PAAR) queries, valuation uplifts, delays, and significant financial penalties. The challenge lies in consistently and accurately mapping a commercial product description to the correct 10-digit Nigerian HS code. This is where RAG classification presents a significant step forward from older methods.
Why traditional classification methods fall short
Traditional methods for HS classification often fail because they cannot adequately process the nuance and context of real-world product descriptions. These systems, typically based on simple keyword searches or rigid rule-based logic, are brittle and prone to error when faced with ambiguity or novelty.
Keyword ambiguity. A simple search for a term like 'monitor' could return HS codes for computer screens, industrial process monitors, or medical vital-signs monitors. Without understanding the context provided in the rest of the invoice description, a keyword-based system cannot reliably distinguish between these vastly different products, which fall under entirely different tariff chapters and duty rates.
Lack of contextual understanding. Product descriptions on a commercial invoice or Form M are often complex. A description like 'replacement filtration unit for a reverse osmosis water purifier' contains multiple concepts. A legacy system might incorrectly classify it based on 'replacement part' generically, attracting an incorrect duty rate. It fails to apply General Interpretative Rule 2(a), which often requires that a part be classified with the machine it is intended for. An advanced system needs to understand the relationship between the part and the primary machine.
Inability to handle new products. The HS tariff is updated periodically, but new technologies and products emerge constantly. When a product is not explicitly named in the tariff schedule, classification must be done by analogy, material composition, or primary function, following the General Interpretative Rules (GIRs). Keyword-based systems cannot perform this type of analogical reasoning. They can only find what is explicitly written, leaving the agent to perform complex manual research for any novel item.
Static and fragmented knowledge. An agent's knowledge is a combination of the official tariff, explanatory notes, past experiences, and institutional memory. Traditional software cannot integrate these disparate sources. It might search the tariff but ignore the critical context provided in the World Customs Organization (WCO) Explanatory Notes or a past Nigeria Customs Service (NCS) circular on a contentious item.
How RAG classification improves HS code accuracy
RAG classification improves accuracy by using a two-step process that mimics an expert's research methodology, allowing it to understand context, cite evidence, and handle novel products. It moves beyond simple keyword matching to a more sophisticated form of semantic understanding and logical reasoning.
The RAG process: retrieval and generation
The method's name describes its function. It is a sequence of two distinct steps designed to produce a reliable and verifiable answer.
Retrieval. When presented with a product description, the system first retrieves a small, relevant set of documents from a specialized, trusted knowledge base. This base is not the open internet; it is a curated library containing specific, authoritative sources like the full 10-digit ECOWAS CET for Nigeria, the WCO Explanatory Notes, the GIRs, and potentially historical, anonymized NCS rulings. This step ensures the final answer is grounded in the correct legal and regulatory texts.
Generation. The retrieved documents and the original product description are then passed to a large language model (LLM). The LLM's task is not to answer from its general knowledge, but to synthesize the information from *only the provided documents* to generate a precise answer. For HS classification, this answer includes the recommended 10-digit code and, critically, a detailed rationale explaining *why* that code is appropriate, citing the specific tariff headings, notes, or rules it used from the retrieved documents.
Key advantages for customs declarations
This retrieval-then-generation workflow provides tangible benefits for preparing compliant declarations.
Evidence-based justification. The most significant advantage is the generation of a defensible rationale. The system does not just suggest a code; it builds a case for it, referencing specific section notes, chapter notes, or heading texts. This audit trail is invaluable for internal compliance, training junior staff, and, most importantly, for responding effectively if the NCS issues a PAAR query on the classification.
Deep contextual analysis. Unlike keyword searches, the language model can parse complex grammatical structures and understand the relationships between words in a product description. It can determine the primary function of a multi-purpose machine or identify the essential character of a composite good, aligning its logic with the principles of the GIRs.
Adaptability to novelty. By reasoning from the foundational principles within the GIRs and Explanatory Notes, a RAG system can propose a logical classification for a new product that is not explicitly mentioned in the tariff. It can perform classification by analogy or material composition in a structured, repeatable way, significantly reducing the time required for manual research.
For more analysis on customs compliance and technology, you can explore further articles on our insights page .
Comparing classification approaches
A decision support tool's value is determined by its ability to deliver accurate, defensible recommendations. The architectural differences between older keyword-based systems and a modern RAG-based approach have direct consequences for the quality of the output an agent receives.
RAG as decision support for the licensed agent
A RAG classification system serves as a powerful decision support tool that augments, rather than replaces, the expertise of the licensed customs agent. Its purpose is to enhance the agent's ability to make informed, compliant decisions by providing foresight into how a declaration will likely be interpreted by customs risk management systems. The final authority and legal responsibility for the declaration always rest with the agent.
When preparing a declaration, the agent uses the system to analyze the commercial invoice and packing list. The system recommends an HS code, along with a complete justification referencing the CET and other core texts. The agent, applying their professional judgment and specific knowledge of the goods, reviews the recommendation. They can scrutinize the evidence, consider alternative interpretations, and make the final determination.
This workflow respects the lodgement boundary. A platform like Nohena prepares a lodgement-ready declaration and document pack based on these evidence-backed recommendations; the licensed agent is the one who reviews, finalizes, and lodges the declaration with the Nigeria Customs Service through the official trade portal. The tool provides a preview of potential risks and a strong rationale for the chosen code, equipping the agent to navigate the complexities of the PAAR and clearance process with greater confidence. It transforms the classification process from a manual, time-consuming search into a strategic review of an evidence-based proposal.
FAQ
What is the difference between a standard chatbot and a RAG classification system?
A standard chatbot or large language model answers questions based on a vast, general set of data from the public internet, which can be outdated or incorrect. A RAG system for customs classification is different; it is restricted to answering questions using only a specific, curated, and trusted knowledge base containing the official customs tariff, explanatory notes, and other regulatory texts, ensuring its proposals are factually grounded and verifiable.
Can RAG guarantee a 100% correct HS code?
No system can guarantee a 100% correct HS code in every scenario, as classification can sometimes be subjective and subject to interpretation or customs authority discretion. RAG classification provides a highly accurate, evidence-backed recommendation for the licensed agent to review. Its primary value is in presenting a defensible and well-reasoned case for a specific code, which greatly increases the probability of compliance and acceptance by customs.
Does using AI for HS codes replace the need for a licensed agent?
No, it does not. AI systems for HS classification are decision support tools designed to augment the expertise of a licensed customs agent. The agent's professional judgment, experience, and legal responsibility are irreplaceable. The tool automates the time-consuming research and analysis, but the agent remains the final decision-maker and the party legally responsible for the declaration lodged with customs.
How does RAG handle the 10-digit Nigerian HS code structure?