Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

%load_ext autoreload
%autoreload 2
import mycode.vap as vap
# The goal is to check if the `fast-search` on attribute used as match-phase limiter is needed.
app = vap.demo_application_package()
from vespa.package import Field, RankProfile, MatchPhaseRanking, FirstPhaseRanking

app.get_schema().add_fields(
    Field(name="id_no_fast_search", type="int", indexing="attribute"),
)
app.get_schema().add_rank_profile(
    RankProfile(
        name="match_phase_fast_search",
        match_phase=MatchPhaseRanking(
            attribute="id_no_fast_search",
            order="descending",
            max_hits=10000,
        ),
        first_phase=FirstPhaseRanking(
            expression="attribute(id_no_fast_search)",
        )
    )
)
print(app.get_schema().schema_to_text)
schema doc {
    document doc {
        field id type int {
            indexing: attribute
            attribute {
                fast-search
            }
        }
        field id_no_fast_search type int {
            indexing: attribute
        }
    }
    rank-profile fields inherits unranked {
        function id() {
            expression {
                attribute(id)
            }
        }
        first-phase {
            expression {
                0
            }
        }
        summary-features {
            id
        }
        match-features {
            id
        }
    }
    rank-profile match_phase_fast_search {
        match-phase {
            attribute: id_no_fast_search
            order: descending
            max-hits: 10000
        }
        first-phase {
            expression {
                attribute(id_no_fast_search)
            }
        }
    }
}
from vespa.deployment import VespaDocker

# In case running colima on macos run the following
# !sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock
vespa_docker = VespaDocker(
    container_image="vespaengine/vespa:8.657.27",
)
# Start a docker container and deploy the application package
client = vespa_docker.deploy(
    application_package=app,
)
Waiting for configuration server, 0/60 seconds...
Waiting for configuration server, 5/60 seconds...
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[18], line 9
      5 vespa_docker = VespaDocker(
      6     container_image="vespaengine/vespa:8.657.27",
      7 )
      8 # Start a docker container and deploy the application package
----> 9 client = vespa_docker.deploy(
     10     application_package=app,
     11 )

File ~/IdeaProjects/notes/.venv/lib/python3.13/site-packages/vespa/deployment.py:225, in VespaDocker.deploy(self, application_package, max_wait_configserver, max_wait_deployment, max_wait_docker, debug)
    204 def deploy(
    205     self,
    206     application_package: ApplicationPackage,
   (...)    210     debug: bool = False,
    211 ) -> Vespa:
    212     """
    213     Deploy the application package into a Vespa container.
    214 
   (...)    223         VespaConnection: A Vespa connection instance once the deployment is complete.
    224     """
--> 225     return self._deploy_data(
    226         application_package,
    227         application_package.to_zip(),
    228         max_wait_configserver=max_wait_configserver,
    229         max_wait_application=max_wait_deployment,
    230         docker_timeout=max_wait_docker,
    231         debug=debug,
    232     )

File ~/IdeaProjects/notes/.venv/lib/python3.13/site-packages/vespa/deployment.py:429, in VespaDocker._deploy_data(self, application, data, debug, max_wait_configserver, max_wait_application, docker_timeout)
    427     raise RuntimeError(f"Deployment request failed: {str(e)}") from e
    428 if r.status_code != 200:
--> 429     raise RuntimeError(
    430         "Deployment failed, code: {}, message: {}".format(
    431             r.status_code, json.loads(r.content.decode("utf8"))
    432         )
    433     )
    435 app = Vespa(url=self.url, port=self.local_port, application_package=application)
    436 app.wait_for_application_up(max_wait=max_wait_application)

RuntimeError: Deployment failed, code: 400, message: {'error-code': 'INVALID_APPLICATION_PACKAGE', 'message': "Invalid application: In search definition 'doc', rank-profile 'match_phase_fast_search': match-phase attribute 'id_no_fast_search' must be fast-search, but it is not"}
# yes, vespa rejects match phase on attribute without fast-search