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
* update vector storage docs
- Add Vector DB guide examples (`search`)
- Update JS examples to include required "key" field for `upsert`
- Update Vector DB guide to reflect both SDKs return `similarity` field
- Remove unnecessary distance-to-similarity conversions
- Add note about JS backwards compatibility with `distance` parameter
* Update subheadings in Vector DB guide
* Update based on suggestions
* Fix grammar in SDK requirement note
Copy file name to clipboardExpand all lines: content/Guides/vector-db.mdx
+316-7Lines changed: 316 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,13 +44,16 @@ Vector storage is created automatically when your agent first calls `context.vec
44
44
45
45
## Vector Storage API
46
46
47
+
For complete API documentation, see:
48
+
-[JavaScript SDK Vector API Reference](/SDKs/javascript/api-reference#vector-storage)
49
+
-[Python SDK Vector API Reference](/SDKs/python/api-reference#vector-storage)
50
+
47
51
### Upserting Documents
48
52
49
53
The `upsert` operation inserts new documents or updates existing ones. You can provide either text (which gets automatically converted to embeddings) or pre-computed embeddings.
50
54
51
-
**SDK Differences:**
52
-
-**JavaScript SDK**: No key field required, search returns `distance` (0 = perfect match)
53
-
-**Python SDK**: Requires `key` field for each document, search returns `similarity` (1.0 = perfect match)
55
+
**SDK Requirements:**
56
+
-**Both SDKs**: Require a `key` field for each document
54
57
55
58
**Idempotent Behavior:**
56
59
The upsert operation is idempotent - upserting with an existing key updates the existing vector rather than creating a duplicate. The same internal vector ID is reused, ensuring your vector storage remains clean and efficient.
@@ -62,10 +65,12 @@ The upsert operation is idempotent - upserting with an existing key updates the
62
65
constids=awaitcontext.vector.upsert(
63
66
'knowledge-base',
64
67
{
68
+
key:'doc-1',
65
69
document:'Agentuity is an agent-native cloud platform',
This example demonstrates a complete Retrieval-Augmented Generation (RAG) pattern - searching for relevant context and using it to generate informed responses.
# 4. Generate response using context (example with AI Gateway)
300
+
prompt = f"""Answer the question based on the following context:
301
+
302
+
Context: {assembled_context}
303
+
304
+
Question: {question}
305
+
306
+
Answer:"""
307
+
308
+
# Use your preferred LLM here (OpenAI, Anthropic, etc.)
309
+
llm_response = await generate_answer(prompt)
310
+
311
+
# 5. Return answer with sources
312
+
return response.json({
313
+
"answer": llm_response,
314
+
"sources": [
315
+
{
316
+
"id": result.id,
317
+
"key": result.key,
318
+
"title": result.metadata.get("title"),
319
+
"similarity": result.similarity
320
+
}
321
+
for result in search_results
322
+
]
323
+
})
324
+
325
+
except Exception as e:
326
+
context.logger.error(f"RAG query failed: {e}")
327
+
return response.json({
328
+
"error": "Failed to process your question",
329
+
"details": str(e)
330
+
})`} />
331
+
332
+
**Key Points:**
333
+
-**Semantic search** finds relevant documents based on meaning, not keywords
334
+
-**Similarity threshold** of 0.7 balances relevance with recall
335
+
-**Context assembly** combines multiple sources for comprehensive answers
336
+
-**Error handling** ensures graceful failures with helpful messages
337
+
-**Source attribution** provides transparency about where information came from
338
+
339
+
### Semantic Search with Metadata Filtering
340
+
341
+
This example shows how to combine semantic similarity with metadata filters for precise results - like finding products that match both meaning and business criteria.
342
+
343
+
<CodeExamplejs={`// JavaScript/TypeScript - Product search with filters
0 commit comments