The Vespa sample applications are created to run both self-hosted and on Vespa Cloud.
You can easily deploy the sample applications to Vespa Cloud without changing the files -
just follow the same steps as for
Managed Vector Search using Vespa Cloud,
adding security credentials.
First-time users should go through the getting-started guides first.
Explore the examples for smaller applications helping you getting started with a particular feature,
and see operations for operational examples.
Standard structure of a Sample Application
We try to build each sample application with a standard structure, so you can
easily find your way around. This section gives you an overview of this structure.
There might be other files and folders than the ones listed here, but this should be the bare minimum that you can expect.
Let's analyze the structure:
README.md - self explainatory: the README specific for the sample application, we recommend reading it through.
dataset/ - contains the dataset used for the sample application. This is usually a small set of documents, but it can be larger.
Note: Sometimes this might be missing, and will be generated by the build script (see below), this is usually because the dataset is too large to be included in the repository.
app/ - contains the Vespa application package, this is the actual definition of the Vespa deployment. The bare minimum includes:
security/ - this is where you will place your clients.pem certificate for data-plane authentication. (Refer to our Security Guide)
schemas/ - contains the schema files used for the application. This is usually a single file, but it can be multiple files.
services.xml - contains the services configuration for the application. This is usually a single file.
Other files and folders that are required for the application to run.
script/ - contains the optional scripts used to help building the application package. This is usually a single file, but it can be multiple files.
build.sh - this is the main script, if multiple files are present, this will be the only one you'll need to worry about.
Note: We recomend refering to the README for the sample application for details on how to run it.
[!NOTE]
We are in the process of updating the sample applications to follow the
structure described here, but some applications may not be fully updated
yet, so please check the README files in each application for details.
Getting Started
Album Recommendations is the intro application to Vespa.
Learn how to configure the schema for simple recommendation and search use cases.
Pyvespa: Querying Vespa
is a good start for Python users, exploring how to query Vespa using the Vespa Query Language (YQL).
Pyvespa: Read and write operations
documents ways to feed, get, update, and delete data;
Using context manager for efficiently managing resources and feeding streams of data using feed_iter,
which can feed from streams, Iterables, Lists, and files by the use of generators.
Pyvespa: Examples
is a repository of small snippets and examples, e.g., really simple vector distance search applications.
The News and Recommendation Tutorial
demonstrates basic search functionality and is a great place to start exploring Vespa features.
It creates a recommendation system where the approximate nearest neighbor search in a shared user/item embedding space
is used to retrieve recommended content for a user.
This app also demonstrates using parent-child relationships.
There is a growing interest in AI-powered vector representations of unstructured multimodal data
and searching efficiently over these representations.
Managed Vector Search using Vespa Cloud
describes how to unlock the full potential of multimodal AI-powered vector representations using Vespa Cloud.
Customizing Frozen Data Embeddings in Vespa
demonstrates how to adapt frozen embeddings from foundational embedding models -
see the blog post.
Frozen data embeddings from foundational models is an emerging industry practice
for reducing the complexity of maintaining and versioning embeddings.
The frozen data embeddings are re-used for various tasks, such as classification, search, or recommendations.
Pyvespa: Using Cohere Binary Embeddings in Vespa
demonstrates how to use the Cohere binary vectors with Vespa,
including a re-ranking phase that uses the float query vector version for improved accuracy.
Pyvespa: Exploring the potential of OpenAI Matryoshka 🪆 embeddings with Vespa
demonstrates the effectiveness of using the recently released (as of January 2024) OpenAI text-embedding-3 embeddings with Vespa.
Specifically, we are interested in the Matryoshka Representation Learning technique used in training,
which lets us "shorten embeddings (i.e., remove some numbers from the end of the sequence) without the embedding losing its concept-representing properties".
This allows us to trade off a small amount of accuracy in exchange for much smaller embedding sizes,
so we can store more documents and search them faster.
Retrieval Augmented Generation (RAG) in Vespa
is an end-to-end RAG application where all the steps are run within Vespa.
This application focuses on the generation part of RAG,
with a simple text search using BM25.
This application has three versions of an end-to-end RAG application:
Using an external LLM service to generate the final response.
Using local LLM inference to generate the final response.
Deploying to Vespa Cloud and using GPU-accelerated LLM inference to generate the final response.
This includes using Vespa Cloud's Secret Store
to save the OpenAI API key.
Visual Retrieval with ColPali
is a self-contained web app (Python + FastHTML) that pairs a frontend with a
Vespa backend for visual PDF retrieval using ColPali — the runnable companion to the pyvespa notebook below.
Pyvespa: Vespa 🤝 ColPali: Efficient Document Retrieval with Vision Language Models
demonstrates how to retrieve PDF pages using the embeddings generated by the ColPali model.
ColPali is a powerful Vision Language Model (VLM) that can generate embeddings for images and text.
This notebook uses ColPali to generate embeddings for images of PDF pages and store them in Vespa.
We also store the base64-encoded image of the PDF page and some metadata like title and url.
Pyvespa: ColPali Ranking Experiments on DocVQA
shows how to reproduce the ColPali results on DocVQA with Vespa.
The dataset consists of PDF documents with questions and answers.
We demonstrate how we can binarize the patch embeddings
and replace the float MaxSim scoring
with a hamming-based MaxSim
without much loss in ranking accuracy but with a significant speedup (close to 4x) and reducing the memory (and storage) requirements by 32x.
Billion-Scale Image Search
demonstrates billion-scale image search using a CLIP model
exported in ONNX-format for retrieval.
It features separation of compute from storage and query-time vector similarity de-duping.
It uses PCA to reduce from 768 to 128 dimensions.
Video Search
Text-video search is a notebook that
downloads a set of videos, converts from .avi to .mp4, creates CLIP embeddings,
feeds to Vespa and lets you query the videos in text using a Streamlit application.
It is a good start for creating a video search application using Vespa!
Video Search and Retrieval with Vespa and TwelveLabs is a notebook
showcasing the use of TwelveLabs state-of-the-art generation and embedding models
for video processing. It demonstrates how to generate rich metadata (including summaries and keywords) for videos
using TwelveLabs' technology, and how to embed video chunks for efficient retrieval. The notebook processes three
sample videos, segments them into chunks, and stores their embeddings along with metadata in Vespa's multi-vector
tensors. You can perform hybrid searches to find specific video scenes based on natural language descriptions.
This serves as an excellent starting point for implementing advanced video retrieval with Vespa!
Ranking
MS Marco Passage Ranking
shows how to represent state-of-the-art text ranking using Transformer (BERT) models.
It uses the MS Marco passage ranking datasets and features
bi-encoders, cross-encoders, and late-interaction models (ColBERT):
Simple single-stage sparse retrieval accelerated by the
WAND
dynamic pruning algorithm with BM25 ranking.
Hypencoder: query-dependent neural ranking
shows how to run Hypencoder in Vespa.
Hypencoder is a neural ranking method where the query creates a small scoring network,
and that network scores each document embedding.
The sample exports the model to ONNX, uses the hugging-face-embedder
for document embeddings, and implements the query-specific scoring network with Vespa tensor expressions.
Compress token vectors using binarization compatible with Vespa's unpack_bits used in ranking.
This implements the binarization of token-level vectors using numpy.
As a bonus, this also demonstrates how to use ColBERT end-to-end with Vespa for both retrieval and ranking.
The retrieval step searches the binary token-level representations using hamming distance.
This uses 32 nearestNeighbor operators in the same query, each finding 100 nearest hits in hamming space.
Then, the results are re-ranked using the full-blown MaxSim calculation.
Long-Context ColBERT
demonstrates Long-Context ColBERT (multi-token vector representation) with extended context windows for long-document retrieval,
as announced in Vespa Long-Context ColBERT.
The app demonstrates the colbert-embedder
and the tensor expressions for performing two types of extended ColBERT late-interaction for long-context retrieval.
This app uses trec-eval for evaluation using
nDCG.
The e-commerce application is an end-to-end shopping engine,
using the Amazon product data set.
This use case bundles a front-end application.
It demonstrates building next-generation E-commerce Search using Vespa,
and is a good intro to using the Vespa Cloud CI/CD tests.
Incremental Search shows search-as-you-type functionality,
where for each keystroke of the user, it retrieves matching documents.
It also demonstrates search suggestions (query auto-completion).
Vespa as ML inference server
Stateless model evaluation demonstrates
using Vespa as a stateless ML model inference server
where Vespa takes care of distributing ML models to multiple serving containers,
offering horizontal scaling and safe deployment.
It features model versioning and a feature processing pipeline,
as well as using custom code in Searchers,
Document Processors and
Request Handlers.
Vespa Documentation Search
Vespa Documentation Search
is the search application that powers search.vespa.ai -
refer to this for GitHub Actions automation.
This sample app is a good start for automated deployments,
as it has system, staging and production test examples.
It uses the Document API
both for regular PUT operations but also for UPDATE with create-if-nonexistent.
It also has Vespa Components
for custom code.