Skip to content

Tilføjet fagspecifik-collections branch #432

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class BaseConfiguration:
},
)

# Tilføj denne nye parameter for fagspecifik søgning
fag: Optional[str] = field(
default=None,
metadata={
"description": "Fagområde for søgning (fx 'jura', 'matematik'). Bestemmer hvilken kollektion der søges i."
},
)

@classmethod
def from_runnable_config(
cls: Type[T], config: Optional[RunnableConfig] = None
Expand All @@ -91,4 +99,4 @@ def from_runnable_config(
return cls(**{k: v for k, v in configurable.items() if k in _fields})


T = TypeVar("T", bound=BaseConfiguration)
T = TypeVar("T", bound=BaseConfiguration)
20 changes: 17 additions & 3 deletions backend/retrieval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from contextlib import contextmanager
from typing import Iterator
from typing import Iterator, Optional

import weaviate
from langchain_core.embeddings import Embeddings
Expand Down Expand Up @@ -35,9 +35,23 @@ def make_weaviate_retriever(
),
skip_init_checks=True,
) as weaviate_client:
# Få fag fra konfigurationen, hvis det findes
fag = getattr(configuration, 'fag', None)

# Bestem collection navnet baseret på fag eller brug fallback
if fag:
# Brug fagspecifik collection
collection_name = f"{fag}_Pensum"
else:
# Fallback: Brug miljøvariabel eller konstant
collection_name = os.environ.get("WEAVIATE_INDEX_NAME", WEAVIATE_DOCS_INDEX_NAME)

# Brug den bestemte collection
print(f"Søger i collection: {collection_name}")

store = WeaviateVectorStore(
client=weaviate_client,
index_name=WEAVIATE_DOCS_INDEX_NAME,
index_name=collection_name, # Nu bruger vi det dynamiske collection navn
text_key="text",
embedding=embedding_model,
attributes=["source", "title"],
Expand All @@ -63,4 +77,4 @@ def make_retriever(
"Unrecognized retriever_provider in configuration. "
f"Expected one of: {', '.join(BaseConfiguration.__annotations__['retriever_provider'].__args__)}\n"
f"Got: {configuration.retriever_provider}"
)
)