How Can We Create Custom Field Types in Payload? #10376
-
Hi there! I am using a postgres adapter to use supabase as DB, and i am working on a RAG system. Which means that i want to store fields of type vector and tsvector into supabase postgres DB. I can't figure out how to accomplish that since it isn't clear how to declare custom field types. For instance,
In this case, in order to store embeddings in the database articles table, the field type in the payload Article.ts collection file AND the column type in the DB table NEED to match. However as we all know there is a limited selection of types native to payloads framework: array So here I ask: Does anyone know how to declare custom field types? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @flowingkhaos what you're working on sounds very interesting! @r1tsuu has your answer from this other discussion: #8544 (comment) You should be able to iterate from that and make the custom db type that way. |
Beta Was this translation helpful? Give feedback.
-
My situation was very specific, but not necessarily uncommon. I am using supabase through the postgres adapter. I wanted to create collections with an ' embeddings ' field, so that I can perform RAG on these tables using my own technology. In that specific instance, supabase expects ' vector ' and ' tsvector ' column types for search functions to work as intended. These types aren't supported in payload. No matter how i flipped it, I wasn't able to create a type match, between the backend and supabase(postgres) for embeddings. If your field typing issue in payload, is related to storing vectors(embeddings) in collections, here is my solution.Supabase gives you two project slots by default. Therefore, I encourage AI developers/engineers, that want to use payload as a cms to create content, generate embeddings for it and store it, to do as follows:
It is not as messy and complicated as it sounds.. The concept is to use two parallel tables that each reside in different supabase projects, to avoid conflict. One for storing cms entries, and one for storing copies with their embeddings. We use payload's hooks to generate an embedding and store the entry in the parallel table every time an entry is created, updated or duplicated. The parallel table will always be in the second supabse project, the one that has copies of your entries with embeddings. don't forget to use a field that is unique, in order to avoid duplicate content in the tables that contains embeddings, since embedding costs money. Slug is commonly used for that purpose. It is far from the most efficient solution, but it fixes the problem, while keeping your structure scalable and somewhat flexible. Hope that was insightful.. |
Beta Was this translation helpful? Give feedback.
My situation was very specific, but not necessarily uncommon. I am using supabase through the postgres adapter. I wanted to create collections with an ' embeddings ' field, so that I can perform RAG on these tables using my own technology.
In that specific instance, supabase expects ' vector ' and ' tsvector ' column types for search functions to work as intended. These types aren't supported in payload. No matter how i flipped it, I wasn't able to create a type match, between the backend and supabase(postgres) for embeddings.
If your field typing issue in payload, is related to storing vectors(embeddings) in collections, here is my solution.
Supabase gives you two project slots by defaul…