This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/refactor for added clarity (#104)
* More clarity in directory layout * complete refactor for additional codebase clarity
- Loading branch information
1 parent
a1fe32f
commit 64a820c
Showing
75 changed files
with
289 additions
and
317 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
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
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
File renamed without changes.
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
24 changes: 4 additions & 20 deletions
24
automata/core/embedding/code_embedding.py → ...ore/memory_store/symbol_code_embedding.py
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,49 @@ | ||
import logging | ||
|
||
from automata.core.base.database.vector import VectorDatabaseProvider | ||
from automata.core.llm.embedding import SymbolEmbeddingHandler | ||
from automata.core.symbol.base import Symbol | ||
from automata.core.symbol_embedding.base import SymbolDocEmbedding | ||
from automata.core.symbol_embedding.embedding_builders import SymbolDocEmbeddingBuilder | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SymbolDocEmbeddingHandler(SymbolEmbeddingHandler): | ||
"""A class to handle the embedding of symbols""" | ||
|
||
def __init__( | ||
self, | ||
embedding_db: VectorDatabaseProvider, | ||
embedding_builder: SymbolDocEmbeddingBuilder, | ||
) -> None: | ||
self.embedding_db = embedding_db | ||
self.embedding_builder = embedding_builder | ||
|
||
def get_embedding(self, symbol: Symbol) -> SymbolDocEmbedding: | ||
return self.embedding_db.get(symbol.dotpath) | ||
|
||
def process_embedding(self, symbol: Symbol) -> None: | ||
source_code = self.embedding_builder.fetch_embedding_context(symbol) | ||
|
||
if not source_code: | ||
raise ValueError(f"Symbol {symbol} has no source code") | ||
|
||
if self.embedding_db.contains(symbol.dotpath): | ||
self.update_existing_embedding(source_code, symbol) | ||
else: | ||
symbol_embedding = self.embedding_builder.build(source_code, symbol) | ||
self.embedding_db.add(symbol_embedding) | ||
|
||
def update_existing_embedding(self, source_code: str, symbol: Symbol) -> None: | ||
existing_embedding = self.embedding_db.get(symbol.dotpath) | ||
if existing_embedding.symbol != symbol or existing_embedding.source_code != source_code: | ||
logger.debug( | ||
f"Rolling forward the embedding for {existing_embedding.symbol} to {symbol}" | ||
) | ||
self.embedding_db.discard(symbol.dotpath) | ||
existing_embedding.symbol = symbol | ||
existing_embedding.source_code = source_code | ||
self.embedding_db.add(existing_embedding) | ||
else: | ||
logger.debug("Passing for %s", symbol) |
Oops, something went wrong.