Skip to content

Commit

Permalink
Add rag enabled setting
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Sep 6, 2024
1 parent 3ce9ee3 commit 316045f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/main/askai/core/askai_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def chunk_overlap(self) -> int:
def rag_retrival_amount(self) -> int:
return settings.get_int("askai.rag.retrival.amount")

@property
def is_rag(self) -> bool:
return settings.get_int("askai.rag.enabled")

@property
def language(self) -> Language:
"""Lookup order: Settings -> Locale -> Environment."""
Expand Down
3 changes: 2 additions & 1 deletion src/main/askai/core/askai_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AskAiSettings(metaclass=Singleton):
INSTANCE: "AskAiSettings"

# Current settings version. Updating this value will trigger a database recreation using the defaults.
_ACTUAL_VERSION: str = "0.1.9"
_ACTUAL_VERSION: str = "0.1.91"

RESOURCE_DIR = str(classpath.resource_path())

Expand Down Expand Up @@ -103,6 +103,7 @@ def defaults(self) -> None:
self._settings.put("askai.text.splitter.chunk.size", "askai", 1000)
self._settings.put("askai.text.splitter.chunk.overlap", "askai", 100)
self._settings.put("askai.rag.retrival.amount", "askai", 3)
self._settings.put("askai.rag.enabled", "askai", True)
# Router
self._settings.put("askai.max.short.memory.size", "askai", 15)
self._settings.put("askai.max.router.iteractions", "askai", 30)
Expand Down
21 changes: 11 additions & 10 deletions src/main/askai/core/support/rag_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ def get_rag_examples(self, query: str, k: int = configs.rag_retrival_amount) ->
:param k: The number of examples to retrieve (default is 3).
:return: A list of strings representing the retrieved examples.
"""
if self._rag_db is None:
self._rag_db = FAISS.from_documents(self._rag_docs, lc_llm.create_embeddings())
example_docs: list[Document] = self._rag_db.similarity_search(query, k=k)
rag_examples = os.linesep.join([doc.page_content for doc in example_docs])
return dedent(f"""
**Examples:**
\"\"\"
{rag_examples}
\"\"\"
""").strip()
if configs.is_rag:
if self._rag_db is None:
self._rag_db = FAISS.from_documents(self._rag_docs, lc_llm.create_embeddings())
example_docs: list[Document] = self._rag_db.similarity_search(query, k=k)
rag_examples = os.linesep.join([doc.page_content for doc in example_docs])
return dedent(f"""
**Examples:**
\"\"\"
{rag_examples}
\"\"\"
""").strip()

0 comments on commit 316045f

Please sign in to comment.