Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vector service concept, and resource endpoint to handle vector search #33

Merged
merged 25 commits into from
Sep 14, 2023

Conversation

sd2k
Copy link
Contributor

@sd2k sd2k commented Sep 7, 2023

This cannibalizes some of #23 but focusses on the read path: adding a resource endpoint to the plugin to search a configured vector store using the configured embedding engine.

It adds:

  • a store package for interacting with various vector stores
    • the interfaces are split into ReadVectorStore and WriteVectorStore so we don't need to implement everything right now (we could remove the write interface for now since it's not being used yet)
    • there's an implementation for the pending Grafana vectorapi here too; I can copy a qdrant one from a draft Grafana PR later on as another example
  • an embed package for interacting with embedding engines
    • there's an implementation here for OpenAI embeddings (which vectorapi is also compatible with); more can be added as-and-when
  • a vector package which wraps and combines objects from these two packages and utilises them to provide a user-friendly service to search for related text, handling the mapping from collection -> model and the embedding process
  • an resource endpoint /vector/search, which frontend clients can use to do search for related objects in various collections
  • another docker-compose service for the vectorapi to be deployed, and extra provisioning for the app including more config to talk to the vectorapi service. This will probably need to be removed for now though since vectorapi isn't OSS yet.

Some decisions made here:

  • collection details are specified in config; specifically this means each collection has exactly one associated model and dimension
    • this is specified in config rather than anywhere else right now because the vector service is responsible for embedding the query using the same model and dimension as the vectors in the collection
    • in theory this could go somewhere else but we can't make many assumptions about what each vector DB implementation lets you store, so config is a fairly safe denominator
    • ideally this would be shared with whatever sync service we end up using, so that they both use the same embedding model for each collection, and the same collection names for each type of object.
  • we have interfaces for vector.Store and embed.Embedder so we can have various concrete implementations, such as Qdrant/Milvus/Weaviate for the store or OpenAI/custom APIs for the embedder. This PR only adds a single one for each though, and we may end up abstracting over stores in vectorapi instead
  • there's a collection in the provisioned config named grafana:core:dashboards. The naming convention here is completely open to bikeshedding. The idea is to scope collections similarly to the way Grafana Live channels are scoped (the : can be replaced with / for consistency)

Testing this is a little tricky right now because we don't have open images for vectorapi, or a process for getting data into the vectorapi store. One way to do so is:

  • build vectorapi using make
  • run docker-compose up in this repository
  • run poetry run python -m src.dashboards.index --directory ./src/dashboards/output from the vector-playground directory of the llm-experiment-lab repository, on the vectordb-playground-vectorapi branch. This will send a bunch of dashboards into the grafana:core:dashboards collection, ready for searching
  • call the resource endpoint with curl http://localhost:3000/api/plugins/grafana-llm-app/resources/vector/search -d '{"collection": "grafana:core:dashboards", "text": "Mimir usage", "limit": 3}'

@sd2k sd2k requested a review from yoziru September 7, 2023 10:26
…arch

This cannibalizes some of #23 but focusses on the read path: searching a
configured vector store using the configured embedding engine.
@sd2k sd2k marked this pull request as ready for review September 8, 2023 09:42
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 8, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 8, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 8, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
sd2k added a commit that referenced this pull request Sep 12, 2023
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
sd2k added a commit that referenced this pull request Sep 12, 2023
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
sd2k added a commit that referenced this pull request Sep 12, 2023
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
sd2k added a commit that referenced this pull request Sep 12, 2023
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
src/plugin.json Outdated Show resolved Hide resolved
sd2k added a commit that referenced this pull request Sep 12, 2023
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
PR #33 can't really be merged until we open-source and package up
vectorapi, so this commit adds a qdrant implementation and modifies
the provisioning file to use it (and OpenAI) by default, rather than
vectorapi.
Otherwise the payloads are JSON marshaled like this:

```json
{"results":[{"payload":{"description":{"Kind":{"NullValue":0}},"panels":{"Kind":{"ListValue":{"values":[{"Kind":{"StructValue":{"fields":{"description":{"Kind":{"StringValue":"CPU usage of Mimir"}},"title":{"Kind":{"StringValue":"CPU usage"}}}}}}]}}},"title":{"Kind":{"StringValue":"Mimir resource usage"}}},"score":0.7932371497154236}]}
```

instead of what we want (after this PR):

```json
{"results":[{"payload":{"description":null,"panels":[{"description":"CPU usage of Mimir","title":"CPU usage"}],"title":"Mimir resource usage"},"score":0.7932371497154236}]}
```
Add qdrant read vector store implementation
Copy link
Collaborator

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Let's get this going and iterate on it as we get more data into vector dbs!

Qdrant doesn't allow ':' in collection names, so replace them with
'.'. In future we might want to follow their [recommendations]
and only using one collection but this will work for now.

[recommendations]: https://qdrant.tech/documentation/faq/qdrant-fundamentals/#how-many-collections-can-i-create
Also tidy up some settings which were getting a bit messy,
and fix secret handling (they shouldn't be in JSON data)
Copy link
Contributor

@yoziru yoziru left a comment

Choose a reason for hiding this comment

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

alright lgtm, provisioning needs some better docs or maybe less nesting but the core concepts work well 👍

@sd2k sd2k merged commit b605e7b into main Sep 14, 2023
3 checks passed
@sd2k sd2k deleted the vector-service branch September 14, 2023 09:34
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 14, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
sd2k added a commit that referenced this pull request Sep 14, 2023
This was moved around as part of #33, should be fixed by this commit.
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 14, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
sd2k added a commit to grafana/grafana-experimental that referenced this pull request Sep 14, 2023
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
SandersAaronD pushed a commit that referenced this pull request Oct 27, 2023
This adds convenience functions to access the endpoints added in
#33.
SandersAaronD pushed a commit that referenced this pull request Oct 30, 2023
This adds convenience functions to access the endpoints added in
#33.
SandersAaronD pushed a commit that referenced this pull request Oct 31, 2023
This adds convenience functions to access the endpoints added in
#33.
SandersAaronD pushed a commit to grafana/grafana-experimental that referenced this pull request Jan 10, 2024
This adds convenience functions to access the endpoints added in
grafana/grafana-llm-app#33.
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.

3 participants