-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Adding Vector Search to the In Memory collection (#9574)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Adds vectorized search and text search to the In Memory connector. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Tao Chen <[email protected]>
- Loading branch information
1 parent
daafde4
commit 1db12c4
Showing
12 changed files
with
267 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,10 @@ jobs: | |
- name: Install the project | ||
run: uv sync --all-extras --dev | ||
- uses: pre-commit/[email protected] | ||
name: Run Pre-Commit Hooks | ||
with: | ||
extra_args: --config python/.pre-commit-config.yaml --all-files | ||
- name: Run Mypy | ||
run: uv run mypy -p semantic_kernel --config-file mypy.ini | ||
- name: Minimize uv cache | ||
run: uv cache prune --ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
python/semantic_kernel/connectors/memory/in_memory/const.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) Microsoft. All rights reserved. | ||
|
||
|
||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
from numpy import dot | ||
from scipy.spatial.distance import cityblock, cosine, euclidean, hamming, sqeuclidean | ||
|
||
from semantic_kernel.data.const import DistanceFunction | ||
|
||
DISTANCE_FUNCTION_MAP: dict[DistanceFunction | str, Callable[..., Any]] = { | ||
DistanceFunction.COSINE_DISTANCE: cosine, | ||
DistanceFunction.COSINE_SIMILARITY: cosine, | ||
DistanceFunction.EUCLIDEAN_DISTANCE: euclidean, | ||
DistanceFunction.EUCLIDEAN_SQUARED_DISTANCE: sqeuclidean, | ||
DistanceFunction.MANHATTAN: cityblock, | ||
DistanceFunction.HAMMING: hamming, | ||
DistanceFunction.DOT_PROD: dot, | ||
"default": cosine, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.