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

Proposal for vector db semantic convention #1231

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

ezimuel
Copy link

@ezimuel ezimuel commented Jul 10, 2024

This is a proposal for vector db semantic convention (see #936). I tried to expand the db semantic convention adding some db.vector attributes. I tried to focus on the basic needs of a general purpose vector database.

I proposed the following experimental attributes (updated with the feedbacks in this PR):

db.search.similarity_metric: specify the metric used in similarity search (e.g. cosine)
db.record.id: the ID of the record (e.g. the ID of the vector)
db.vector.field_name: the name field of the vector embedding
db.vector.dimension_count: the dimension of the vector (e.g. 1536)
db.vector.query.top_k: the top-k most similar vectors returned by a query (e.g. similarity search)

The operations performed in a vector db, such as insert, update, search and delete can be performed using the existing db.operation.name attribute.

Regarding the similarity search we can use the db.query attributes, such as db.query.parameter.<key>.

@ezimuel ezimuel requested review from a team July 10, 2024 15:14
Copy link

linux-foundation-easycla bot commented Jul 10, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

model/registry/db.yaml Outdated Show resolved Hide resolved
docs/database/dynamodb.md Outdated Show resolved Hide resolved
model/registry/db.yaml Outdated Show resolved Hide resolved
model/registry/db.yaml Outdated Show resolved Hide resolved
brief: >
The dimension of the vector.
examples: [3]
- id: model
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be captured with gen_ai.request.model (and other gen-ai attributes) - it's ok to mix different attributes on the same telemetry item.

Copy link
Author

Choose a reason for hiding this comment

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

This is the model for the embedding and can be different from the gen_ai.request.model. Vector databases are not strictly related with GenAI. There are many use cases where vector db can be used without GenAI (e.g. semantic search).

Copy link
Contributor

Choose a reason for hiding this comment

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

could you provide some examples of databases that can compute embeddings?

How would database instrumentation know which model was used to create embeddings if it only stores and queries them?

Copy link
Author

Choose a reason for hiding this comment

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

Some vendors that provide in-database embedding:

I think many other vendors will add this feature. Having the possibility to generate embeddings in the database simplify the customer use cases.

Regarding the question on how database instrumentation know which model was used to create an embedding this is an information that is specified when you create a collection or when you provide some search (e.g. in PostgreML). Moreover, I think the instrumentation libraries can also leverage this model attribute since they know the embedding model used to generate the vectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems all of them use some GenAI model (in-process or external) and provide an integration layer with it.

I'm not sure what benefit defining a new attribute for databases brings. If embeddings become cross-domain concerns, let's find a generic attribute name for the vectorization model that will be reused between DB and GenAI. For now I strongly recommend to avoid adding new attribute.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I agree that we can wait to see how this topic progresses.

type: int
stability: experimental
brief: >
The dimension of the vector.
Copy link
Contributor

Choose a reason for hiding this comment

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

is it the number of dimensions? let's call it something like db.vector.dimension_count and also update the brief

Copy link
Contributor

Choose a reason for hiding this comment

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

@ezimuel you marked this as resolved, but looks like you missed this change, it still shows dimension instead of dimention_count

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in a3330ff

type: string
stability: experimental
brief: >
The name field as of the vector (e.g. a field name).
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need both - the name and the id?

Copy link
Author

Choose a reason for hiding this comment

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

The id is the identifier of the vector, the name is the field name that contains the vector. Many database uses both but some uses only name of the field. Maybe we should use a better naming here.

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova what do you think about this? Thanks.

Copy link
Contributor

@lmolkova lmolkova Jul 26, 2024

Choose a reason for hiding this comment

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

Could you provide some examples of id and name?

Let's pick a few (2-3) popular databases and explain what id and name would mean in their context.

E.g. I look into MongoDB and I don't understand what id or name would be.

Or I look into Azure Search and don't understand what should go into id.

I look into pinecone and it does not talk about ids.

Also, perhaps by vector you mean index? Or if it's about individual vectors, then how the index would be represented?

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova Here some examples:

  • MongoDB uses name for the field (i.e. path in search here and field-name in the definition here)
  • Azure Search uses name (here)
  • Pinecone uses id (here)
  • Qdrant uses id (Point ID, here)
  • Elasticsearch uses name (here)
  • Milvus uses id (here)
  • Chroma uses id (here)
  • pgvector for PostgreSQL uses name (i.e. the field name with type vector(x), here)
  • Redis uses name (i.e. the field name that will contain the vector values in fieldname_embedding, here)

By db.vector.name I mean the field name in the document that will be used for embedding (most common for DB like MongoDB, Azure Search, Redis, Elasticsearch, PostgreSQL) and by db.vector.id I mean the identifier of the vector (most used in native vector db like Pinecone, Qdrant, Chroma, Milvus).

Basically these attributes, name and ID, are used to identify the vector, maybe a better naming for db.vector.name can be db.vector.field_name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the context!

name

I agree that db.vector.field_name would be more descriptive.
It could be difficult to collect it though - for cosmos, postgres and many other dbs it would require parsing queries (and specific parsing for vector search). I.e. it'd probably mean that very few generic DB instrumentations will do it.

Even the native instrumentation that we have in CosmosDB does not know if query supplied by user is doing vector search.

So I wonder how critical this attribute is for the observability purposes. Also I'd be mostly static - is it important enough to justify additional costs of populating it on each span?

A typical semconv decision making hint is: if we're not sure we need it, let's not add it. Adding attributes to spans is easy, removing them is breaking and hard.

Copy link
Contributor

Choose a reason for hiding this comment

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

id

I still don't understand what's behind db.vector.id - it seems to be a generic record id and there is nothing vector-specific here.

I support adding generic attribute like db.record.id: string or db.record.ids: string[] (needs polishing)

Copy link
Author

Choose a reason for hiding this comment

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

The db.vector.id is the record id but specific for the vector. The db.record.id will work as well, since it's just an identifier for the record (i.e. vector).

I think we should add db.vector.field_name since it is used in many database to specify which field has been used for the embedding.

brief: >
This group defines attributes for vector databases.
attributes:
- id: similarity
Copy link
Contributor

Choose a reason for hiding this comment

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

suggesting more explicit name like db.vector.search.similarity_metric

Copy link
Contributor

Choose a reason for hiding this comment

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

@ezimuel I think you also missed this change, is marked as resolved without any updates :)

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in a3330ff

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, who/how/when is going to populate it?

