feat: qa vector db#3393
Draft
nsantacruz wants to merge 9 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces vector search and indexing capabilities to the project, supporting both pgvector (PostgreSQL extension) and Qdrant (a vector database). It adds new API endpoints for vector search and indexing, provides helper functions for interacting with both backends, and includes infrastructure changes to support Qdrant in both Docker Compose and Helm deployments. Additionally, scripts for initializing and benchmarking the vector databases are included.
API and Backend Functionality:
api/v3/vector-search/<backend>andapi/v3/vector-index/<backend>insefaria/urls_shared.pyand implemented correspondingVectorSearchandVectorIndexview classes to handle search and indexing requests for both pgvector and Qdrant backends. ([[1]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-8f355aa80bd3ead68ed63deaf8856b8ae9f3d71a6234d67dfe6cbcdb984e19e0R79-R80),[[2]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-7fb412808754eb12ee1b172c34c44eb9ce58b3bba43d62ffcb986ad7917588a8R71-R105))sefaria/helper/vector_search.pyfor searching and indexing embeddings in both pgvector and Qdrant, including connection management and payload formatting. ([sefaria/helper/vector_search.pyR1-R63](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-b9c1eba71d65731c93bd67ebbd7ade5fbc3bf3308798892dc229c37e2b9e2494R1-R63))Infrastructure and Configuration:
pgvector/pgvector:pg17image for PostgreSQL and added a Qdrant service with persistent storage. ([[1]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-e45e45baeda1c1e73482975a664062aa56f20c03dd9d64a827aba57775bed0d3L37-R37),[[2]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-e45e45baeda1c1e73482975a664062aa56f20c03dd9d64a827aba57775bed0d3R47-R58))helm-chart/sefaria/templates/qdrant.yaml) and related configuration (helm-chart/sefaria/values.yaml) to support deploying Qdrant in Kubernetes environments. ([[1]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-90f91964db768066b22da07d30ec6e487cca2d09b558055050749d34df67b7c1R1-R78),[[2]](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-f456df0f77726a2691872d2aafe48fcc6416f34f51ba3652644a9e56ed096125R93-R104))sefaria/settings.pyfor Qdrant host, port, collection name, and vector dimensions. ([sefaria/settings.pyR313-R317](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-527bb6e93208e6b52293bab4c87f3ef11938f72d3b22b04a36df5c077c1016e5R313-R317))Utility Scripts:
scripts/init_vector_dbs.pyto initialize the pgvector table and Qdrant collection for storing embeddings. ([scripts/init_vector_dbs.pyR1-R56](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-59d33840dfa99e488ff4febdd47d7585024df3a2e4f9536943b06118d34bf35dR1-R56))scripts/benchmark_vector_dbs.pyto benchmark latency between pgvector and Qdrant using pre-embedded query vectors via the new API endpoints. ([scripts/benchmark_vector_dbs.pyR1-R82](https://github.com/Sefaria/Sefaria-Project/pull/3393/files#diff-6cf414a305699141dbdce8532c122f844ae6a90bd86684969c297b8fc027153eR1-R82))