- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2k
 
Support similarity scores in Document API #1794
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright 2023-2024 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| 
     | 
||
| package org.springframework.ai.document; | ||
| 
     | 
||
| import org.springframework.ai.vectorstore.VectorStore; | ||
| 
     | 
||
| /** | ||
| * Common set of metadata keys used in {@link Document}s by {@link DocumentReader}s and | ||
| * {@link VectorStore}s. | ||
| * | ||
| * @author Thomas Vitale | ||
| * @since 1.0.0 | ||
| */ | ||
| public enum DocumentMetadata { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea for this enum is to use it for other common metadata used in Documents, such as the "source file" or "page" when using a   | 
||
| 
     | 
||
| // @formatter:off | ||
| 
     | 
||
| /** | ||
| * Measure of distance between the document embedding and the query vector. | ||
| * The lower the distance, the more they are similar. | ||
| * It's the opposite of the similarity score. | ||
| */ | ||
| DISTANCE("distance"); | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept this metadata for backward compatibility, but we might consider removing it completely since we now have the "score" field in each Document (and "distance" is always the opposite value of "score").  | 
||
| 
     | 
||
| private final String value; | ||
| 
     | 
||
| DocumentMetadata(String value) { | ||
| this.value = value; | ||
| } | ||
| public String value() { | ||
| return this.value; | ||
| } | ||
| 
     | 
||
| // @formatter:on | ||
| 
     | 
||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright 2023-2024 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| 
     | 
||
| @NonNullApi | ||
| @NonNullFields | ||
| package org.springframework.ai.document; | ||
| 
     | 
||
| import org.springframework.lang.NonNullApi; | ||
| import org.springframework.lang.NonNullFields; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've updated it so that it adds to the existing list vs. replacing it. There are tests that assume it aggregates.