It seems it's only available at index creation time and not available at query or insert time. I.e. very rarely.

Copy link
Author

Choose a reason for hiding this comment

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

Correct, this is generally provided during the index creation but some databases uses it also in the query (e.g. Qdrant).

I think we can also leverage the Conditionally Required level for some attributes that are not always available, like the db.vector.search.similarity_metric, WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova just a reminder for this, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, it makes sense!

BTW I think the attribute should be db.search.similarity_metric or similar - similarity is not always based on vectors and we don't need to limit this attribute.

model/registry/db.yaml Outdated Show resolved Hide resolved
@karthikscale3
Copy link
Contributor

karthikscale3 commented Jul 17, 2024

Thanks for creating this PR. A few additional attributes which we instrument today with our SDK that we have found useful are the following:

db.index
db.namespace
db.collection.name
db.top_k
db.query

Thoughts on the ones listed above? cc @lmolkova

@ezimuel
Copy link
Author

ezimuel commented Jul 17, 2024

@karthikscale3 regarding the attributes that you proposed, some already exists:

  • db.index can be represented using db.operation.name = index;
  • db.namespace already exists;
  • db.collection.name already exists;
  • db.query can be represented using db.query.text and also db.query.parameter;

The top_k proposal I think it's a good idea:

  • db.vector.query.top_k to represent the k most similar vectors returned by a similarity serach;

Moreover, I found very interesting the proposal of OpenLLMetry project especially the part regarding the attributes for vector db, here:

 # Vector DB
 VECTOR_DB_VENDOR = "db.system"
 VECTOR_DB_OPERATION = "db.operation"
 VECTOR_DB_QUERY_TOP_K = "db.vector.query.top_k"

@ezimuel
Copy link
Author

ezimuel commented Jul 17, 2024

@lmolkova I applied all the feedbacks, thanks for the review. @karthikscale3 I added the top_k attribute, thanks.

Summary of the changes:

  • removed vector in db.system;
  • removed the db.vector.embeddings;
  • renamed db.vector.dimension in db.vector.dimension_count;
  • added the db.vector.query.top_k as suggested by @karthikscale3;
  • removed the allow_custom_values: true in db.yaml, see last commit;

@karthikscale3
Copy link
Contributor

@karthikscale3 regarding the attributes that you proposed, some already exists:

  • db.index can be represented using db.operation.name = index;
  • db.namespace already exists;
  • db.collection.name already exists;
  • db.query can be represented using db.query.text and also db.query.parameter;

The top_k proposal I think it's a good idea:

  • db.vector.query.top_k to represent the k most similar vectors returned by a similarity serach;

Moreover, I found very interesting the proposal of OpenLLMetry project especially the part regarding the attributes for vector db, here:

 # Vector DB
 VECTOR_DB_VENDOR = "db.system"
 VECTOR_DB_OPERATION = "db.operation"
 VECTOR_DB_QUERY_TOP_K = "db.vector.query.top_k"

Yea that sounds good! And yes, my intention was to reuse the existing ones. Wasn't sure if we needed them redefined for the sake of vector dbs or not. But sounds like its unnecessary.

@karthikscale3
Copy link
Contributor

@lmolkova I applied all the feedbacks, thanks for the review. @karthikscale3 I added the top_k attribute, thanks.

Summary of the changes:

  • removed vector in db.system;
  • removed the db.vector.embeddings;
  • renamed db.vector.dimension in db.vector.dimension_count;
  • added the db.vector.query.top_k as suggested by @karthikscale3;
  • removed the allow_custom_values: true in db.yaml, see last commit;

Thank you! From my side, everything looks good. We discussed this PR in today's working group call and @nirga wanted to take a deeper look at it once again.

docs/attributes-registry/db.md Outdated Show resolved Hide resolved
docs/database/dynamodb.md Outdated Show resolved Hide resolved
@ezimuel
Copy link
Author

ezimuel commented Jul 18, 2024

I fixed the merge issues. Thanks @trask

Copy link
Contributor

@nirga nirga left a comment

Choose a reason for hiding this comment

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

Thanks, that's a great start! I wonder if we want to add specific spans that use these attributes in this PR as well?

@ezimuel
Copy link
Author

ezimuel commented Jul 20, 2024

@nirga can you give me an example of specific span? FYI, I'm going offline and I'll come back August 4 for further discussion.

@nirga
Copy link
Contributor

nirga commented Jul 20, 2024

Sorry, nvm I think this is already covered as part of the DB semconv

@@ -199,6 +200,28 @@ This group defines attributes for Elasticsearch.

**[8]:** Many Elasticsearch url paths allow dynamic values. These SHOULD be recorded in span attributes in the format `db.elasticsearch.path_parts.<key>`, where `<key>` is the url path part name. The implementation SHOULD reference the [elasticsearch schema](https://raw.githubusercontent.com/elastic/elasticsearch-specification/main/output/schema/schema.json) in order to map the path part values to their names.

## Db Vector Attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Vector Database Attributes

@maryliag
Copy link
Contributor

@ezimuel looks like you missed some of the changes you marked as resolved:

  • rename db.vector.dimension to db.vector.dimension_count: it is still showing db.vector.dimension
  • rename db.vector.similarity to db.vector.search.similarity_metric: it is still showing db.vector.similarity

brief: >
The model used for the embedding.
examples: 'text-embedding-3-small'
- id: query.top_k
Copy link
Contributor

@lmolkova lmolkova Jul 26, 2024

Choose a reason for hiding this comment

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

I think we should come up with a more common attribute not specific to vector dbs.
Many databases allow to limit number of returned rows:

Suggesting db.query.max_returned_items. The actual returned count could be even better - db.query.item_count could mean items inserted or returned depending on the operation.

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova I see the similarity here but I think the db.vector.query.top-k is more specific from a semantic point of view and more related to vectors, since it specifies the top k results in order, starting from the most similar. In semantic search we have this similarity value that is always present in any result that we don't have in standard database. The limit parameter of SQL returns the first k results but not in order, it depends on how you build the query (e.g. using ORDER BY).
I personally think we should keep db.vector.query.top-k and potentially add a db.query.limit (or db.query.max_returned_items as you suggested) in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of the few dbs I checked, they use limit in vector search

So we're saying that DB instrumentations will need to detect if query is related to vector search or not and depending on this populate top-k or limit. That's difficult or impossible, but most importantly inconsistent and depends on instrumentation capabilities.

I.e. instrumentations that don't have vector-db specifics and those that do will use different attributes for the same thing.

So, I'd still prefer db.query.limit or something similar (and it should be under the same condition as db.query.text - we cannot require instrumentations to do query parsing)

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova do you agree that top-k and limit are two different concepts, based on my previous comment? If they are I think we cannot use a single attribute (e.g. db.query.limit) to manage both.

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova just a reminder for this, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ezimuel I see that databases use both terms to describe the same thing (see my comment above).

Let's say you have a postgres query like SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5; - the general-purpose DB instrumentation can report limit. If you make it understand vector search syntax, it may be able to use top_k instead, but that's would be inconsistent and unfamiliar for those who use vector search in postgres.

Copy link
Author

Choose a reason for hiding this comment

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

@lmolkova I see your point but I think top-k has a different meaning from limit. If you are using a relation database as vector db, limit is fine since you are building an SQL statement and you specify the order. But, if you are using a native vector database (e.g. Qdrant), the top-k is more relevant since top implies the order, using a similarity metric.

I think we should add both:

  • db.query.limit
  • db.vector.query.top-k

@lmolkova
Copy link
Contributor

We need to reference new attributes in the database spans conventions (see https://github.com/open-telemetry/semantic-conventions/blob/main/model/trace/database.yaml), specifically on the conventions for the databases we have there which support vector search.

We should describe how new attributes apply to them.

maryliag and others added 15 commits August 20, 2024 11:12
Co-authored-by: Aaron Clawson <[email protected]>
Co-authored-by: Liudmila Molkova <[email protected]>
Signed-off-by: ChrsMark <[email protected]>
Co-authored-by: Liudmila Molkova <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Liudmila Molkova <[email protected]>
…n /internal/tools (open-telemetry#1350)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Liudmila Molkova <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@ezimuel ezimuel requested review from a team August 20, 2024 09:13
@ezimuel
Copy link
Author

ezimuel commented Aug 20, 2024

@lmolkova I provided the following changes:

  • renamed db.vector.name in db.vector.field_name;
  • removed db.vector.id in favor of db.record.id.

I think the only missing point is about db.vector.query.top-k, see my last comment.
Thanks!

@AlexanderWert
Copy link
Member

@ezimuel Can you please update this PR with the new semconv folder structure? Thanks

@lmolkova
Copy link
Contributor

thanks for working on this @ezimuel !

Please make sure to update actual database semantic conventions and reference attributes you're adding under those that report them - #1231 (comment)

@ezimuel ezimuel requested review from a team as code owners September 25, 2024 11:36
@ezimuel
Copy link
Author

ezimuel commented Sep 25, 2024

@AlexanderWert I updated the PR and applied the suggestions from @lmolkova. I did the following changes:

  • removed the db.vector.model as reported here;
  • moved db.vector.search.similarity_metric to db.search.similarity_metric, as suggested here;

The only open question is about limit vs top-k, see my last comment.

@lmolkova I didn't understand what I supposed to do in this comment, since the link https://github.com/open-telemetry/semantic-conventions/blob/main/model/trace/database.yaml does not work. Can you clarify? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs More Approval
Development

Successfully merging this pull request may close these issues.