Decoding Vector Search and Embeddings for React Developers

Rate this content
Bookmark

In this talk we'll break down key Generative AI concepts like Vector Search and Vector Embeddings and how can React Developers leverage them with technologies like LangChainJS to build intuitive AI powered apps. We will discuss different AI enabled search experiences like vector and hybrid search approaches, exploring how each method works, their advantages and disadvantages, and practical use cases.

The talk will break down what can be overly complex concepts into practical takeaways for our everyday work as React/JavaScript developers. By the end of the session you'll have a better understanding of when and how to use different search techniques to optimize your user experience. Most importantly you will also learn how as a React developer we use can use these search techniques using open source tooling and libraries including some powerful search engines written in TS/JS and create AI powered applications in React. 

This talk has been presented at React Day Berlin 2024, check out the latest edition of this React Conference.

FAQ

Couchbase is a NoSQL database platform that empowers developers with AI capabilities, including support for vector search.

Vector search is a method that uses vectors to find semantically related meanings in data, improving search accuracy. It's important for React developers as it enables more powerful search experiences in applications.

Traditional search methods rely on exact keyword matching, whereas vector search finds semantically related data by converting text into vectors and comparing their similarities.

Vectors are lists of numbers representing words, phrases, or images, conveying their meaning. Embeddings are low-dimensional numerical representations of these vectors, making it easier to search and organize data.

React developers can use APIs and tools like Langchain and Vercel's AI SDK to integrate vector search capabilities into their applications, improving search accuracy without designing complex algorithms.

Semantic search finds meanings in queries rather than exact keyword matches, similar to vector search. It enhances user experience by providing relevant results based on context.

Tools like Langchain, Vercel's AI SDK, and various vector databases can help React developers integrate vector search capabilities into their applications.

Vector search improves user experience by providing more accurate search results based on the semantic meaning of user queries, reducing the chances of users not finding what they're looking for.

Common distance measures in vector search include Euclidean distance, cosine similarity, and Manhattan distance, which evaluate how close vectors are to each other.

RAG combines vector search with generative AI to find relevant data and generate coherent text, improving the accuracy and relevance of AI-generated responses.

Shivay Lamba
Shivay Lamba
28 min
16 Dec, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Welcome to my talk at React Day Berlin. Today, we'll discuss vector search and embeddings for React developers. Traditional search is broken, resulting in poor user experiences. Converting data into embeddings unlocks more accurate search, content recommendations, and document comparisons. Vector search measures the closeness or similarity of vectors using distances. In vector search, the closest relevant documents are found based on similarities between vectors. There are multiple ways to calculate the distance between data in vector search. Generative AI applications often deal with both textual and image data, making vector search useful. By converting queries and data into vectors, semantic meaning is considered, allowing for more accurate results. React and Next.js developers have access to a range of toolings, including BlankChain and AI SDK from Vercel. Retrieval augmented generation enhances search results by converting data into vectors and generating more coherent text. The user query is converted into a vector and matched using vector search, and the response is generated using the AISDK from Vercel.

1. Introduction to Vector Search and Embeddings

Short description:

Welcome to my talk at React Day Berlin. Today, we'll discuss vector search and embeddings for React developers. Traditional search is broken, resulting in poor user experiences. We'll explore vectors, embeddings, and how they apply to React development. Vectors are lists of numbers that represent text and embeddings organize text for efficient searching.

Hello, everyone. Welcome to my talk at React Day Berlin. I'm Shabal Amba. I work as a developer evangelist at Couchbase, which is a NoSQL database platform empowering developers, including a lot of AI capabilities that are being taken with support for vector search.

So today's session is going to be around decoding vector search and embeddings for React developers. Now imagine that you are like Joey from Friends and sitting on a really nice looking couch. Of course, all of us love couch and having a good chair, right? So of course, if you're a software developer, you would probably love your work chair or if you're just enjoying looking at a movie and enjoying rocking behind with a really nice chair. So of course, all of us love that. And if you use it too much, sometimes you might see that your chair just breaks. So of course, the next step would be that you might want to look up for that particular type of chair that you really love. So you might have a search query on an e-commerce platform where you search for I'm looking for an old chair, which is very comfortable. It has kind of a brown color because you can't really remember the exact brand of that particular chair that you're looking for, because it's so old.

