Skip to content
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

fix issue #1174 #1177

Merged
merged 1 commit into from
Nov 24, 2024
Merged
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
13 changes: 10 additions & 3 deletions deepeval/synthesizer/chunking/context_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ def __init__(
):
from chromadb.api.models.Collection import Collection

self.model, self.using_native_model = initialize_model(model)
self.embedder = embedder
# Chunking parameters
self.chunk_size = chunk_size
self.chunk_overlap = chunk_overlap
self.document_paths: List[str] = document_paths
self.total_chunks = 0
self.document_paths: List[str] = document_paths

# Model parameters
self.model, self.using_native_model = initialize_model(model)
self.embedder = embedder

# Quality parameters
self.max_retries = max_retries
self.filter_threshold = filter_threshold
self.similarity_threshold = similarity_threshold
Expand Down Expand Up @@ -106,6 +111,7 @@ def generate_contexts(
)

# Generate contexts
self.total_chunks = 0
for path, collection in self.source_files_to_collections_map.items():
num_chunks = collection.count()
min_num_context = min(num_context_per_document, num_chunks)
Expand Down Expand Up @@ -181,6 +187,7 @@ async def a_chunk_and_store(key, chunker: DocumentChunker):
)

# Generate contexts
self.total_chunks = 0
tasks = [
self._a_process_document_async(
path,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_context_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from deepeval.synthesizer.chunking.context_generator import ContextGenerator
from deepeval.models.openai_embedding_model import OpenAIEmbeddingModel
from itertools import chain

context_generator = ContextGenerator(
document_paths=["./synthesizer_data/pdf_example.pdf"],
embedder=OpenAIEmbeddingModel()
)
context_generator._load_docs()
context_generator._load_docs()
context_generator._load_docs()

contexts, source_files, context_scores = context_generator.generate_contexts(num_context_per_document=10)
print(f"Utilizing {len(set(chain.from_iterable(contexts)))} out of {context_generator.total_chunks} chunks.")

context_generator._load_docs()
contexts, source_files, context_scores = context_generator.generate_contexts(num_context_per_document=10)
print(f"Utilizing {len(set(chain.from_iterable(contexts)))} out of {context_generator.total_chunks} chunks.")
Loading