Package com.tnsai.tools.database
Class WeaviateTools
java.lang.Object
com.tnsai.tools.database.WeaviateTools
Function-shape Weaviate vector-database tools — the LangChain-style
replacement for the Weaviate half of the legacy
VectorDBTool
(#188). Sister POJO to QdrantTools (Phase 2 batch 5d).
Five typed @Tool methods covering Weaviate's REST + GraphQL hybrid API:
| Method | Endpoint | Idempotent |
|---|---|---|
weaviateClasses() | GET /v1/schema | ✓ |
weaviateCount(java.lang.String) | POST /v1/graphql (Aggregate) | ✓ |
weaviateSearch(java.lang.String, java.util.List<java.lang.Double>, int) | POST /v1/graphql (Get + nearVector) | ✓ |
weaviateCreateClass(java.lang.String) | POST /v1/schema | ✓ (idempotent on identical body) |
weaviateUpsert(java.lang.String, java.util.List<java.util.Map<java.lang.String, java.lang.Object>>) | POST /v1/objects (per object) | ✓ (Weaviate uses uuid; same uuid replaces) |
Class-name convention
Weaviate requires class names to start with an uppercase letter
("Documents", not "documents"). The LLM doesn't need to remember that —
the POJO capitalises class names automatically before sending the request,
matching the legacy VectorDBTool's behaviour.
- Since:
- 0.5.7 (Phase 2 batch 5e — built-in tool migration to function shape, see #188)
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — picksWEAVIATE_URL+WEAVIATE_API_KEYfrom env.WeaviateTools(String baseUrl) Explicit URL constructor (no API key — for local / unauthenticated Weaviate).WeaviateTools(String baseUrl, String apiKey) Explicit URL + API key constructor (Weaviate Cloud / WCS).WeaviateTools(String baseUrl, String apiKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests or shared HTTP/JSON instances. -
Method Summary
Modifier and TypeMethodDescriptionweaviateCount(String collection) weaviateCreateClass(String collection) weaviateSearch(String collection, List<Double> vector, int limit)
-
Constructor Details
-
WeaviateTools
public WeaviateTools()Default constructor — picksWEAVIATE_URL+WEAVIATE_API_KEYfrom env. -
WeaviateTools
Explicit URL constructor (no API key — for local / unauthenticated Weaviate). -
WeaviateTools
Explicit URL + API key constructor (Weaviate Cloud / WCS). -
WeaviateTools
public WeaviateTools(String baseUrl, String apiKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests or shared HTTP/JSON instances.
-
-
Method Details
-
weaviateClasses
@Tool(name="weaviate_classes", description="List all classes in the configured Weaviate schema. Returns the class names as a string array. Read-only.", keywords={"weaviate","vector","schema","classes","list"}, idempotent=true) public List<String> weaviateClasses() throws IOException- Throws:
IOException
-
weaviateCount
@Tool(name="weaviate_count", description="Count the objects in a Weaviate class via the Aggregate GraphQL API. Returns {\"class\": \u2026, \"count\": N}. Class names are auto-capitalised (Weaviate requires the first letter uppercase). Read-only.", keywords={"weaviate","vector","count","aggregate"}, idempotent=true) public Map<String,Object> weaviateCount(@ToolParam(description="Class name (will be capitalised \u2014 \"docs\" \u2192 \"Docs\")") String collection) throws IOException - Throws:
IOException
-
weaviateSearch
@Tool(name="weaviate_search", description="Find the {limit} most similar objects to the query vector in a Weaviate class via the GraphQL Get + nearVector API. Returns a list of {id, distance} maps. Class name is auto-capitalised. Read-only.", keywords={"weaviate","vector","search","similarity","nearvector","rag","knn"}, idempotent=true) public List<Map<String,Object>> weaviateSearch(@ToolParam(description="Class name (will be capitalised)") String collection, @ToolParam(description="Query vector \u2014 array of floats matching the class\'s vector dimension") List<Double> vector, @ToolParam(description="Number of results (1..1000); 0 falls back to default 10",required=false,defaultValue="0") int limit) throws IOException - Throws:
IOException
-
weaviateCreateClass
@Tool(name="weaviate_create_class", description="DESTRUCTIVE: create a Weaviate class (collection). Class name is auto-capitalised. Idempotent on identical config; calling with different config on an existing class is an error from Weaviate\'s side. {dimension} is advisory \u2014 Weaviate auto-detects the dimension on first object insert if you don\'t pass a vectoriser config.", keywords={"weaviate","vector","create","schema","class"}, idempotent=true) public Map<String,Object> weaviateCreateClass(@ToolParam(description="Class name (will be capitalised)") String collection) throws IOException - Throws:
IOException
-
weaviateUpsert
@Tool(name="weaviate_upsert", description="DESTRUCTIVE: insert or update objects in a Weaviate class. Each {objects[i]} is a {vector?, payload?} map; vector is the pre-computed embedding, payload populates the class\'s properties. Class name is auto-capitalised. Each object is POSTed individually (Weaviate\'s REST API does not bulk-insert via /v1/objects). Returns {class, total, succeeded}.", keywords={"weaviate","vector","upsert","insert","embedding"}, idempotent=true) public Map<String,Object> weaviateUpsert(@ToolParam(description="Class name (will be capitalised)") String collection, @ToolParam(description="Objects \u2014 list of {vector, payload?} maps") List<Map<String, Object>> objects) throws IOException- Throws:
IOException
-