-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use util to construct embeddings collection name
- Loading branch information
Showing
8 changed files
with
74 additions
and
16 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
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
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,25 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. | ||
# Licensed under the MIT License | ||
|
||
"""Utilities for working with embeddings stores.""" | ||
|
||
from graphrag.index.config.embeddings import all_embeddings | ||
|
||
|
||
def create_collection_name( | ||
container_name: str, embedding_name: str, validate: bool = True | ||
) -> str: | ||
""" | ||
Create a collection name for the embedding store. | ||
Within any given vector store, we can have multiple sets of embeddings organized into projects. | ||
The `container` param is used for this partitioning, and is added as a prefix to the collection name for differentiation. | ||
The embedding name is fixed, with the available list defined in graphrag.index.config.embeddings | ||
Note that we use dot notation in our names, but many vector stores do not support this - so we convert to dashes. | ||
""" | ||
if validate and embedding_name not in all_embeddings: | ||
msg = f"Invalid embedding name: {embedding_name}" | ||
raise KeyError(msg) | ||
return f"{container_name}-{embedding_name}".replace(".", "-") |
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,2 @@ | ||
# Copyright (c) 2024 Microsoft Corporation. | ||
# Licensed under the MIT License |
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) 2024 Microsoft Corporation. | ||
# Licensed under the MIT License | ||
|
||
import pytest | ||
|
||
from graphrag.utils.embeddings import create_collection_name | ||
|
||
|
||
def test_create_collection_name(): | ||
collection = create_collection_name("default", "entity.name") | ||
assert collection == "default-entity-name" | ||
|
||
|
||
def test_create_collection_name_invalid_embedding_throws(): | ||
with pytest.raises(KeyError): | ||
create_collection_name("default", "invalid.name") | ||
|
||
|
||
def test_create_collection_name_invalid_embedding_does_not_throw(): | ||
collection = create_collection_name("default", "invalid.name", validate=False) | ||
assert collection == "default-invalid-name" |