Search for documents
Perform a similarity search on a Telnyx Storage Bucket, returning the most similar num_docs document chunks to the query.
Currently the only available distance metric is cosine similarity which will return a distance between 0 and 1.
The lower the distance, the more similar the returned document chunks are to the query.
A certainty will also be returned, which is a value between 0 and 1 where the higher the certainty, the more similar the document.
You can read more about Weaviate distance metrics here: Weaviate Docs
If a bucket was embedded using a custom loader, such as intercom, the additional metadata will be returned in the
loader_metadata field.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.embeddings.similaritySearch({
bucket_name: 'bucket_name',
query: 'query',
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.embeddings.similarity_search(
bucket_name="bucket_name",
query="query",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Embeddings.SimilaritySearch(context.TODO(), telnyx.AIEmbeddingSimilaritySearchParams{
BucketName: "bucket_name",
Query: "query",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.embeddings.EmbeddingSimilaritySearchParams;
import com.telnyx.sdk.models.ai.embeddings.EmbeddingSimilaritySearchResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmbeddingSimilaritySearchParams params = EmbeddingSimilaritySearchParams.builder()
.bucketName("bucket_name")
.query("query")
.build();
EmbeddingSimilaritySearchResponse response = client.ai().embeddings().similaritySearch(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.embeddings.similarity_search(bucket_name: "bucket_name", query: "query")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->embeddings->similaritySearch(
bucketName: 'bucket_name', query: 'query', numOfDocs: 0
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:embeddings similarity-search \
--api-key 'My API Key' \
--bucket-name bucket_name \
--query querycurl --request POST \
--url https://api.telnyx.com/v2/ai/embeddings/similarity-search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"bucket_name": "Bucket Name",
"query": "Query",
"num_of_docs": 3
}
'{
"data": [
{
"document_chunk": "Document Chunk",
"distance": 0,
"metadata": {
"source": "Source",
"checksum": "Checksum",
"embedding": "Embedding",
"filename": "Filename",
"certainty": 0
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Response
Successful Response
Show child attributes
Show child attributes
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.embeddings.similaritySearch({
bucket_name: 'bucket_name',
query: 'query',
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.embeddings.similarity_search(
bucket_name="bucket_name",
query="query",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Embeddings.SimilaritySearch(context.TODO(), telnyx.AIEmbeddingSimilaritySearchParams{
BucketName: "bucket_name",
Query: "query",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.embeddings.EmbeddingSimilaritySearchParams;
import com.telnyx.sdk.models.ai.embeddings.EmbeddingSimilaritySearchResponse;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmbeddingSimilaritySearchParams params = EmbeddingSimilaritySearchParams.builder()
.bucketName("bucket_name")
.query("query")
.build();
EmbeddingSimilaritySearchResponse response = client.ai().embeddings().similaritySearch(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.embeddings.similarity_search(bucket_name: "bucket_name", query: "query")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->embeddings->similaritySearch(
bucketName: 'bucket_name', query: 'query', numOfDocs: 0
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:embeddings similarity-search \
--api-key 'My API Key' \
--bucket-name bucket_name \
--query querycurl --request POST \
--url https://api.telnyx.com/v2/ai/embeddings/similarity-search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"bucket_name": "Bucket Name",
"query": "Query",
"num_of_docs": 3
}
'{
"data": [
{
"document_chunk": "Document Chunk",
"distance": 0,
"metadata": {
"source": "Source",
"checksum": "Checksum",
"embedding": "Embedding",
"filename": "Filename",
"certainty": 0
}
}
]
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}