You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add end-to-end example showing full OCI application flow
Demonstrates embeddings → vector search → grounded chat → tool use
(multi-turn) → vision → streaming in a single runnable script.
All steps verified against live OCI Generative AI.
Copy file name to clipboardExpand all lines: fern/pages/deployment-options/oracle-cloud-infrastructure-oci.mdx
+138Lines changed: 138 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -345,6 +345,144 @@ for i, embedding in enumerate(response.embeddings.float_):
345
345
|`tokenize`| Offline only |
346
346
|`detokenize`| Offline only |
347
347
348
+
## End-to-End Example
349
+
350
+
The following example demonstrates a complete application flow on OCI Generative AI: embedding documents for a knowledge base, retrieving relevant context, using tool calling for live data, processing images with vision, and streaming a final response.
351
+
352
+
```python
353
+
import cohere
354
+
import base64
355
+
356
+
# Initialize V2 client for Command A models
357
+
client = cohere.OciClientV2(
358
+
oci_region="us-chicago-1",
359
+
oci_compartment_id="ocid1.compartment.oc1...",
360
+
)
361
+
362
+
# --- Step 1: Build a knowledge base with embeddings ---
363
+
364
+
documents = [
365
+
"Oracle Cloud Infrastructure provides enterprise-grade AI services.",
366
+
"Cohere Command A is a 111B parameter model with 256K context window.",
367
+
"OCI Generative AI is FedRAMP High and DISA IL5 authorized.",
368
+
]
369
+
370
+
doc_embeddings = client.embed(
371
+
model="embed-english-v3.0",
372
+
texts=documents,
373
+
input_type="search_document",
374
+
).embeddings.float_
375
+
376
+
query_embedding = client.embed(
377
+
model="embed-english-v3.0",
378
+
texts=["What security certifications does OCI have?"],
379
+
input_type="search_query",
380
+
).embeddings.float_[0]
381
+
382
+
# Find the most relevant document (cosine similarity)
383
+
best_idx =max(
384
+
range(len(documents)),
385
+
key=lambdai: sum(a * b for a, b inzip(query_embedding, doc_embeddings[i])),
386
+
)
387
+
print(f"Best match: {documents[best_idx]}")
388
+
389
+
# --- Step 2: Grounded chat with retrieved context ---
390
+
391
+
response = client.chat(
392
+
model="command-a-03-2025",
393
+
messages=[
394
+
{"role": "system", "content": "Answer based on the provided context only."},
395
+
{"role": "user", "content": f"Context: {documents[best_idx]}\n\nWhat certifications does OCI have?"},
0 commit comments