Meet Objective Text Indexes: AI-Powered Semantic Search in a Few Lines of Code

February 26, 2024
Team Objective

The team here at Objective has been hard at work this month making Objective Search smarter and we’re excited to introduce you to Text Indexes, launching into self-service Private Beta today. We’re onboarding developers into the Private Beta as fast as we can, so if you don’t have an account yet, get on the waitlist and we’ll let you know when your account is ready!

Searching for meaning, not just matches.

For most of our lives as web developers, we’ve used old search platforms (or hacked features together ourselves) that rely on ‘lexical’ search. Most of us know it as a ‘keyword’ search - search that compares two string values for equality (here’s looking at you, MySQL INSTR() 😘). There are some things lexical search is great at, like looking up names in an employee directory.

But there are a lot of things that are hard or just flat-out impossible with lexical search, because of the difference between matching and understanding meaning. Fortunately for your app, Objective Search is great at both.

Really smart search in a few lines of code

Objective Search speaks in meaning — taking your user’s search query, extracting the semantic meaning, and comparing it to the meaning of the Objects in your Object Store.

Let’s say you’re building product search for your fashion store, and you’ve added Objects to your Object Store that have name and color string attributes with product info, like this —


{
	"name": "Winter Wonderland Pea Coat",
	"color": "forest green"
}

And let’s say your user searches for “dark green heavy winter coat”. Pretty reasonable, right?

Simple dictionary-lookup search would miss our Winter Wonderland Pea Coat Object entirely. But your Objective Search Indexes understand the meaning in the query, and know we’re looking for a winter coat. It also understands that forest green is semantically very similar to dark green. Which is good news for your user, who is now about to look pretty sharp this winter.

At it’s core, your Text Index understands the meaning of your user’s search query, understands the meaning of all of the string attributes of the Objects in your Object Store, and retrieves the most relevant results for your user. And that means more finding what they want. One of the best parts is how much power you get from a few lines of code.

First, jump into your CLI and grab our new Python lib (or Typescript, if that’s your flavor!) —

% pip install objective-sdk

And then in your favorite .py file, let’s put some stuff in an Object Store


from objective import Client
client = Client(api_key="YOUR_API_KEY")

objects = [
	{
		"title": "Winter Wonderland Pea Coat",
		"color": "forest green"
	},
	{
		"title": "Winter Wonderland Hat",
		"color": "forest green"
	},
	{
		"title": "Endless Summer Basketweave Pool Hat",
		"color": "tan"
	},
	{
		"title": "High-Pile Winter Fleece Coat",
		"color": "lime green"
	}
]

client.object_store.upsert_objects(objects)

Your Object Store has a few different Objects in it now - some are coats, some aren’t. Some are different kinds of green, some aren’t. Now let’s make your first Text Index —


# The fields attribute lets you define which properties of your Object
# your new Text Index should be searchable. To ignore a field, just
# remove it from the array!

index = client.indexes.create_index(
	index_type="text", fields={"searchable": ["title", "color"]}
)

All Objective Search Indexes process (and reprocess!) your Objects automatically. While an Index is processing, you can programmatically poll the status of Index processing by - you guessed it — calling status.


index.status()

Index status() returns a queue of processing operations during this execution, that you can use to make decisions about how to wait or proceed:


{'UPLOADED':1, 'PROCESSING':0, 'READY':0, 'ERROR':0}

Once everything has processed, all that’s left to do is run a search query and watch the magic happen. Let’s find that coat our user was looking for:


# We can ask our Text Index to return only certain fields, or all.
# For this example, we want 'em all, so we'll pass a *

index.search(query="dark green heavy winter coat", object_fields="*")

Your Text Index will look inside each Object in your Object Store and will prioritize the most relevant results first. There’s that coat we were after:


{
	"results": [
		{
			"title": "Winter Wonderland Pea Coat",
			"color": "forest green"
		},
		...
	],
	"pagination": {"pages":1, "page":1, "next":null}
}

Notice that your Text Index knew we weren’t talking about the other coat we added that was a different green - and it knew we weren’t talking about either of the hats. It prioritized the forest green Winter Wonderland Coat. Let’s go ahead and find all the cold weather gear instead.


index.search(query="winter clothes", object_fields="*")

Your Text Index should come back with these snappy numbers prioritized first in the result set:


{
	"results": [
		{
			"title": "Winter Wonderland Pea Coat",
			"color": "forest green"
		},
		{
			"title": "Winter Wonderland Hat",
			"color": "forest green"
		},
		{
			"title": "High-Pile Winter Fleece Coat",
			"color": "lime green"
		},
		...
	],
	"pagination": {"pages":1, "page":1, "next":null}
}

We think every website and every app gets better when every developer has powerful, production-ready, built-for-massive-scale AI-driven search in their toolbelt. If you have a Private Beta account, you can log in and get started today! If not, you can get on the waitlist and we’ll let you know when your account is ready!

We can’t wait to see what you build!

Subscribe to our Newsletter!

Get the latest news and updates directly to your inbox.
Thank you! We'll get back to you as soon as possible.
Uh-oh... something went wrong. Please try again later.

We recommend you to read