And of course, what would happen if you were to give such a descriptive description of the chair when you move ahead and try to search with this right type kind of description on a different kind of e-commerce platforms? Let's see what actually happens. So do you think Joey will be able to actually find that same chair that he's actually looking for? Well, according to a lot of surveys, 88% of the users won't be able to actually find what they're actually looking for, and they don't return to a website after such kind of a bad experience where they don't look or where they are not able to find what they're looking for. And 61% of the users say that they are not able to actually find what they're looking for within five seconds. And if that happens, they will actually go to the next site for finding out the results.

So of course, if I put in that same description inside of an e-commerce platform, then what would happen? Then if you go ahead and search for that particular type of chair, we probably won't be able to find the same thing that we're looking for. We find a bunch of other random chairs that do not match the description that we are trying to search for. So what does that mean about search experiences? We saw that we didn't find any brown chairs, no earthy brown chairs, no manual recliners or automatic recliners. But at least these were chairs, but they still didn't meet our description that we wanted to find. So that is why the traditional search is actually broken.

So what we're going to be talking about today, we're going to be talking about what is a vector, what are embeddings, what are vector search, and then how does it actually apply for us React or Next.js developers? So we saw that, of course, the traditional search, which is typically based on the full text search, where whatever user query is being sent, we try to match the exact search query and we try to find results in our database that match the exact word to word or text by letter or letter by letter based on the search query that you have sent. So if you have a very vague description like I'm looking for a really nice looking brown chair that is reclining, if that same text is not existing in your database, then you'll not be able to actually find results for that. So let's find how we can overcome that particular issue. So first, let's understand that what exactly is a vector. So again, a warning that if you are a React developer or a JavaScript developer, this will involve a lot of numbers. Well, a vector is a list of numbers that can represent words, phrases, images, and a lot more. And over here, each number in this particular list will basically have some information about the meaning of that particular text that you are showing to it. And an embedding or a vector embedding basically turns these words or sentences into these low dimensional lists of numbers. And these embeddings are very compact and they help making tasks like searching and organizing these texts very easy.

2. Working with Embeddings for Vector Search

Short description:

Converting data into embeddings unlocks more accurate search, content recommendations, and document comparisons. Embedding models are specialized AI models that convert text into numerical arrays using neural networks. Vector search measures the closeness or similarity of vectors using distances. Closer vectors indicate similar real-world features. For example, a query like 'I'm looking for my old chair with its leg part went up' can be used for vector search.

So for example, if you have this entire description that we were trying to search within our search box, when we convert this into the embedding using an embedding API, it will get converted into this vector. So as you can see that it basically represents this entire embedding model. And here you have an array of these embeddings. So these values, they represent the real world features of your data. You're just converting your real world features of the data into these numerical values with the help of an AI model called as embedding model, where you can see that the embedding model in this case is the TextEmbedding3 model, which converts your input data into these embeddings that represents the real world features or the real world dimensions of your data. And the reason why we convert this into this numerical format or this embedding format, we'll come to that later.

And over here, this TextEmbedding model is from OpenAI. So your data application basically transforms all the way from all of this data, like the textual data that you see right now, into a large array of the dimensions of the vector representations, which unlocks. So by converting your data from text into these embeddings, it basically unlocks more accurate search, content recommendations, and then being able to also do document comparisons. So the question is that, is this really magic? So let's first also discuss about embedding models. So embedding models on a high level will convert your text into these numerical arrays. And this basically happens with the help of these specialized AI models, which really just are neural networks. So in the landscape of machine learning, deep learning, these are neural networks, which basically take the data from the words to understand what's there in that word. And then it will convert it into this numerical value. And of course, these models are traditionally trained over a lot of vast data to properly understand what does that data actually represent, so that it can then convert into this numerical form and have the relevant context of what the features of that particular data are. Similarly, of course, these days, a lot of the different AI models, like the GPT models, are what are being used under the large language models, which are generative models, which allow you to generate data and generate human-like responses, whether it's text generation or summarization. So of course, those are different categories of models, which are used for LLMs. But the embedding models is what is able to basically convert your data into the numerical format.

