Check out a free preview of the full Build AI-Powered Apps with OpenAI and Node.js course

The "Search & Langchain Overview" Lesson is part of the full, Build AI-Powered Apps with OpenAI and Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Scott introduces semantic search, which goes beyond simple string matching to understand the meaning and context of words. Scott shares some examples of semantic search in action, such as autocomplete suggestions and recommendation systems. Langchain is introduced, and the semantic search feature in the documentation is demonstrated.

Preview
Close

Transcript from the "Search & Langchain Overview" Lesson

[00:00:00]
>> We all know what search is, right? You've built search or you've seen search built or you've interacted with search. There's so many ways around it. I mean, let's start from the beginning. We know search engines, basically, something like Google or Bing or Yahoo, those are search engines.

[00:00:15]
And what they try to do is they try to find the most relevant thing based off whatever query you typed in, right? And that's how it started. So Google has its page rank score, which ranks pages based off of how many other good links they link to. So the more links you link to, the higher your page score, which is funny because the guy who created it was Larry Page, but they're also on pages.

[00:00:41]
I think it's pretty funny. And, it started off as that, it might have evolved passed in, but they try to figure that out. That's one search engine. You might be on Amazon searching for a product, that's another search engine, right? You might have built some things where you do faceting, which is, check this filter, check this filter, uncheck this filter.

[00:01:00]
When you're searching for clothes on a website or something, this size, this color, pants, and you might check those, that's called faceting. You have string matching, so you're just doing I'm filtering off of whether or not this string is a subset of another string. There's so many ways to do that type of filtering in search.

[00:01:21]
But when you start adding AI to search, and you start thinking about semantics and meaning behind the text, this goes back pretty far. So if you think about how Google works, Google can autocomplete as you type, right? It can suggest things that you type for, based off of what other people are typing for.

[00:01:43]
So it's trying to figure out the intent on what it is that you're looking for. So there's a little bit of AI there. And there's a lot of systems that go into that, that create that personalization. But I can promise you, it requires billions and billions of points of data, talking beyond terabytes.

[00:01:59]
And it requires a lot of training, a lot of resources, and a lot of models working together, and even better yet, a lot of really smart people to build that. It's not something that's one person did, there's a huge team of people trying to figure that out. And they need a lot of different data points from things that you click on, from ads that you look at, from people in your area.

[00:02:19]
There's a lot of stuff that goes into it. So it's not that trivial to make. So enter semantic search. So semantic search is basically where you can search on how things relate semantically, as in meaning, not just whether or not it's a substring of something. Like, I wanna know if the words that I'm typing in are similar in meaning to some other words that this system might be indexed on, right?

[00:02:48]
So if you are indexed on, I don't know, you have a system that's indexed on pets and I type in cute and fluffy, I would hope to get back some results that didn't have reptiles in it, because reptiles aren't cute and fluffy, right? Whereas even if the reptile had the word cute and fluffy in it, to talk about how it wasn't cute and fluffy, I would imagine it still would not come back, because its meaning is not that, right?

[00:03:16]
There's some semantics behind it that only a human would understand, because they understand context, they know what a reptile is and they understand that, right? So it's like, that's more of a word of semantic searches. It's not good for everything. If you are only searching for one word, semantic search is actually terrible at that.

[00:03:36]
It's too slow. And if you're searching for one word, you're probably looking for something that has that one word. Like if I hit Cmd+F right now, and I search for one word, like how, I'll want to go to all the results that say how. I don't want to find results that feel like I'm saying how.

[00:03:54]
No, I wanna go exactly to how, right? If I type in search, I wanna go exactly to all the instances of search and not something that says find, cuz it means something similar to search. So semantic search isn't always the best, specifically for things where I'm looking for an exact thing.

[00:04:11]
So exact matching is still better there. But it's really great for, I wanna understand the meaning behind two things or more than one thing and how they relate and I wanna find stuff that way. So that's where it's good to do that. And a really good example is a recommendation system where you're recommending things based off someone's viewing habits.

[00:04:35]
If you're in Netflix and you wanna show people some more titles based off their viewing habits. You can semantically see how something they've watched might be related to something that they haven't watched, beyond just the category that it's in, the director that shot it, the actors that are in it, the genre of the film, it's beyond that.

[00:04:55]
It's the plot, right, the plot is similar or the setting is similar or something like that, right? So that's semantic search. One good example of it just to show you. Let me see. If you go to LangChain, which actually I'm glad I'm showing this, cuz we're gonna be using this.

[00:05:14]
So if you go to LangChain, which is an SDK, that's like, I don't know how to describe LangChain, it's everything. [LAUGH] It's basically a very popular, probably the most popular SDK around AI. So if you wanna build AI-powered apps, right now we're just using the OpenAI SDK. LangChain is like, it takes that to the next level.

[00:05:36]
That chat interface that we had to create, they just have that as a method you can just use, so you don't have to make that. And all those scaling issues that I talked about, they handle a lot of them automatically for you, you just kinda connect things together.

[00:05:50]
So it's really cool. I started my journey using LangChain on everything. I don't use as much anymore for everything. There are some things that I always use it for, there's other things I don't, but it's really great. I highly recommend diving into it and we will be using it today.

[00:06:04]
But anyway, their docs have an example of semantic search. So if I click on search here, it's powered by this thing called Mendable. Mendable is this product that allows you to add semantic search to your, if you have a technical product that as documentation, you can use Mendable to teach your search about that documentation, to allow your users to search on those things semantically.

[00:06:27]
That's what Mendable is. So anyway, I can go in here, I can be like, how. And it's like a hybrid. You can see right now it's doing a text search here as I type, something a traditional search would do, right? But when I hit Enter, it's gonna do this semantic search.

[00:06:45]
So how to create an agent. So if I hit that, you can see now it's searching the documentation, it's trying to figure out the semantics behind this, find the necessary context. And then it creates its own result based off of that documentation. So this result is unique to this query.

[00:07:06]
This is not as a result that is already written somewhere. The AI is literally generating this result in front of my eyes right now based off the documentation on which it was indexed on, right? So this is a combination of semantic search plus document QA, which we'll talk about later, plus the hybrid traditional searching.

[00:07:26]
So it's a combination of all the things, but I just want you to see how different this is versus just getting, as you saw those instant results as I type, that's a different type of search. So yeah, this is a really good example of semantic search. Yeah, we're not gonna build this [LAUGH], but we're gonna build a foundation of this, and you're gonna understand the insides of it, so.

[00:07:49]
Cuz there's a lot that goes into it to make that happen, and so let's talk about it.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now