Skip to content

added CRUD for Chorma Vector store#7

Open
RonitKiranMurmu wants to merge 5 commits intopixelThreaderOfficial:mainfrom
RonitKiranMurmu:utility-modules
Open

added CRUD for Chorma Vector store#7
RonitKiranMurmu wants to merge 5 commits intopixelThreaderOfficial:mainfrom
RonitKiranMurmu:utility-modules

Conversation

@RonitKiranMurmu
Copy link
Contributor

No description provided.

Copy link
Contributor

@pixelThreader pixelThreader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonitKiranMurmu Please Update these changes in the file as instructed and use the DBLogger log the data and please ensure you're not repeating yourself!

use from main.src.utils.versionManagement import getAppVersion for getting the version Dynamically. for instance you can read the DRSecrets.py for looking how I used the logger there!!

_std_logger = logging.getLogger(__name__)

try:
import chromadb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep all import statements at top

Copy link
Contributor Author

@RonitKiranMurmu RonitKiranMurmu Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-except block around [import chromadb] is a pattern for optional dependencies.
Here is why it is used instead of a standard top-level import:
Prevents App Crashes: [chromadb] is a heavy library. If a user (or a CI/CD server) doesn't have it installed, a standard [import chromadb] would crash the entire application immediately upon startup. The try-except block allows the app to start even if is missing.
Graceful Handling: It sets the flag [_CHROMA_AVAILABLE] which allows the rest of the code to handle the missing library gracefully (e.g., by setting [db_vector_manager = None] or raising a clear error message like ["Run: uv add chromadb"] when someone actually tries to use it).
If you move it to a bare [import chromadb] at the top, the program will crash instantly with ModuleNotFoundError if the package isn't installed.

So do i make it essential and move it to the top anyway or leave it right there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually remove the try-catch block from the chromadb that's not important because the backend is setup by experienced developers.

origin="system",
module="DB",
urgency=urgency, # type: ignore
app_version="1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong!!

NO HARDCODED VERSION ACCEPTED!!

use from main.src.utils.versionManagement import getAppVersion

then the use the getAppVersion like app_version=getAppVersion()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it to remove hardcoding

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, there is still the version hardcoded

Image

try:
chroma_store_dir.mkdir(parents=True, exist_ok=True)
_std_logger.info(f"ChromaDB storage directory ensured: {chroma_store_dir}")
dr_logger.log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the _log function and don't hardcode the version

Comment on lines +619 to +626
dr_logger.log(
log_type="error",
message=f"Failed to initialize ChromaDB store directory: {e}",
origin="system",
module="DB",
urgency="critical",
app_version="1.0",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the _log function and don't hardcode the version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brother use the logging module and you dont have to write the tests in the logs database!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running automated tests, we should not pollute the real logs database (logs.db.sqlite3) with test data. Tests should be isolated and "silent" regarding side effects like database writes.

How I addressed it:
I ensured this in two ways:

Mocking the Logger in Tests:
In [test_db_vector.py], the [setUp] method now includes:

self.patcher = patch("main.src.store.DBVector.dr_logger")
self.mock_logger = self.patcher.start()

This intercepts all calls to [dr_logger.log] during tests and sends them to a fake (mock) object instead of the real database. This effectively stops tests from writing to the logs DB.

Preventing Import Side-Effects:
In [DBVector.py], I added this check:

if not any("unittest" in arg for arg in sys.argv) and not any("pytest" in arg for arg in sys.argv):
_initialize_chroma_store()

This ensures that simply importing the file during a test run doesn't trigger the initialization log entry.

So, your tests are now clean and they verify the logic without junking up your actual database logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ronit, I think this is complicated for a quick testing. we can use the logger to log directly in terminal to see the usage.. you don't have to mock into the DB, because the tests don't have to do anything with the logger it will not run at the prod....

So from future you can skip this Mock DB Loggers in test, because those are just complications. just use terminal loggers only!!

Copy link
Contributor

@pixelThreader pixelThreader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and there are some minor needs just make them then, we're good to merge to main branch.

_std_logger = logging.getLogger(__name__)

try:
import chromadb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually remove the try-catch block from the chromadb that's not important because the backend is setup by experienced developers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ronit, I think this is complicated for a quick testing. we can use the logger to log directly in terminal to see the usage.. you don't have to mock into the DB, because the tests don't have to do anything with the logger it will not run at the prod....

So from future you can skip this Mock DB Loggers in test, because those are just complications. just use terminal loggers only!!

origin="system",
module="DB",
urgency=urgency, # type: ignore
app_version="1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, there is still the version hardcoded

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants