1. Fundamentals: Vectors & Embeddings
What is a Vector?
In the context of computer science and data, a vector is simply an ordered list of numbers (e.g., [1.2, -0.5, 0.8]). In mathematics/physics, it represents magnitude and direction, but in AI, it is primarily a way to represent features or coordinates in a multi-dimensional space.
What are Embeddings?
An Embedding is a specific type of vector used to represent "real world" objects (text, images, users, products) in a form that machines can understand.
- Transformation: AI models (like GPT) take complex data (e.g., the word "Apple") and transform it into a long list of numbers (e.g., a 1536-dimensional vector).
- Semantic Meaning: Crucially, this transformation preserves meaning.
- The vector for "Apple" will be numerically closer to "Banana" (both fruits) than to "Car" (vehicle).
- The vector for "King" minus "Man" plus "Woman" results in a vector very close to "Queen".
Importance for AI
Embeddings are the foundation of modern "Semantic Search" and RAG (Retrieval Augmented Generation).
- Traditional Search: Matches keywords (
WHERE name ILIKE '%apple%'). Fails if user searches for "Fruit". - Vector Search: Matches meaning (
ORDER BY embedding <-> query_embedding). Successfully finds "Apple" when searching for "Fruit" because their vectors are close in the multi-dimensional space. - Memory: They allow AI agents to "remember" vast amounts of data by retrieving only the most relevant snippets (context) based on the semantic similarity to the user's current question.
2. OCA Module: field_vector
Purpose
The field_vector module (part of OCA/server-tools) introduces a native Vector Field type to the Odoo framework. It was originally introduced for Odoo 16.0 by Laurent Mignon (Acsone) via PR #3251.
- Native Integration: It allows developers to define
vectorfields on Odoo models just likeCharorIntegerfields. - pgvector Backup: It leverages the pgvector PostgreSQL extension to store these vectors efficiently.
- No External DB: It eliminates the need for a separate Vector Database (like Pinecone).
Note on Odoo 19.0
We worked on the migration of that module to odoo 19.0, see PR #3430.