Blog
This is some text inside of a div block.

Real-time data embedding and indexing for RAG with Neum and Supabase

Kevin Cohen
November 25, 2023
8
min read

Intro

Over the past months, we at Neum AI, have been working on a Retrieval Augmented Generation platform to help developers bring up-to-date context into AI applications. Recently we open sourced our framework (https://github.com/NeumTry/NeumAI) and released our first python sdk.

Retrieval Augmented Generation, or RAG, helps finding data quickly by performing search in a “natural way” and use that information/knowledge to power a more accurate AI application that needs such information! It is a recent methodology employed by lots of people when building accurate and up-to-date AI applications!

In this blog post we will dive deep on how Neum offers integration with Supabase for both Postgres and Storage connectors, as well as real-time synchronization of vector embeddings to power your RAG pipelines and AI applications.

Supabase storage

Supabase Storage is one of the connectors that Neum offers out of the box. By simply specifying the connection configuration, we can create a pipeline that will read data from Supabase Storage, embed it with OpenAI embeddings and finally store it in a vector database, in this case we will showcase the integration with Supabase  as our sink (a Postgres table leveraging pgvector). More details in our docs


from neumai.Pipelines import Pipeline
from neumai.Sources.SourceConnector import SourceConnector
from neumai.DataConnectors import SupabaseStorageConnector
from neumai.EmbedConnectors import OpenAIEmbed
from neumai.SinkConnectors import SupabaseSink

supabase_storage_connector = SupabaseStorageConnector(url="",key="")
source = SourceConnector(data_connector=supabase_storage_connector)
sources = [source]
embed = OpenAIEmbed(api_key="")
sink = SupabaseSink(database_connection="", collection_name="")
pipeline = Pipeline(sources=sources, embed=embed, sink=sink)
pipeline.run()
search_results = pipeline.search(query="")

Make sure to substitute the empty strings for your configurations!

When running this locally you will be able to check data that was stored in Supabase Storage (blob) and search it semantically.

If you want to deploy this pipeline after you’ve tested it just simply run:


from neumai.Client.NeumClient import NeumClient
client = NeumClient(api_key="")
client.create_pipeline(pipeline=pipeline)

This will deploy the pipeline to our cloud and you will be able to log in to https://dashboard.neum.ai and take a look at the status and search!

Supabase postgres

In addition to connecting to Supabase Storage, you can also connect to a hosted Postgres table (in this case we will leverage one we have in Supabase) and create a Pipeline configuration similar to the one we had above.

Because this scenario involves structured data most likely, you can also specify the types of columns that are particular useful to embed and those that are important to store as metadata as part of the vectors.


from neumai.Shared.Selector import Selector
column_postgres_selector = Selector(to_embed=['column1, column2'], to_metadata=['column3'])
postgres_connector = PostgresConnector(connection_string='', query='Select * from table', selector=column_postgres_selector)
source = postgres_connector(data_connector=postgres_connector)

# ... rest of code shown in previous snippet

Similar to above, you can run and search the pipeline either locally or deploy it to our cloud offering.

All of this is great, and the framework is easy-to-use for everyone to jump right in and try it. But, as you move into production-like applications, chances are that you will need to embed and index real-time data. Supabase allows you to listen for events of a particular table and with Neum you can enable real-time in your pipeline seamlessly! Without this, you would need to re embed and rerun pipelines every time new data is added to a table.

Real-time support

Real-time vector synchronization is essential to have up-to-date context in your AI applications. With Supabase’s Real-time Postgres events, you can listen to insertions, deletions and updates in a given table. Having this data constantly flowing, being vectorized, and stored in your vector database is crucial to ensure effective Retrieval Augmented Generation as it is a great guarantee that recent data will be available to the prompt at all times.

💡 Real-time support is only available through our cloud offering, and so for this, we will show how to enable it for a Postgres table hosted via Supabase.

Enabling real-time vector syncing with Postgres on Supabase is as easy as three steps

  1. Enable your desired table in Supabase for real-time support (link)
  2. Create a Neum pipeline (either through SDK or Dashboard) - Serves also as a way to validate connections and make sure you can see some data flowing first
  3. Enable Realtime in Neum dashboard - This will tell Neum to listen for events coming from Supabase for the desired table and have new data embedded and stored in your vector database chosen in #2
Enabling realtime support for pipeline in Neum Dashboard

Conclusion

As we can see, the process of loading, vectorizing and indexing data for Retrieval Augmented Generation is trivial to do with Neum. Integrations with Supabase Storage and Postgres on Supabase make a delightful experience for anyone building production-grade applications that depend on real-time events.

At Neum, we focus on ensuring your data is always indexed and in the correct way to let you focus on your end user’s needs!

As always, reach out to founders@tryneum.com if interested in chatting more about this topic or if you’d like to give this a try!

Take a look at our other blog posts here

Check out our latest post

Follows us on social for additional content

Configuring RAG pipelines requires iteration across different parameters ranging from pre-processing loaders and chunkers, to the actual embedding model being used. To assist in testing different configurations, Neum AI provides several tools to test, evaluate and compare pipelines.
David de Matheu
December 6, 2023
10
min read
Real-time synchronization of embeddings into vector databases is now trivial! Learn how to create a real-time Retrieval Augmented Generation pipeline with Neum and Supabase.
Kevin Cohen
November 25, 2023
8
min read
Following the release of Neum AI framework, an open-source project to build large scale RAG pipelines, we explore how to get started building with the framework in a multi-part series.
David de Matheu
November 22, 2023
15
min read

Ready to start scaling your RAG solution?

We are here to help. Get started today with our SDK and Cloud offerings.