mirror of
https://github.com/microsoft/graphrag.git
synced 2026-01-29 15:21:58 +08:00
Some checks failed
gh-pages / build (push) Has been cancelled
Python CI / python-ci (ubuntu-latest, 3.10) (push) Has been cancelled
Python CI / python-ci (ubuntu-latest, 3.11) (push) Has been cancelled
Python CI / python-ci (windows-latest, 3.10) (push) Has been cancelled
Python CI / python-ci (windows-latest, 3.11) (push) Has been cancelled
Python Integration Tests / python-ci (ubuntu-latest, 3.10) (push) Has been cancelled
Python Integration Tests / python-ci (windows-latest, 3.10) (push) Has been cancelled
Python Notebook Tests / python-ci (ubuntu-latest, 3.10) (push) Has been cancelled
Python Notebook Tests / python-ci (windows-latest, 3.10) (push) Has been cancelled
Python Publish (pypi) / Upload release to PyPI (push) Has been cancelled
Python Smoke Tests / python-ci (ubuntu-latest, 3.10) (push) Has been cancelled
Python Smoke Tests / python-ci (windows-latest, 3.10) (push) Has been cancelled
Spellcheck / spellcheck (push) Has been cancelled
* Initial plan * Refactor VectorStoreFactory to use registration functionality like StorageFactory Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * Fix linting issues in VectorStoreFactory refactoring Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * Remove backward compatibility support from VectorStoreFactory and StorageFactory Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * Run ruff check --fix and ruff format, add semversioner file Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * ruff formatting fixes * Fix pytest errors in storage factory tests by updating PipelineStorage interface implementation Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * ruff formatting fixes * update storage factory design * Refactor CacheFactory to use registration functionality like StorageFactory Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * revert copilot changes * fix copilot changes * update comments * Fix failing pytest compatibility for factory tests Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * update class instantiation issue * ruff fixes * fix pytest * add default value * ruff formatting changes * ruff fixes * revert minor changes * cleanup cache factory * Update CacheFactory tests to match consistent factory pattern Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * update pytest thresholds * adjust threshold levels * Add custom vector store implementation notebook Create comprehensive notebook demonstrating how to implement and register custom vector stores with GraphRAG as a plug-and-play framework. Includes: - Complete implementation of SimpleInMemoryVectorStore - Registration with VectorStoreFactory - Testing and validation examples - Configuration examples for GraphRAG settings - Advanced features and best practices - Production considerations checklist The notebook provides a complete walkthrough for developers to understand and implement their own vector store backends. Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> * remove sample notebook for now * update tests * fix cache pytests * add pandas-stub to dev dependencies * disable warning check for well known key * skip tests when running on ubuntu * add documentation for custom vector store implementations * ignore ruff findings in notebooks * fix merge breakages * speedup CLI import statements * remove unnecessary import statements in init file * Add str type option on storage/cache type * Fix store name * Add LoggerFactory * Fix up logging setup across CLI/API * Add LoggerFactory test * Fix err message * Semver * Remove enums from factory methods --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com> Co-authored-by: Josh Bradley <joshbradley@microsoft.com> Co-authored-by: Nathan Evans <github@talkswithnumbers.com>
119 lines
3.6 KiB
Python
119 lines
3.6 KiB
Python
# Copyright (c) 2024 Microsoft Corporation.
|
|
# Licensed under the MIT License
|
|
|
|
"""Tests for standard logging functionality."""
|
|
|
|
import logging
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from graphrag.logger.standard_logging import DEFAULT_LOG_FILENAME, init_loggers
|
|
from tests.unit.config.utils import get_default_graphrag_config
|
|
|
|
|
|
def test_standard_logging():
|
|
"""Test that standard logging works."""
|
|
logger = logging.getLogger("graphrag.test")
|
|
assert logger.name == "graphrag.test"
|
|
|
|
|
|
def test_logger_hierarchy():
|
|
"""Test that logger hierarchy works correctly."""
|
|
# reset logging to default state using init_loggers
|
|
config = get_default_graphrag_config()
|
|
init_loggers(config)
|
|
|
|
root_logger = logging.getLogger("graphrag")
|
|
child_logger = logging.getLogger("graphrag.child")
|
|
|
|
# setting level on root should affect children
|
|
root_logger.setLevel(logging.ERROR)
|
|
assert child_logger.getEffectiveLevel() == logging.ERROR
|
|
|
|
# clean up after test
|
|
root_logger.handlers.clear()
|
|
|
|
|
|
def test_init_loggers_file_config():
|
|
"""Test that init_loggers works with file configuration."""
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
config = get_default_graphrag_config(root_dir=temp_dir)
|
|
|
|
# call init_loggers with file config
|
|
init_loggers(config=config)
|
|
|
|
logger = logging.getLogger("graphrag")
|
|
|
|
# should have a file handler
|
|
file_handlers = [
|
|
h for h in logger.handlers if isinstance(h, logging.FileHandler)
|
|
]
|
|
assert len(file_handlers) > 0
|
|
|
|
# test that logging works
|
|
test_message = "Test init_loggers file message"
|
|
logger.info(test_message)
|
|
|
|
# check that the log file was created
|
|
log_file = Path(temp_dir) / "logs" / DEFAULT_LOG_FILENAME
|
|
assert log_file.exists()
|
|
|
|
with open(log_file) as f:
|
|
content = f.read()
|
|
assert test_message in content
|
|
|
|
# clean up
|
|
for handler in logger.handlers[:]:
|
|
if isinstance(handler, logging.FileHandler):
|
|
handler.close()
|
|
logger.handlers.clear()
|
|
|
|
|
|
def test_init_loggers_file_verbose():
|
|
"""Test that init_loggers works with verbose flag."""
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
config = get_default_graphrag_config(root_dir=temp_dir)
|
|
|
|
# call init_loggers with file config
|
|
init_loggers(config=config, verbose=True)
|
|
|
|
logger = logging.getLogger("graphrag")
|
|
|
|
# test that logging works
|
|
test_message = "Test init_loggers file message"
|
|
logger.debug(test_message)
|
|
|
|
# check that the log file was created
|
|
log_file = Path(temp_dir) / "logs" / DEFAULT_LOG_FILENAME
|
|
|
|
with open(log_file) as f:
|
|
content = f.read()
|
|
assert test_message in content
|
|
|
|
# clean up
|
|
for handler in logger.handlers[:]:
|
|
if isinstance(handler, logging.FileHandler):
|
|
handler.close()
|
|
logger.handlers.clear()
|
|
|
|
|
|
def test_init_loggers_custom_filename():
|
|
"""Test that init_loggers works with custom filename."""
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
config = get_default_graphrag_config(root_dir=temp_dir)
|
|
|
|
# call init_loggers with file config
|
|
init_loggers(config=config, filename="custom-log.log")
|
|
|
|
logger = logging.getLogger("graphrag")
|
|
|
|
# check that the log file was created
|
|
log_file = Path(temp_dir) / "logs" / "custom-log.log"
|
|
assert log_file.exists()
|
|
|
|
# clean up
|
|
for handler in logger.handlers[:]:
|
|
if isinstance(handler, logging.FileHandler):
|
|
handler.close()
|
|
logger.handlers.clear()
|