So now let's understand that how does vector search actually work? So we've discussed about what are vectors? What are these embeddings that are generating these vectors from our input data? And of course, these vectors are also multi-model, which means that you have text-based embeddings, but then you can also have image or even a combination of both images and text. So once you convert these into the embeddings, what does it actually mean? Why are we even converting them into the embeddings? So that's where the vector search actually comes into picture. So first, let's talk about closeness and understand what does that closeness actually mean. So closeness within vector search basically means that how close two vectors are or how similar they are, which is typically measured with the help of a distance, which represents the value of how far apart these vectors are. So basically, in a nutshell, if the two vectors are smaller in their distance, like if they are closer to each other, that means they will have more similarity. And what does that mean in real world? So first, these vectors are representing the real-world features of something. So if the vectors are closer to each other, that means the real-world features of two things are matching more than if they are further apart. So that means that two things which are similar in their features will actually represent, their vectors will be closer with each other. That means the distance between them will be smaller in size. So here is an example. Let's say that we have the query. I'm looking for my old chair with its leg part went up.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building a Voice-Enabled AI Assistant With Javascript
JSNation 2023JSNation 2023
21 min
Building a Voice-Enabled AI Assistant With Javascript
Top Content
This Talk discusses building a voice-activated AI assistant using web APIs and JavaScript. It covers using the Web Speech API for speech recognition and the speech synthesis API for text to speech. The speaker demonstrates how to communicate with the Open AI API and handle the response. The Talk also explores enabling speech recognition and addressing the user. The speaker concludes by mentioning the possibility of creating a product out of the project and using Tauri for native desktop-like experiences.
AI and Web Development: Hype or Reality
JSNation 2023JSNation 2023
24 min
AI and Web Development: Hype or Reality
Top Content
This talk explores the use of AI in web development, including tools like GitHub Copilot and Fig for CLI commands. AI can generate boilerplate code, provide context-aware solutions, and generate dummy data. It can also assist with CSS selectors and regexes, and be integrated into applications. AI is used to enhance the podcast experience by transcribing episodes and providing JSON data. The talk also discusses formatting AI output, crafting requests, and analyzing embeddings for similarity.
The Rise of the AI Engineer
React Summit US 2023React Summit US 2023
30 min
The Rise of the AI Engineer
Watch video: The Rise of the AI Engineer
The rise of AI engineers is driven by the demand for AI and the emergence of ML research and engineering organizations. Start-ups are leveraging AI through APIs, resulting in a time-to-market advantage. The future of AI engineering holds promising results, with a focus on AI UX and the role of AI agents. Equity in AI and the central problems of AI engineering require collective efforts to address. The day-to-day life of an AI engineer involves working on products or infrastructure and dealing with specialties and tools specific to the field.
The Ai-Assisted Developer Workflow: Build Faster and Smarter Today
JSNation US 2024JSNation US 2024
31 min
The Ai-Assisted Developer Workflow: Build Faster and Smarter Today
AI is transforming software engineering by using agents to help with coding. Agents can autonomously complete tasks and make decisions based on data. Collaborative AI and automation are opening new possibilities in code generation. Bolt is a powerful tool for troubleshooting, bug fixing, and authentication. Code generation tools like Copilot and Cursor provide support for selecting models and codebase awareness. Cline is a useful extension for website inspection and testing. Guidelines for coding with agents include defining requirements, choosing the right model, and frequent testing. Clear and concise instructions are crucial in AI-generated code. Experienced engineers are still necessary in understanding architecture and problem-solving. Energy consumption insights and sustainability are discussed in the Talk.
Web Apps of the Future With Web AI
JSNation 2024JSNation 2024
32 min
Web Apps of the Future With Web AI
Web AI in JavaScript allows for running machine learning models client-side in a web browser, offering advantages such as privacy, offline capabilities, low latency, and cost savings. Various AI models can be used for tasks like background blur, text toxicity detection, 3D data extraction, face mesh recognition, hand tracking, pose detection, and body segmentation. JavaScript libraries like MediaPipe LLM inference API and Visual Blocks facilitate the use of AI models. Web AI is in its early stages but has the potential to revolutionize web experiences and improve accessibility.
Code coverage with AI
TestJS Summit 2023TestJS Summit 2023
8 min
Code coverage with AI
Codium is a generative AI assistant for software development that offers code explanation, test generation, and collaboration features. It can generate tests for a GraphQL API in VS Code, improve code coverage, and even document tests. Codium allows analyzing specific code lines, generating tests based on existing ones, and answering code-related questions. It can also provide suggestions for code improvement, help with code refactoring, and assist with writing commit messages.

