Skip to content

Support multiple index statements in Field definitions#1097

Merged
thomasht86 merged 7 commits into
masterfrom
copilot/fix-983-2
Jul 30, 2025
Merged

Support multiple index statements in Field definitions#1097
thomasht86 merged 7 commits into
masterfrom
copilot/fix-983-2

Conversation

Copilot AI commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

This PR implements support for multiple index statements in Vespa Field definitions, addressing a limitation where fields could only have a single index configuration.

Problem

Previously, the schema template was hardcoded to render only one index statement per field:

index: {{ field.index }}

This prevented defining fields with complex index configurations like:

field predicate_field type predicate {
    indexing: attribute
    index {
        arity: 2
        lower-bound: 3
        upper-bound: 200
        dense-posting-list-threshold: 0.25
    }
}

Or fields requiring multiple index blocks with different configurations.

Solution

The implementation extends the Field class to accept multiple index configurations while maintaining full backward compatibility:

API Changes

The index parameter now accepts:

  • String (existing): index="enable-bm25"
  • Dict (existing): index={"arity": 2, "lower-bound": 3}
  • List (new): index=["enable-bm25", {"arity": 2}, "another-setting"]

Examples

Single complex index block (from original issue):

Field(
    name="predicate_field",
    type="predicate", 
    indexing=["attribute"],
    index={
        "arity": 2,
        "lower-bound": 3,
        "upper-bound": 200,
        "dense-posting-list-threshold": 0.25
    }
)

Multiple index configurations:

Field(
    name="complex_field",
    type="string",
    index=[
        "enable-bm25",              # Simple setting
        {"arity": 2, "lower-bound": 3},  # Complex block
        "another-setting"           # Another simple setting
    ]
)

Parameterless index settings:

Field(
    name="taxonomy", 
    type="array<string>",
    index={"enable-bm25": None}  # Renders as just "enable-bm25"
)

Template Updates

Updated Jinja2 templates to iterate over multiple index configurations and handle parameterless settings (None values render without : None).

Backward Compatibility

All existing code continues to work unchanged. The new functionality is additive and doesn't break any existing Field definitions.

Testing

Added comprehensive test suite with 11 test cases covering:

  • Backward compatibility verification
  • Multiple index configuration scenarios
  • Mixed string/dict configurations
  • ANN field integration
  • Edge case handling

Fixes #983.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: thomasht86 <24563696+thomasht86@users.noreply.github.com>
Copilot AI changed the title [WIP] Support multiple index statements in Field-definition Support multiple index statements in Field definitions Jul 29, 2025
Copilot AI requested a review from thomasht86 July 29, 2025 06:29
@thomasht86 thomasht86 marked this pull request as ready for review July 29, 2025 09:45

@thomasht86 thomasht86 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good bot! 🤖

@thomasht86 thomasht86 requested a review from kkraune July 30, 2025 05:39
@thomasht86

Copy link
Copy Markdown
Collaborator

@kkraune need another approval since I collaborated with Copilot on this one. 🙏

@kkraune

kkraune commented Jul 30, 2025

Copy link
Copy Markdown
Member

nice work by the robot!

@thomasht86 thomasht86 merged commit d555947 into master Jul 30, 2025
46 of 48 checks passed
@thomasht86 thomasht86 deleted the copilot/fix-983-2 branch July 30, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple index statements in Field-definition

3 participants