Skip to content

Commit eeee84e

Browse files
authored
Add vector store id reference to embeddings config. (#1662)
1 parent 1bbce33 commit eeee84e

File tree

10 files changed

+43
-18
lines changed

10 files changed

+43
-18
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "patch",
3+
"description": "Add vector store id reference to embeddings config."
4+
}

graphrag/config/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
VECTOR_STORE_DB_URI = str(Path(OUTPUT_BASE_DIR) / "lancedb")
107107
VECTOR_STORE_CONTAINER_NAME = "default"
108108
VECTOR_STORE_OVERWRITE = True
109-
VECTOR_STORE_INDEX_NAME = "output"
109+
VECTOR_STORE_DEFAULT_ID = "default_vector_store"
110110

111111
# Local Search
112112
LOCAL_SEARCH_TEXT_UNIT_PROP = 0.5

graphrag/config/embeddings.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,10 @@ def get_embedding_settings(
5757
embeddings_llm_settings = settings.get_language_model_config(
5858
settings.embeddings.model_id
5959
)
60-
num_entries = len(settings.vector_store)
61-
if num_entries == 1:
62-
store = next(iter(settings.vector_store.values()))
63-
vector_store_settings = store.model_dump()
64-
else:
65-
# The vector_store dict should only have more than one entry for multi-index query
66-
vector_store_settings = None
60+
vector_store_settings = settings.get_vector_store_config(
61+
settings.embeddings.vector_store_id
62+
).model_dump()
6763

68-
if vector_store_settings is None:
69-
return {
70-
"strategy": settings.embeddings.resolved_strategy(embeddings_llm_settings)
71-
}
7264
#
7365
# If we get to this point, settings.vector_store is defined, and there's a specific setting for this embedding.
7466
# settings.vector_store.base contains connection information, or may be undefined

graphrag/config/init_content.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
# deployment_name: <azure_model_deployment_name>
4141
4242
vector_store:
43-
{defs.VECTOR_STORE_INDEX_NAME}:
43+
{defs.VECTOR_STORE_DEFAULT_ID}:
4444
type: {defs.VECTOR_STORE_TYPE}
4545
db_uri: {defs.VECTOR_STORE_DB_URI}
4646
container_name: {defs.VECTOR_STORE_CONTAINER_NAME}
4747
overwrite: {defs.VECTOR_STORE_OVERWRITE}
4848
4949
embeddings:
5050
model_id: {defs.DEFAULT_EMBEDDING_MODEL_ID}
51+
vector_store_id: {defs.VECTOR_STORE_DEFAULT_ID}
5152
5253
### Input settings ###
5354

graphrag/config/models/graph_rag_config.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _validate_update_index_output_base_dir(self) -> None:
226226

227227
vector_store: dict[str, VectorStoreConfig] = Field(
228228
description="The vector store configuration.",
229-
default={"output": VectorStoreConfig()},
229+
default={defs.VECTOR_STORE_DEFAULT_ID: VectorStoreConfig()},
230230
)
231231
"""The vector store configuration."""
232232

@@ -263,6 +263,30 @@ def get_language_model_config(self, model_id: str) -> LanguageModelConfig:
263263

264264
return self.models[model_id]
265265

266+
def get_vector_store_config(self, vector_store_id: str) -> VectorStoreConfig:
267+
"""Get a vector store configuration by ID.
268+
269+
Parameters
270+
----------
271+
vector_store_id : str
272+
The ID of the vector store to get. Should match an ID in the vector_store list.
273+
274+
Returns
275+
-------
276+
VectorStoreConfig
277+
The vector store configuration if found.
278+
279+
Raises
280+
------
281+
ValueError
282+
If the vector store ID is not found in the configuration.
283+
"""
284+
if vector_store_id not in self.vector_store:
285+
err_msg = f"Vector Store ID {vector_store_id} not found in configuration. Please rerun `graphrag init` and set the vector store configuration."
286+
raise ValueError(err_msg)
287+
288+
return self.vector_store[vector_store_id]
289+
266290
@model_validator(mode="after")
267291
def _validate_model(self):
268292
"""Validate the model configuration."""

graphrag/config/models/text_embedding_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class TextEmbeddingConfig(BaseModel):
3434
description="The model ID to use for text embeddings.",
3535
default=defs.EMBEDDING_MODEL_ID,
3636
)
37+
vector_store_id: str = Field(
38+
description="The vector store ID to use for text embeddings.",
39+
default=defs.VECTOR_STORE_DEFAULT_ID,
40+
)
3741

3842
def resolved_strategy(self, model_config: LanguageModelConfig) -> dict:
3943
"""Get the resolved text embedding strategy."""

tests/fixtures/azure/settings.yml

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

44
embeddings:
55
vector_store:
6-
output:
6+
default_vector_store:
77
type: "azure_ai_search"
88
url: ${AZURE_AI_SEARCH_URL_ENDPOINT}
99
api_key: ${AZURE_AI_SEARCH_API_KEY}

tests/fixtures/min-csv/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ models:
2626
async_mode: threaded
2727

2828
vector_store:
29-
output:
29+
default_vector_store:
3030
type: "lancedb"
3131
db_uri: "./tests/fixtures/min-csv/lancedb"
3232
container_name: "lancedb_ci"

tests/fixtures/text/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ models:
2626
async_mode: threaded
2727

2828
vector_store:
29-
output:
29+
default_vector_store:
3030
type: "azure_ai_search"
3131
url: ${AZURE_AI_SEARCH_URL_ENDPOINT}
3232
api_key: ${AZURE_AI_SEARCH_API_KEY}

tests/unit/config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
DEFAULT_GRAPHRAG_CONFIG_SETTINGS = {
5151
"models": DEFAULT_MODEL_CONFIG,
5252
"vector_store": {
53-
"output": {
53+
defs.VECTOR_STORE_DEFAULT_ID: {
5454
"type": defs.VECTOR_STORE_TYPE,
5555
"db_uri": defs.VECTOR_STORE_DB_URI,
5656
"container_name": defs.VECTOR_STORE_CONTAINER_NAME,

0 commit comments

Comments
 (0)