4D Blog

Home Tips AI Brings Magical Search to 4D Write Pro Documents

AI Brings Magical Search to 4D Write Pro Documents

August 13, 2025

Tips

In many 4D business applications, documents are everything — technical notes, reports, manuals, internal guides. But when users can’t remember the exact wording, finding the right one becomes slow, frustrating, or worse — impossible.

With 4D 20 R10, semantic search powered by AI vectors changes that. Instead of matching keywords, you match meaning. Users get the right document, even if they search in different words or a different language. It’s a smarter way to surface the knowledge hidden in your documents — fast, accurate, and built for how people actually search.

Let’s consider a concrete example: a user wants to locate a technical note that explains how to insert an image into a 4D Write Pro document. However, they may not recall the precise phrase used in the document.

HDI_4DWP_AI_Vector

How to search in 4D Write Pro documents

Searching through documents stored in a database is not a new concept. Traditionally, 4D developers have relied on keyword-based search to implement this functionality. Today, however, artificial intelligence opens the door to a far more flexible and powerful approach: semantic search using vectors.

Let’s take a closer look at both techniques and see how vectors revolutionize the way we search.

Traditional search methods with Keywords

This method involves extracting a document’s keywords and storing them in a text field. A search query is then performed by matching specific keywords entered by the user.

This approach is fast and effective when the query matches the document’s wording exactly. If the wording changes even slightly, the search fails. For example, a search for “insert image” would not find documents containing “add picture”.

Semantic Search with AI Vectors

Starting with 4D 20 R10, a powerful new feature is available: AI vector support. This enables semantic search, powered by artificial intelligence.

Unlike keyword search, semantic search focuses on meaning, not exact words. It allows users to find documents that express the same idea in different ways. For example, phrases like “insert image” or “add picture” convey the same idea.

Users can even enter queries in a language different from the document content. Meaning is preserved and matched — something keyword indexing cannot do.

How It Works

  1. Each document is analyzed and converted into a vector using the 4D AIKit component. This vector represents the semantic meaning of the text.
  2. A user query is also converted into a vector.
  3. The similarity between the query vector and the document vectors is calculated.
  4. The documents are returned, sorted from most to least relevant.

Implementation Example

A demo database was created to showcase this feature. It contains several 4D Write Pro documents representing technical notes.

Step 1 – Generate vectors for each document

Vector generation can be triggered when a document is saved to the database. In our example, a method was created to generate all vectors at once:

var $document : cs.NoteEntity
var $documents:=ds.Note.all()
For each ($document; $documents)
  $txt:=WP Get text($document.Document)
  $document.Vector:=cs.AIManagement.new($apiKey).generateVector($txt)
  $document.save()
End for each

Step 2 – Generate the vector from the user’s query

When the user clicks on a search button, we create a vector from the user’s prompt

var $vector:=cs.AIManagement.new($apiKey).generateVector($prompt)

Step 3 – Compare vectors and sort by similarity

Finally, we return a list of documents, sorted by semantic relevance to the user’s query.

var $formula:=Formula(This.Vector.cosineSimilarity($vector)
$documents:=ds.Note.all().orderByFormula($formula); dk descending)

In this example, we return all documents ranked from most to least relevant. You can also limit the results presented to the user — for example, to the top five.

Live action

Conclusion

Semantic search with AI vectors marks a major evolution in how users interact with document-based data in 4D. It provides more flexibility, better accuracy, and a more intuitive user experience — without relying on strict keyword matching.

Whether for internal notes, documentation, or knowledge bases, vector search unlocks a new level of intelligence in your 4D applications.

An upcoming 4D version (not too far away) will introduce a special vector index type for fast analysis of large datasets.

And you? Has this blog sparked ideas for your own projects? What types of documents could benefit from semantic search in your applications?

Discuss

Tags 20 R10, 21, 4D AIKit, 4D Write Pro, AI, Artificial Intelligence, OpenAI, Vector Search, Vectors, Word processor

Latest related posts

  • September 15, 2025

    Find the right spot in your 4D Write Pro document with AI

  • September 2, 2025

    Intelligent 4D Write Pro document analysis with AI

  • August 25, 2025

    ORDA – Constructor and touched event – Detailed behaviour through a network

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy