↵select↑↓navigateescclose
Search Avunu EDI addons

LlamaIndex Document Import

On this page

Turns each document sent to one email address into a draft Odoo record. LlamaCloud classifies the document against a list of rules, extracts the fields of the model the matching rule names, and the module matches what was extracted to existing records before it creates the draft. A clean draft can be confirmed straight away.

It is the Odoo port of the Frappe appAvunu/llamaindex_integration, and keeps its pipeline, its matching rules and its safeguards.

Why

The pattern-template modules of this repository need one hand-written template per vendor document, and a template breaks whenever a vendor changes its layout. Here a rule only describes the kind of document in plain words and names the model it becomes. The extraction schema is built from the model's fields.

How a document is imported

  1. Intake. Three ways in:

    • Email. Mail to the import address (Settings > Document Import, defaultdocuments@<alias domain>) creates a document for each attachment whose extension is allowed. An email with no such attachment has its body printed to PDF, and that PDF is the document. Small images, and images the email body shows inline, are ignored.

    • Upload. The Upload button on the document list.

    • Printer. A user in the Upload group (and no other Document Import group) creates an ir.attachment with res_model llamaindex.document and res_id 0. The Upload button does the same. The same bytes uploaded again within a day are the printer's outbox retrying, and are Ignored.

    For a forwarded email, the vendor is matched, not the shop: a forwarding rule (such as Gmail's) keeps the vendor in From. A person who forwards by hand becomes the From, so the sender quoted in the forwarded header block is used instead (Original Sender). A colleague's own address is never matched. Reply Addresses keeps the shop's mailbox that received or forwarded the email, for modules that answer it.

  2. Classify. The file is uploaded to LlamaCloud once and classified against the description of every active rule. A result under the minimum confidence, or no result, stops at Needs Review.

  3. Extract. A JSON Schema is built from the rule's model: the fields listed on the rule, or every required field without a default. A one2many is extracted with its line fields. Match keys (identifier fields of the linked models) are added, so the resolver can read them.

  4. Resolve. Each many2one value is matched in this order: the exact name (ignoring case), the identifier fields, the linked model's own _llamaindex_find() lookup, the partner of the sender's email, a fuzzy match on the name, then auto-create. Each step after the exact name, and each value nothing matched, is noted for review.

  5. Create. Under a lock per file and per model: the same file must not have created a record already, the rule's duplicate key must not match an existing record, and the extracted total must match the computed one. Any of these goes to Needs Review, with nothing created. Otherwise the draft is created as the import user, and the source file is attached to it.

  6. Confirm. When the rule names a confirm method (such as button_confirm) and nothing was noted for review, it runs. A confirm that fails leaves the draft for review.

Every LlamaCloud step is paid, so each one is committed as soon as it is done, and the id of a running LlamaCloud job is stored before it is waited for. A retry reads the job it already paid for instead of starting another. While LlamaCloud works, the queue job is postponed and runs again a few seconds later; no worker waits.

Configuration

  • Settings > Document Import: turn the import on, the import address, the LlamaCloud API key, the import user (records are matched and created with its access rights and companies), the allowed extensions, the minimum classification confidence and the fuzzy match threshold.

  • Document Import > Configuration > Rules: one rule per kind of document: a code (what LlamaCloud classifies into), a description, the target model, the fields to extract, the duplicate key, the reconciliation total, default values, the confirm method and the extraction tier. The target model must have a draft state.

  • Document Import > Configuration > Entity Matches: one per linked model, for matching beyond the exact name: a domain (such as companies only, since Odoo copies a company's Tax ID onto its contacts), identifier fields, the sender's partner, fuzzy matching and auto-create.

For developers

  • _llamaindex_find(value, source) on any model: return the records an extracted value names, for example by a vendor's product code. source holds every value extracted at the same level. The default finds nothing.

  • The job is llamaindex.document._llamaindex_process(attempt) on the queue channelroot.llamaindex. Its job function allows commits.

  • The LlamaCloud client, the extraction schema rules, the entity resolver, the pipeline's stages and the helpers that need no database come fromllamaindex-edi, which the Frappe app shares. services/schema_builder.py, services/entity_resolver.py andservices/tasks.py pass it this addon's backends, and services/meta.py describes Odoo fields with Frappe's fieldtypes for it. The creator is still ported from the Frappe app, with its function names; tools/check_frappe_parity.py reports how much of it is the same code.

Dependencies

  • mail, and queue_job from OCA/queue.

  • Python: llamaindex-edi, which bringsllama-cloud 2.x andrapidfuzz. It is installed from a release tag (nix/pyproject.toml) until it is on PyPI.

  • Outbound HTTPS to api.cloud.llamaindex.ai.