spring-projects / spring-projects/spring-ai

Handling of meta data is inconsistent between different embedding models.

Open
#2,579 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

OpenAiEmbeddingModel uses the following code for creating an embedding for a document:

@Override
public float[] embed(Document document) {
	Assert.notNull(document, "Document must not be null");
	return this.embed(document.getFormattedContent(this.metadataMode));
}

metadataModel controls if all, some or none of the metadata is included in constructing the String that then is used to create an embedding.
The default MetadataMode is EMBED which includes all fields, that aren't explicitly excluded.

OllamaEmbeddingModel on the other hand uses this implementation:

@Override
public float[] embed(Document document) {
	return embed(document.getText());
}

This means metadata is not included at all.

I don't see a reason why this behaviour is different for different embedding models. It should be the same for all and only implemented once, possibly in AbstractEmbeddingModel

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the Document overloads in OpenAiEmbeddingModel and OllamaEmbeddingModel, then inspect the possible shared implementation in AbstractEmbeddingModel and the MetadataMode default described in the issue. Done means document embedding handles metadata consistently across the affected models, with coverage confirming the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.