Workshops on related topic

AI on Demand: Serverless AI
DevOps.js Conf 2024DevOps.js Conf 2024
163 min
AI on Demand: Serverless AI
Top Content
Featured WorkshopFree
Nathan Disidore
Nathan Disidore
In this workshop, we discuss the merits of serverless architecture and how it can be applied to the AI space. We'll explore options around building serverless RAG applications for a more lambda-esque approach to AI. Next, we'll get hands on and build a sample CRUD app that allows you to store information and query it using an LLM with Workers AI, Vectorize, D1, and Cloudflare Workers.
AI for React Developers
React Advanced 2024React Advanced 2024
142 min
AI for React Developers
Featured Workshop
Eve Porcello
Eve Porcello
Knowledge of AI tooling is critical for future-proofing the careers of React developers, and the Vercel suite of AI tools is an approachable on-ramp. In this course, we’ll take a closer look at the Vercel AI SDK and how this can help React developers build streaming interfaces with JavaScript and Next.js. We’ll also incorporate additional 3rd party APIs to build and deploy a music visualization app.
Topics:- Creating a React Project with Next.js- Choosing a LLM- Customizing Streaming Interfaces- Building Routes- Creating and Generating Components - Using Hooks (useChat, useCompletion, useActions, etc)
Leveraging LLMs to Build Intuitive AI Experiences With JavaScript
JSNation 2024JSNation 2024
108 min
Leveraging LLMs to Build Intuitive AI Experiences With JavaScript
Featured Workshop
Roy Derks
Shivay Lamba
2 authors
Today every developer is using LLMs in different forms and shapes, from ChatGPT to code assistants like GitHub CoPilot. Following this, lots of products have introduced embedded AI capabilities, and in this workshop we will make LLMs understandable for web developers. And we'll get into coding your own AI-driven application. No prior experience in working with LLMs or machine learning is needed. Instead, we'll use web technologies such as JavaScript, React which you already know and love while also learning about some new libraries like OpenAI, Transformers.js
Llms Workshop: What They Are and How to Leverage Them
React Summit 2024React Summit 2024
66 min
Llms Workshop: What They Are and How to Leverage Them
Featured Workshop
Nathan Marrs
Haris Rozajac
2 authors
Join Nathan in this hands-on session where you will first learn at a high level what large language models (LLMs) are and how they work. Then dive into an interactive coding exercise where you will implement LLM functionality into a basic example application. During this exercise you will get a feel for key skills for working with LLMs in your own applications such as prompt engineering and exposure to OpenAI's API.
After this session you will have insights around what LLMs are and how they can practically be used to improve your own applications.
Table of contents: - Interactive demo implementing basic LLM powered features in a demo app- Discuss how to decide where to leverage LLMs in a product- Lessons learned around integrating with OpenAI / overview of OpenAI API- Best practices for prompt engineering- Common challenges specific to React (state management :D / good UX practices)
Working With OpenAI and Prompt Engineering for React Developers
React Advanced 2023React Advanced 2023
98 min
Working With OpenAI and Prompt Engineering for React Developers
Top Content
Workshop
Richard Moss
Richard Moss
In this workshop we'll take a tour of applied AI from the perspective of front end developers, zooming in on the emerging best practices when it comes to working with LLMs to build great products. This workshop is based on learnings from working with the OpenAI API from its debut last November to build out a working MVP which became PowerModeAI (A customer facing ideation and slide creation tool).
In the workshop they'll be a mix of presentation and hands on exercises to cover topics including:
- GPT fundamentals- Pitfalls of LLMs- Prompt engineering best practices and techniques- Using the playground effectively- Installing and configuring the OpenAI SDK- Approaches to working with the API and prompt management- Implementing the API to build an AI powered customer facing application- Fine tuning and embeddings- Emerging best practice on LLMOps
Building AI Applications for the Web
React Day Berlin 2023React Day Berlin 2023
98 min
Building AI Applications for the Web
Workshop
Roy Derks
Roy Derks
Today every developer is using LLMs in different forms and shapes. Lots of products have introduced embedded AI capabilities, and in this workshop you’ll learn how to build your own AI application. No experience in building LLMs or machine learning is needed. Instead, we’ll use web technologies such as JavaScript, React and GraphQL which you already know and love.