Vector Database Integration — Client Developer Documentation
Introduction
The Vector Database add-on gives agents one interface for storing and searching embeddings (semantic search, recommendation, retrieval-augmented generation). It is provided by the EmbeddingsSDK class in the agent_addons package.
Supported providers:
- Weaviate (via the
weaviate-clientv3weaviate.ClientAPI) - Pinecone (serverless indexes)
EmbeddingsSDK provides:
- Collection (Weaviate class / Pinecone index) management.
- Vector CRUD and similarity search with metadata filters.
- Text-based helpers that embed text with an embeddings generator before inserting or searching.
- Ingestion of pre-computed vectors from local JSON/JSONL files or S3.
The same package includes AgentRAG, a small retrieval-augmented generation helper built on EmbeddingsSDK.
Typical workflow:
- Declare an
AddonItemin the Subject Specification to record the vector DB (optional). - Create an
EmbeddingsSDKclient for Weaviate or Pinecone. - Create a collection, then insert vectors (or texts) with optional metadata.
- Search by vector or by text, with optional filters.
- Retrieve, update, or delete vectors as needed.
Installation
EmbeddingsSDK is part of agent_addons (libs/agents-addons), which installs weaviate-client, pinecone-client and boto3.
pip install ./libs/agents-addons
Registering Vector DB in Subject Specification
Vector databases can be recorded in the subject's integrations.addons list using AddonItem.
Data Class Reference
from dataclasses import dataclass, field
from typing import Dict, Any
@dataclass
class AddonItem:
addon_id: str
addon_type: str
addon_config: Dict[str, Any] = field(default_factory=dict)
Example Configuration
{
"addon_id": "vector-primary",
"addon_type": "vector_db",
"addon_config": {
"provider": "weaviate",
"weaviate_url": "http://weaviate.default.svc.cluster.local:8080",
"metric": "cosine"
}
}
Field Descriptions
| Field | Type | Description |
|---|---|---|
| addon_id | str |
Unique identifier for this add-on. |
| addon_type | str |
Add-on kind, e.g. "vector_db". |
| addon_config | Dict[str, Any] |
Client settings. Use the EmbeddingsSDK constructor arguments as keys (see below). |
The agents SDK does not create clients from add-on entries automatically. Read the entry from
self.subject.integrations.addonsin your agent and build the client yourself, e.g.EmbeddingsSDK(**addon.addon_config).
Import and Setup
from agent_addons.embeddings_store import EmbeddingsSDK
Weaviate
vdb = EmbeddingsSDK(
provider="weaviate",
weaviate_url="http://localhost:8080",
weaviate_api_key=None, # optional
metric="cosine",
)
Pinecone
vdb = EmbeddingsSDK(
provider="pinecone",
pinecone_api_key="pc-...",
dimension=1536, # required to create indexes
metric="cosine",
pinecone_cloud="aws",
pinecone_region="us-east-1",
)
| Argument | Default | Description |
|---|---|---|
provider |
— (required) | "weaviate" or "pinecone" (anything else raises ValueError) |
dimension |
None |
Vector dimension (used when creating Pinecone indexes) |
metric |
"cosine" |
Distance metric (Weaviate class distance / Pinecone index metric) |
weaviate_url |
None |
Required for Weaviate |
weaviate_api_key |
None |
Optional Weaviate API key |
pinecone_api_key |
None |
Required for Pinecone |
pinecone_index_name |
None |
Stored on the client for reference |
pinecone_cloud |
"aws" |
Serverless cloud for new indexes |
pinecone_region |
"us-east-1" |
Serverless region for new indexes |
Usage Guide
A. Collections
A collection is a Weaviate class or a Pinecone index.
vdb.create_collection("KnowledgeBase")
vdb.list_collections() # ['KnowledgeBase', ...]
vdb.delete_collection("KnowledgeBase")
- Weaviate: creates a class with
vectorizer: "none"(you bring your own embeddings), an HNSW index and the configured distance. - Pinecone: creates a serverless index with
dimensionandmetric.
B. Insert vectors
vdb.insert_vectors("KnowledgeBase", [
{"id": "4b7c1c1e-6a8e-4b6c-9a0e-2f1a3b4c5d6e", "values": [0.12, 0.98, ...], "metadata": {"text": "Doc A", "source": "wiki"}},
{"id": "9f0e2d3c-1b2a-4c5d-8e7f-6a5b4c3d2e1f", "values": [0.33, 0.71, ...]},
])
- Weaviate: objects are batch-added with the given
idas UUID (Weaviate requires UUIDs),valuesas the vector andmetadataas properties. - Pinecone: the list is upserted as-is into the index.
C. Get, update and delete
vdb.get_vector("KnowledgeBase", vid) # Weaviate object / Pinecone fetch result (dict)
vdb.update_vector("KnowledgeBase", vid, new_values, metadata={"source": "updated"})
vdb.delete_vector("KnowledgeBase", vid)
D. Similarity search
results = vdb.search("KnowledgeBase", query_vector, top_k=5, filters=None)
filters is passed to the provider unchanged:
- Weaviate: a
wherefilter, e.g.{"path": ["source"], "operator": "Equal", "valueText": "wiki"}. The result is the raw GraphQL response ({"data": {"Get": {"KnowledgeBase": [...]}}}). - Pinecone: a metadata filter, e.g.
{"source": {"$eq": "wiki"}}. The result is the raw query response (matcheswithid,score,metadata).
E. Text-based helpers
These helpers take an embedder: any object with embed_texts(texts, batch_size=...) -> List[List[float]], such as the generators from the Embeddings SDK.
from agents_embeddings.custom import OpenAIEmbeddingsGenerator
embedder = OpenAIEmbeddingsGenerator(model="text-embedding-3-small") # uses OPENAI_API_KEY
# Items can be strings or dicts with "text" (+ optional "id", "metadata")
vdb.insert_texts("KnowledgeBase", [
"AI is transforming industries.",
{"id": "4b7c1c1e-...", "text": "Vector DBs store embeddings.", "metadata": {"source": "notes"}},
], embedder=embedder, batch_size=128)
vdb.update_texts("KnowledgeBase", [{"id": "4b7c1c1e-...", "text": "Updated text"}], embedder=embedder)
hits = vdb.search_text("KnowledgeBase", "What stores embeddings?", embedder=embedder, top_k=3)
many = vdb.bulk_search_texts("KnowledgeBase", ["query one", "query two"], embedder=embedder, top_k=3)
- Items without an
idget a random hex ID (uuid4().hex). insert_textsstores only the item'smetadata, not the text itself. Include the text inmetadataif you need it back from search results.- Use
id_key,text_keyandmetadata_keyto map other field names, andpreprocessto transform text before embedding.
F. Ingest pre-computed vectors
The file or S3 object must be a JSON array or JSONL of {"id", "values", "metadata"} records (or anything transform turns into that).
vdb.ingest_from_file("KnowledgeBase", "/data/vectors.jsonl", batch_size=100)
vdb.ingest_from_s3("KnowledgeBase", bucket="my-bucket", key="vectors/part-0001.jsonl",
region="us-east-1", transform=lambda r: {"id": r["uuid"], "values": r["emb"], "metadata": r["meta"]})
S3 ingestion uses the default boto3 credential chain; the region defaults to AWS_REGION.
Retrieval-Augmented Generation (AgentRAG)
AgentRAG combines an EmbeddingsSDK, an embedder and an LLM to answer questions from stored documents.
from agent_addons.rag import AgentRAG
from agents_llm_lite.custom import OpenAIInference
llm = OpenAIInference(model="gpt-4o-mini")
rag = AgentRAG(
collection="KnowledgeBase",
embeddings_sdk=vdb,
embedder=embedder,
llm=llm, # an agents_llm_lite provider, e.g. OpenAIInference(model="gpt-4o-mini")
text_field="text", # metadata field holding the chunk text
default_top_k=5,
max_context_chars=12_000,
chunk_size=1200,
chunk_overlap=200,
)
rag.add_texts(["Acme was founded in 1999.", {"text": "RetailCo is based in Delaware."}])
rag.add_documents_chunked([{"id": "contract-1", "text": long_contract_text, "metadata": {"type": "contract"}}])
chunks = rag.retrieve("Where is RetailCo based?", top_k=3) # List[RetrievedChunk(id, score, metadata, text)]
result = rag.ask("Where is RetailCo based?")
print(result["answer"])
print(result["sources"]) # chunks that fit in the context budget
add_textsandadd_documents_chunkedstore the text inmetadata[text_field], so it is available at retrieval time. Chunk IDs are<doc id>__0000,<doc id>__0001, …, and each chunk's metadata includeschunk_indexandparent_id.retrievenormalizes Weaviate and Pinecone results intoRetrievedChunkobjects, sorted by score (higher is better). Weaviate distances are converted to1 / (1 + distance).askpacks retrieved chunks into the prompt up tomax_context_chars, asks the LLM to cite them as[1],[2], … (cite_inline=True), and returns{"answer", "sources", "retrieved"}. Passprompt_template(with{context}and{question}) to customize the prompt, andcallbackto extract the answer text from your LLM's response (default: OpenAIchoices[0].message.content).