Quickstart

Getting started with Objective Search requires the following steps:

  • Add data: Add data to the Object Store
  • Create Index: Build an Index using the data
  • Search Index: Querying the Index to get results

Setup

For this quickstart we'll be using the Objective SDK. First, get an API key and install the SDK.

To get an API key, sign up.

If you already have an account, you can find your API key on the API Keys page.

Install the Objective SDK

See SDKs for more SDK options.

Install SDK

pip3 install --upgrade objective-sdk requests

Adding data

Push Objects to the Object Store using the Batch API.

Adding data

import json
import requests
from objective import Objective
client = Objective(api_key='sk_YOUR_API_KEY')

data = json.loads(requests.get("https://d11p8vtjlacpl4.cloudfront.net/demos/ecommerce/hm-10k.json").text)
batch_size = 100
for i in range(0, len(data), batch_size):
   batch = data[i:i+batch_size]
   client.objects.batch(
       operations=[{"method": "PUT", "object_id": str(obj.get("article_id")), "object": obj} for obj in batch]
   )
   print(f"\rUpserted {i+batch_size} objects...", end="", flush=True)

print("\nUpsert complete!")

Building an Index

Build an index out of the Objects pushed to the API. This will create an Index and add all of the Objects in the Object Store to it, making them searchable. For more details on configuring indexes, see Configuring Indexes.

Building an Index

from objective import Objective

from objective.types.index_create_params import Configuration, ConfigurationIndexType, ConfigurationFields

client = Objective(api_key='sk_YOUR_API_KEY')

index = client.indexes.create(
       configuration=Configuration(
           index_type=ConfigurationIndexType(
               name="multimodal",
           ),
           fields=ConfigurationFields(
               searchable={
                   "allow": [
                     "prod_name",
                     "colour_group_name",
                     "detail_desc",
                     "department_name",
                     "garment_group_name",
                     "index_group_name",
                     "perceived_colour_master_name",
                     "perceived_colour_value_name",
                     "product_type_name",
                     "product_group_name",
                     "section_name"
                   ],
               },
               crawlable={
                   "allow":[
                       "image_url"
                   ]
               },
               filterable={
                  "allow": [
                       "department_name",
                       "price"
                   ]
               },
               types={
                   "department_name": "string",
                   "price": "int",
               },
           )
       ),
   )

print(f"Index {index.id} is has been created!")

Querying results

Querying results

from objective import Objective

client = Objective(api_key="sk_YOUR_API_KEY")

search_response = client.indexes.search(
    index_id="idx_YOUR_INDEX_ID",
    query="red dress",
    object_fields="*"
)

print(search_response.to_json())

Learn more at these links:

  • managing data via the Object Store APIs
  • configuring indexes via the Index APIs
  • searching and filtering via the Search API

For help or to ask a question, email us: [email protected].

Was this page helpful?