From 9e8984a7f3cf58977d26bb659004f4490271d165 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Thu, 13 Nov 2025 14:13:48 +0530 Subject: [PATCH 1/7] Update note to support GitHub rendering Signed-off-by: Srihari Thyagarajan --- examples/README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/README.md b/examples/README.md index ac618127a..6163f67e7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -52,8 +52,6 @@ Check out our [examples documentation](https://cocoindex.io/docs/examples) for m - 🛍️ [**product_recommendation**](./product_recommendation) - Build real-time recommendation engine with LLM and graph database ---- - -> **Note**: New to CocoIndex? Check out the [Getting Started](https://cocoindex.io/docs/getting_started) guide first! -> -> **Contribute**: We welcome contributions! Submit a [pull request](https://github.com/cocoindex-io/cocoindex/pulls) to add more examples. +> [!NOTE] +> New to CocoIndex? Check out the [Getting Started](https://cocoindex.io/docs/getting_started) guide first! +We also welcome contributions! Submit a [pull request](https://github.com/cocoindex-io/cocoindex/pulls) to add more examples. From 6516c6a94330347fa52c841424c75ebe07b18030 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:06:28 +0530 Subject: [PATCH 2/7] feat: add support for `additionalProperties` option in JSON schema generation --- rust/cocoindex/src/base/json_schema.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rust/cocoindex/src/base/json_schema.rs b/rust/cocoindex/src/base/json_schema.rs index e001e9dfe..1a663337e 100644 --- a/rust/cocoindex/src/base/json_schema.rs +++ b/rust/cocoindex/src/base/json_schema.rs @@ -21,6 +21,10 @@ pub struct ToJsonSchemaOptions { /// If true, the top level must be a JSON object. pub top_level_must_be_object: bool, + + /// If true, include `additionalProperties: false` in object schemas. + /// Some LLM APIs (e.g., Gemini) do not support this constraint and will error. + pub supports_additional_properties: bool, } struct JsonSchemaBuilder { @@ -263,7 +267,11 @@ impl JsonSchemaBuilder { .filter(|&f| self.options.fields_always_required || !f.value_type.nullable) .map(|f| f.name.to_string()) .collect(), - additional_properties: Some(Schema::Bool(false).into()), + additional_properties: if self.options.supports_additional_properties { + Some(Schema::Bool(false).into()) + } else { + None + }, ..Default::default() })); schema @@ -406,6 +414,7 @@ mod tests { supports_format: true, extract_descriptions: false, top_level_must_be_object: false, + supports_additional_properties: true, } } @@ -415,6 +424,7 @@ mod tests { supports_format: true, extract_descriptions: true, top_level_must_be_object: false, + supports_additional_properties: true, } } @@ -424,6 +434,7 @@ mod tests { supports_format: true, extract_descriptions: false, top_level_must_be_object: false, + supports_additional_properties: true, } } @@ -433,6 +444,7 @@ mod tests { supports_format: true, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: true, } } @@ -1357,6 +1369,7 @@ mod tests { supports_format: false, extract_descriptions: false, top_level_must_be_object: false, + supports_additional_properties: true, }; let result = build_json_schema(value_type, options).unwrap(); let json_schema = schema_to_json(&result.schema); @@ -1396,6 +1409,7 @@ mod tests { supports_format: true, extract_descriptions: false, // We want to see the description in the schema top_level_must_be_object: false, + supports_additional_properties: true, }; let result = build_json_schema(enriched_value_type, options).unwrap(); From 950715209edb8c80aa3d96dda1adafc92a2ff5e8 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:07:12 +0530 Subject: [PATCH 3/7] `feat`: enable support for additional properties --- rust/cocoindex/src/llm/anthropic.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/cocoindex/src/llm/anthropic.rs b/rust/cocoindex/src/llm/anthropic.rs index c84e2c483..3a3b4baa1 100644 --- a/rust/cocoindex/src/llm/anthropic.rs +++ b/rust/cocoindex/src/llm/anthropic.rs @@ -164,6 +164,7 @@ impl LlmGenerationClient for Client { supports_format: false, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: true, } } } From 0d0109eecabdd541d96011294ee966c97940186a Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:07:27 +0530 Subject: [PATCH 4/7] `feat`: add support for additional properties in LlmGenerationClient --- rust/cocoindex/src/llm/bedrock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/cocoindex/src/llm/bedrock.rs b/rust/cocoindex/src/llm/bedrock.rs index 0f5f99035..00baccd45 100644 --- a/rust/cocoindex/src/llm/bedrock.rs +++ b/rust/cocoindex/src/llm/bedrock.rs @@ -174,6 +174,7 @@ impl LlmGenerationClient for Client { supports_format: false, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: true, } } } From 821c9695ef6e9c29e0f4eea1a51aaef7f6e34ea7 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:07:53 +0530 Subject: [PATCH 5/7] `refactor`: remove unused `remove_additional_properties` function and simplify JSON schema handling in `LlmGenerationClient` --- rust/cocoindex/src/llm/gemini.rs | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/rust/cocoindex/src/llm/gemini.rs b/rust/cocoindex/src/llm/gemini.rs index 0e6ce1bce..cd1b49e8d 100644 --- a/rust/cocoindex/src/llm/gemini.rs +++ b/rust/cocoindex/src/llm/gemini.rs @@ -49,24 +49,6 @@ impl AiStudioClient { } } -// Recursively remove all `additionalProperties` fields from a JSON value -fn remove_additional_properties(value: &mut Value) { - match value { - Value::Object(map) => { - map.remove("additionalProperties"); - for v in map.values_mut() { - remove_additional_properties(v); - } - } - Value::Array(arr) => { - for v in arr { - remove_additional_properties(v); - } - } - _ => {} - } -} - impl AiStudioClient { fn get_api_url(&self, model: &str, api_name: &str) -> String { format!( @@ -149,8 +131,7 @@ impl LlmGenerationClient for AiStudioClient { // If structured output is requested, add schema and responseMimeType if let Some(OutputFormat::JsonSchema { schema, .. }) = &request.output_format { - let mut schema_json = serde_json::to_value(schema)?; - remove_additional_properties(&mut schema_json); + let schema_json = serde_json::to_value(schema)?; payload["generationConfig"] = serde_json::json!({ "responseMimeType": "application/json", "responseSchema": schema_json @@ -181,6 +162,7 @@ impl LlmGenerationClient for AiStudioClient { supports_format: false, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: false, } } } @@ -379,6 +361,7 @@ impl LlmGenerationClient for VertexAiClient { supports_format: false, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: false, } } } From b573961358bc37eeda1efeebc8b75162ea6cd860 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:08:07 +0530 Subject: [PATCH 6/7] `feat`: enable support for additional properties --- rust/cocoindex/src/llm/ollama.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/cocoindex/src/llm/ollama.rs b/rust/cocoindex/src/llm/ollama.rs index b02a6ddc3..35c93bfc8 100644 --- a/rust/cocoindex/src/llm/ollama.rs +++ b/rust/cocoindex/src/llm/ollama.rs @@ -120,6 +120,7 @@ impl LlmGenerationClient for Client { supports_format: true, extract_descriptions: true, top_level_must_be_object: false, + supports_additional_properties: true, } } } From eea15b1f3ff58b047ace9107db79da1fdf3ab122 Mon Sep 17 00:00:00 2001 From: Srihari Thyagarajan Date: Sat, 22 Nov 2025 11:08:30 +0530 Subject: [PATCH 7/7] feat: help for additional properties in `LlmGenerationClient` config --- rust/cocoindex/src/llm/openai.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/cocoindex/src/llm/openai.rs b/rust/cocoindex/src/llm/openai.rs index 67a23be35..853166a2a 100644 --- a/rust/cocoindex/src/llm/openai.rs +++ b/rust/cocoindex/src/llm/openai.rs @@ -162,6 +162,7 @@ impl LlmGenerationClient for Client { supports_format: false, extract_descriptions: false, top_level_must_be_object: true, + supports_additional_properties: true, } } }