Skip to content

Commit 47bd55d

Browse files
[Backport 8.13] Add inference doc code examples (#2497)
* Add inference examples * switching from `model_id` to `inference_id` as per discussion. (cherry picked from commit 135c60a) Co-authored-by: Iulia Feroli <[email protected]>
1 parent b5a2439 commit 47bd55d

16 files changed

+146
-6
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// inference/put-inference.asciidoc:276
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="my-e5-model",
8+
body={
9+
"service": "elasticsearch",
10+
"service_settings": {
11+
"num_allocations": 1,
12+
"num_threads": 1,
13+
"model_id": ".multilingual-e5-small",
14+
},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// inference/put-inference.asciidoc:371
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="my-msmarco-minilm-model",
8+
body={
9+
"service": "elasticsearch",
10+
"service_settings": {
11+
"num_allocations": 1,
12+
"num_threads": 1,
13+
"model_id": "msmarco-MiniLM-L12-cos-v5",
14+
},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// inference/post-inference.asciidoc:72
2+
3+
[source, python]
4+
----
5+
resp = client.inference.inference(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
body={
9+
"input": "The sky above the port was the color of television tuned to a dead channel."
10+
},
11+
)
12+
print(resp)
13+
----

docs/examples/3541d4a85e27b2c3896a7a7ee98b4b37.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:470
1+
// health/health.asciidoc:478
22

33
[source, python]
44
----
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// inference/put-inference.asciidoc:252
2+
3+
[source, python]
4+
----
5+
6+
resp = client.inference.put_model(
7+
task_type="text_embedding",
8+
inference_id="cohere_embeddings",
9+
body={
10+
"service": "cohere",
11+
"service_settings": {
12+
"api_key": "api_key",
13+
"model_id": "embed-english-v3.0",
14+
"embedding_type": "int8",
15+
},
16+
"task_settings": {},
17+
},
18+
)
19+
print(resp)
20+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// inference/delete-inference.asciidoc:51
2+
3+
[source, python]
4+
----
5+
resp = client.inference.delete_model(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
)
9+
print(resp)
10+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// inference/put-inference.asciidoc:301
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="sparse_embedding",
7+
inference_id="my-elser-model",
8+
body={
9+
"service": "elser",
10+
"service_settings": {"num_allocations": 1, "num_threads": 1},
11+
"task_settings": {},
12+
},
13+
)
14+
print(resp)
15+
----

docs/examples/73be1f93d789264e5b972ddb5991bc66.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// setup/logging-config.asciidoc:156
1+
// setup/logging-config.asciidoc:158
22

33
[source, python]
44
----

docs/examples/87733deeea4b441b595d19a0f97346f0.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:463
1+
// health/health.asciidoc:471
22

33
[source, python]
44
----

docs/examples/8e286a205a1f84f888a6d99f2620c80e.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// setup/logging-config.asciidoc:233
1+
// setup/logging-config.asciidoc:235
22

33
[source, python]
44
----

0 commit comments

Comments
 (0)