Search API
Search functionalities of the Vantage API
The Search API gives you the ability to perform different types of searches supported by the Vantage platform. Currently, we support four different types. For more details, you can check the Search page of our documentation.
Vantage Client
In the following code blocks, we're initializing the Vantage client using Vantage API key. For more information on client configuration, check out the API Usage page.
Semantic Search
The following example demonstrates how to perform a semantic search over the collection example-collection
.
For more details on how it works, visit our Semantic Search documentation page.
from vantage_sdk import VantageClient
vantage_instance = VantageClient.using_vantage_api_key(
vantage_api_key=VANTAGE_API_KEY,
account_id=ACCOUNT_ID,
)
# Assuming that collection `example-collection` exists and contains data
search_results = vantage_instance.semantic_search(
text="example query",
collection_id="example-collection",
vantage_api_key="VANTAGE_API_KEY",
)
print(search_results)
import { VantageClientConfiguration, VantageClient } from "@vantage-sdk";
const configuration: VantageClientConfiguration = {
vantageApiKey: vantageApiKey,
accountId: accountId,
}
let client = new VantageClient(configuration)
// Assuming that collection `example-collection` exists and contains data
const collectionId = "example-collection"
const queryText = "Example query"
const searchResults = client.semanticSearch(collectionId, queryText);
searchResults.then((data) => console.log(data))
import com.vantage.sdk.VantageClient;
import com.vantage.sdk.api.search.model.SearchResult;
public static void main(final String[] args) {
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(ACCOUNT_ID)
.withVantageApiKey(VANTAGE_API_KEY)
.build();
final SearchResult searchResult = client
.search()
.collection("example-collection")
.semantic()
.withSearchText("example query")
.execute();
}
./cli.py semantic-search --text "my query text" "example-collection"
Embedding Search
The following example demonstrates how to perform a embedding search over the collection example-collection
.
For more details on how it works, visit our Embedding Search documentation page.
from vantage_sdk import VantageClient
vantage_instance = VantageClient.using_vantage_api_key(
vantage_api_key=VANTAGE_API_KEY,
account_id=ACCOUNT_ID,
)
# Assuming that collection `example-collection` exists and contains data
search_results = vantage_instance.embedding_search(
embedding=[0.1, 0.2, 0.3],
collection_id="example-collection",
vantage_api_key="VANTAGE_API_KEY",
)
print(search_results)
import { VantageClientConfiguration, VantageClient } from "./src";
const configuration: VantageClientConfiguration = {
vantageApiKey: vantageApiKey,
accountId: accountId,
}
let client = new VantageClient(configuration)
// Assuming that collection `example-collection` exists and contains data
const collectionId = "example-collection"
const queryEmbedding = [0.1, 0.2, 0.3]
const searchResults = client.embeddingSearch(collectionId, queryEmbedding);
searchResults.then((data) => console.log(data))
import java.math.BigDecimal;
import java.util.List;
import com.vantage.sdk.VantageClient;
import com.vantage.sdk.api.search.model.SearchResult;
public static void main(final String[] args) {
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(ACCOUNT_ID)
.withVantageApiKey(VANTAGE_API_KEY)
.build();
final SearchResult searchResult = client
.search()
.collection("example-collection")
.embedding(List.of(
BigDecimal.valueOf(0.1d),
BigDecimal.valueOf(0.2d),
BigDecimal.valueOf(0.3d),
))
.withEmbeddings(searchEmbeddings)
.execute();
}
./cli.py embedding-search --embedding [-0.010061902925372124, -0.017514921724796295, .... ] "example-collection"
More-Like-This Search
The following example demonstrates how to perform a more-like-this search over the collection example-collection
.
For more details on how it works, visit our More-Like-This Search documentation page.
from vantage_sdk import VantageClient
vantage_instance = VantageClient.using_vantage_api_key(
vantage_api_key=VANTAGE_API_KEY,
account_id=ACCOUNT_ID,
)
# Assuming that collection `example-collection` exists and contains data
search_results = vantage_instance.more_like_this_search(
document_id="DOCUMENT_ID",
collection_id="example-collection",
vantage_api_key="VANTAGE_API_KEY",
)
print(search_results)
import { VantageClientConfiguration, VantageClient } from "./src";
const configuration: VantageClientConfiguration = {
vantageApiKey: vantageApiKey,
accountId: accountId,
}
let client = new VantageClient(configuration)
const collectionId = "example-collection"
const documentId = "DOCUMENT_ID"
const searchResults = client.moreLikeThisSearch(collectionId, documentId);
searchResults.then((data) => console.log(data))
import com.vantage.sdk.VantageClient;
import com.vantage.sdk.api.search.model.SearchResult;
public static void main(final String[] args) {
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(ACCOUNT_ID)
.withVantageApiKey(VANTAGE_API_KEY)
.build();
final SearchResult result = client
.search()
.collection("example-collection")
.moreLikeThis()
.withDocumentId(DOCUMENT_ID)
.execute();
}
./cli.py more-like-this-search --document-id "document-123" "example-collection"
More-Like-These Search
The following example demonstrates how to perform a more-like-these search over the collection example-collection
.
For more details on how it works, visit our More-Like-These Search documentation page.
To understand and create a list of these
objects, the best option is to check all the details described here.
In the example below, these
consists of four objects: the first two represent image embedding vectors, the third represents a document ID, and the fourth represents plain text. Vantage will be able to perform a search based on all of these objects and find a group of new objects that match the most.
from vantage_sdk import VantageClient
vantage_instance = VantageClient.using_vantage_api_key(
vantage_api_key=VANTAGE_API_KEY,
account_id=ACCOUNT_ID,
)
# Assuming that collection `example-collection` exists and contains data
these = [
{
"embedding": [ 0.2, 0.1, -0.1 ... ], // Image 1
"weight": 0.15
},
{
"embedding": [ 0.1, 0.11, -0.9 ... ], // Image 2
"weight": 0.15
},
{
"query_document_id": "item-27", // Item 27 in collection
"weight": 0.2
},
{
"query_text": "soft chair", // Search Bar Text
"weight": 0.5
}
]
search_results = vantage_instance.more_like_these_search(
more_like_these=these,
collection_id="example-collection",
vantage_api_key="VANTAGE_API_KEY",
)
print(search_results)
import { VantageClientConfiguration, VantageClient } from "./src";
const configuration: VantageClientConfiguration = {
vantageApiKey: vantageApiKey,
accountId: accountId,
}
let client = new VantageClient(configuration)
const collectionId = "example-collection"
const these = [
{
"embedding": [ 0.2, 0.1, -0.1 ... ], // Image 1
"weight": 0.15
},
{
"embedding": [ 0.1, 0.11, -0.9 ... ], // Image 2
"weight": 0.15
},
{
"query_document_id": "item-27", // Item 27 in collection
"weight": 0.2
},
{
"query_text": "soft chair", // Search Bar Text
"weight": 0.5
}
]
const searchResults = client.moreLikeTheseSearch(collectionId, these);
searchResults.then((data) => console.log(data))
import com.vantage.sdk.VantageClient;
import com.vantage.sdk.api.search.model.SearchResult;
import com.vantage.sdk.api.search.model.These;
import java.math.BigDecimal;
import java.util.List;
public static void main(final String[] args) {
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(ACCOUNT_ID)
.withVantageApiKey(VANTAGE_API_KEY)
.build();
final List<These> these = List.of(
These.forEmbedding(
BigDecimal.valueOf(0.15),
List.of(BigDecimal.valueOf(0.2), BigDecimal.valueOf(0.1), BigDecimal.valueOf(-0.1))
),
These.forEmbedding(
BigDecimal.valueOf(0.15),
List.of(BigDecimal.valueOf(0.1), BigDecimal.valueOf(0.11), BigDecimal.valueOf(-0.9))
),
These.forQueryDocumentId(
BigDecimal.valueOf(0.2),
"item-27"
),
These.forQueryText(
BigDecimal.valueOf(0.5),
"soft chair"
)
);
final SearchResult result = client
.search()
.collection("example-collection")
.moreLikeThese()
.withThese(these)
.withVantageApiKey("VANTAGE_API_KEY")
.execute();
}
./cli.py more-like-these-search --more-like-these-json '[{"embedding": [ 0.2, 0.1, -0.1 ... ], "weight": 0.15 },{"embedding": [ 0.1, 0.11, -0.9 ... ], "weight": 0.15 }]' "example-collection"
Shopping Assistant Search
The following example demonstrates how to perform a semantic search using Shopping Assistant over the collection example-collection
.
For more details on how it works, visit our Shopping Assistant Search documentation page.
from vantage_sdk import VantageClient
vantage_instance = VantageClient.using_vantage_api_key(
vantage_api_key=VANTAGE_API_KEY,
account_id=ACCOUNT_ID,
)
shopping_assistant_id = "shopping-assistant-id"
collection_id = "example-collection"
text = "query text"
max_groups = 3
response = client.shopping_assistant_search(
collection_id=collection_id,
text=text,
shopping_assistant_id=shopping_assistant_id,
max_groups=max_groups,
)
import { VantageClientConfiguration, VantageClient } from "./src";
const configuration: VantageClientConfiguration = {
vantageApiKey: vantageApiKey,
accountId: accountId,
}
let client = new VantageClient(configuration)
const shoppingAssistantId = "shopping-assistant-id"
const collectionId = "example-collection"
const text = "query text"
const maxGroups = 3
const response = await client.shoppingAssistantSearch(
shoppingAssistantId,
text,
collectionId,
maxGroups
)
import com.vantage.sdk.VantageClient;
import com.vantage.sdk.api.search.model.SearchResult;
import com.vantagediscovery.sdk.api.search.model.ShoppingAssistantSearchResult;
public static void main(final String[] args) {
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(ACCOUNT_ID)
.withVantageApiKey(VANTAGE_API_KEY)
.build();
final ShoppingAssistantSearchResult searchResult = client
.search()
.collection("example-collection")
.usingShoppingAssistant(EXAMPLE_ASSISTANT_ID)
.withMaxGroups(15)
.withText("example search")
.execute();
}
Vantage Vibe Search
The following example demonstrates how to perform a Vantage Vibe search over the collection example-collection
.
For more details on how it works, visit our Vantage Vibe Search documentation page.
from vantage_sdk.model.search import VantageVibeImageUrl, VantageVibeImageBase64
images = [
VantageVibeImageUrl(url="https://www.someimageurl.com"),
VantageVibeImageBase64(base64="imagebase64"),
]
text = "test search"
client.vantage_vibe_search(
collection_id="example-collection",
images=images,
text=text,
)
const collectionId = "example-collection"
const queryText = "test search"
const urlImage: VantageVibeImageUrl = {
url: "https://www.someimageurl.com",
}
const base64Image: VantageVibeImageBase64 = {
base64: "imagebase64"
}
const images: Array<VantageVibeImageUrl | VantageVibeImageBase64> = [
urlImage,
base64Image
]
client.vantageVibeSearch(
collectionId,
images,
queryText
)
final VantageClient client = VantageClient.usingVantageApiKey()
.withAccountId(testUser)
.withVantageApiKey(vantageApiKey)
.build();
final SearchResult result = client
.search()
.collection(semanticSearchCollection)
.vibe()
.withSearchText("test search")
..withImageURL(vibeImageUrl)
.withImageEncodedAsBase64(vibeImageAsBase64)
.withImagesURLs(listOfVibeImagesURLs)
.withImagesEncodedAsBase64(listOfImagesAddBase64)
.execute();
Updated 2 months ago