Skip to content

Commit 8064244

Browse files
committed
Move embeddings function to config
1 parent 0e791e4 commit 8064244

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

graphrag/api/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from graphrag.config.embeddings import (
2828
community_full_content_embedding,
29+
create_collection_name,
2930
entity_description_embedding,
3031
text_unit_text_embedding,
3132
)
@@ -47,7 +48,6 @@
4748
read_indexer_text_units,
4849
)
4950
from graphrag.utils.cli import redact
50-
from graphrag.utils.embeddings import create_collection_name
5151
from graphrag.vector_stores.base import BaseVectorStore
5252
from graphrag.vector_stores.factory import VectorStoreFactory
5353

graphrag/config/embeddings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,22 @@ def get_embedding_settings(
7575
return {
7676
"strategy": strategy,
7777
}
78+
79+
80+
def create_collection_name(
81+
container_name: str, embedding_name: str, validate: bool = True
82+
) -> str:
83+
"""
84+
Create a collection name for the embedding store.
85+
86+
Within any given vector store, we can have multiple sets of embeddings organized into projects.
87+
The `container` param is used for this partitioning, and is added as a prefix to the collection name for differentiation.
88+
89+
The embedding name is fixed, with the available list defined in graphrag.index.config.embeddings
90+
91+
Note that we use dot notation in our names, but many vector stores do not support this - so we convert to dashes.
92+
"""
93+
if validate and embedding_name not in all_embeddings:
94+
msg = f"Invalid embedding name: {embedding_name}"
95+
raise KeyError(msg)
96+
return f"{container_name}-{embedding_name}".replace(".", "-")

graphrag/index/operations/embed_text/embed_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from graphrag.cache.pipeline_cache import PipelineCache
1414
from graphrag.callbacks.workflow_callbacks import WorkflowCallbacks
15+
from graphrag.config.embeddings import create_collection_name
1516
from graphrag.index.operations.embed_text.strategies.typing import TextEmbeddingStrategy
16-
from graphrag.utils.embeddings import create_collection_name
1717
from graphrag.vector_stores.base import BaseVectorStore, VectorStoreDocument
1818
from graphrag.vector_stores.factory import VectorStoreFactory
1919

graphrag/utils/embeddings.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/unit/utils/test_embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from graphrag.utils.embeddings import create_collection_name
6+
from graphrag.config.embeddings import create_collection_name
77

88

99
def test_create_collection_name():

0 commit comments

Comments
 (0)