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

Make the embedding field name configurable for the ElasticSearchVectorStore #2175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dev-jonghoonpark
Copy link

Related issue: #2082

Motivation:

On #2082, We found embedding field name is not configurable.

Modification:

Added a configuration option for the embedding field name in the ElasticSearchVectorStore

Result:

Users can now specify a custom embedding field name through configuration.
Close #2082 issue.

Further discussion:

Is an ElasticSearchDocument record really necessary? If not, what about just using the Map class?

@dev-jonghoonpark
Copy link
Author

Fixed conflict with #2176

@ilayaperumalg
Copy link
Member

Is an ElasticSearchDocument record really necessary? If not, what about just using the Map class?

@dev-jonghoonpark We wanted to go with a specific type instead of Map. Do you see any downside of using the Record type for this?

@dev-jonghoonpark
Copy link
Author

@ilayaperumalg
No, I was just using the Map to make the field names configurable, with no other intentions.
In the code I wrote, I had to use conditional branching to configure the field names. This approach feels a bit unsatisfactory, so I wanted to share my thoughts with this comment.

private Object getDocument(Document document, float[] embedding, String fieldName) {
    Assert.notNull(document.getText(), "document's text must not be null");
    if (fieldName.equals("embedding")) {
	    return new ElasticSearchDocument(document.getId(), document.getText(), document.getMetadata(), embedding);
    }
    
    return Map.of("id", document.getId(), "content", document.getText(), "metadata", document.getMetadata(),
		    fieldName, embedding);
}

Could there have been a better way?

@dev-jonghoonpark dev-jonghoonpark force-pushed the GH-2082 branch 2 times, most recently from a567120 to 729ab32 Compare February 12, 2025 15:24
@Bean
public EmbeddingModel embeddingModel() {
return new OpenAiEmbeddingModel(new OpenAiApi(System.getenv("OPENAI_API_KEY")));
Copy link
Author

Choose a reason for hiding this comment

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

OpenAiApi constructor deprecated since 1.0.0.M6, so I changed to use builder

@dev-jonghoonpark
Copy link
Author

@ilayaperumalg
I've updated it based on your feedback.

@ilayaperumalg ilayaperumalg modified the milestones: 1.0.0-M6, 1.0.0-M7 Feb 12, 2025
@dev-jonghoonpark
Copy link
Author

Fixed conflict with #2209

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.

ElasticsearchVectorStore
2 participants