mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-23 08:33:09 +00:00
# What does this PR do? - Adds documentation on how to contribute a Vector DB provider. - Updates the testing section to be a little friendlier to navigate. - Also added new shortcut for search so that `/` and `⌘ K` or `ctrl+K` trigger search <img width="1903" height="1346" alt="Screenshot 2025-08-11 at 10 10 12 AM" src="https://github.com/user-attachments/assets/6995b3b8-a2ab-4200-be72-c5b03a784a29" /> <img width="1915" height="1438" alt="Screenshot 2025-08-11 at 10 10 25 AM" src="https://github.com/user-attachments/assets/1f54d30e-5be1-4f27-b1e9-3c3537dcb8e9" /> <!-- If resolving an issue, uncomment and update the line below --> <!-- Closes #[issue-number] --> ## Test Plan <!-- Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.* --> Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
5.1 KiB
5.1 KiB
Adding a New Vector Database
This guide will walk you through the process of adding a new vector database to Llama Stack.
NOTE: Here's an example Pull Request of the Milvus Vector Database Provider.
Vector Database providers are used to store and retrieve vector embeddings. Vector databases are not limited to vector search but can support keyword and hybrid search. Additionally, vector database can also support operations like filtering, sorting, and aggregating vectors.
Steps to Add a New Vector Database Provider
- Choose the Database Type: Determine if your vector database is a remote service, inline, or both.
- Remote databases make requests to external services, while inline databases execute locally. Some providers support both.
- Implement the Provider: Create a new provider class that inherits from
VectorDatabaseProviderand implements the required methods.- Implement methods for vector storage, retrieval, search, and any additional features your database supports.
- You will need to implement the following methods for
YourVectorIndex:YourVectorIndex.create()YourVectorIndex.initialize()YourVectorIndex.add_chunks()YourVectorIndex.delete_chunk()YourVectorIndex.query_vector()YourVectorIndex.query_keyword()YourVectorIndex.query_hybrid()
- You will need to implement the following methods for
YourVectorIOAdapter:YourVectorIOAdapter.initialize()YourVectorIOAdapter.shutdown()YourVectorIOAdapter.list_vector_dbs()YourVectorIOAdapter.register_vector_db()YourVectorIOAdapter.unregister_vector_db()YourVectorIOAdapter.insert_chunks()YourVectorIOAdapter.query_chunks()YourVectorIOAdapter.delete_chunks()
- You will need to implement the following methods for
- Implement methods for vector storage, retrieval, search, and any additional features your database supports.
- Add to Registry: Register your provider in the appropriate registry file.
- Update {repopath}
llama_stack/providers/registry/vector_io.pyto include your new provider.
- Update {repopath}
from llama_stack.providers.registry.specs import InlineProviderSpec
from llama_stack.providers.registry.api import Api
InlineProviderSpec(
api=Api.vector_io,
provider_type="inline::milvus",
pip_packages=["pymilvus>=2.4.10"],
module="llama_stack.providers.inline.vector_io.milvus",
config_class="llama_stack.providers.inline.vector_io.milvus.MilvusVectorIOConfig",
api_dependencies=[Api.inference],
optional_api_dependencies=[Api.files],
description="",
),
- Add Tests: Create unit tests and integration tests for your provider in the
tests/directory.- Unit Tests
- By following the structure of the class methods, you will be able to easily run unit and integration tests for your database.
- You have to configure the tests for your provide in
/tests/unit/providers/vector_io/conftest.py. - Update the
vector_providerfixture to include your provider if they are an inline provider. - Create a
your_vectorprovider_indexfixture that initializes your vector index. - Create a
your_vectorprovider_adapterfixture that initializes your vector adapter. - Add your provider to the
vector_io_providersfixture dictionary.
- Please follow the naming convention of
your_vectorprovider_indexandyour_vectorprovider_adapteras the tests require this to execute properly.
- You have to configure the tests for your provide in
- By following the structure of the class methods, you will be able to easily run unit and integration tests for your database.
- Integration Tests
- Integration tests are located in {repopath}
tests/integration. These tests use the python client-SDK APIs (from thellama_stack_clientpackage) to test functionality. - The two set of integration tests are:
tests/integration/vector_io/test_vector_io.py: This file tests registration, insertion, and retrieval.tests/integration/vector_io/test_openai_vector_stores.py: These tests are for OpenAI-compatible vector stores and test the OpenAI API compatibility.- You will need to update
skip_if_provider_doesnt_support_openai_vector_storesto include your provider as well asskip_if_provider_doesnt_support_openai_vector_stores_searchto test the appropriate search functionality.
- Running the tests in the GitHub CI
- You will need to update the
.github/workflows/integration-vector-io-tests.ymlfile to include your provider. - If your provider is a remote provider, you will also have to add a container to spin up and run it in the action.
- You will need to update the
- Integration tests are located in {repopath}
- Updating the pyproject.yml
- If you are adding tests for the
inlineprovider you will have to update theunitgroup.uv add new_pip_package --group unit
- If you are adding tests for the
remoteprovider you will have to update thetestgroup, which is used in the GitHub CI for integration tests.uv add new_pip_package --group test
- If you are adding tests for the
- Unit Tests
- Update Documentation: Please update the documentation for end users
- Generate the provider documentation by running {repopath}
./scripts/provider_codegen.py. - Update the autogenerated content in the registry/vector_io.py file with information about your provider. Please see other providers for examples.
- Generate the provider documentation by running {repopath}