-
Notifications
You must be signed in to change notification settings - Fork 4
perf: Share SentenceTransformer between RAGIndexer and ContextRetriever #157
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |||||||||||||||
|
|
||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||
| from pathlib import Path | ||||||||||||||||
| from typing import List, Optional | ||||||||||||||||
| from typing import List, Optional, Any | ||||||||||||||||
|
|
||||||||||||||||
| from refactron.rag.indexer import get_sentence_transformer | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+7
to
10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize import ordering to satisfy isort. This block is out of isort order (typing members should be alphabetized). That’s consistent with the reported pre-commit failure. Suggested patch-from typing import List, Optional, Any
+from typing import Any, List, Optional📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| try: | ||||||||||||||||
| import chromadb | ||||||||||||||||
|
|
@@ -38,7 +40,7 @@ class ContextRetriever: | |||||||||||||||
| def __init__( | ||||||||||||||||
| self, | ||||||||||||||||
| workspace_path: Path, | ||||||||||||||||
| embedding_model: str = "all-MiniLM-L6-v2", | ||||||||||||||||
| embedding_model: Any = "all-MiniLM-L6-v2", | ||||||||||||||||
| collection_name: str = "code_chunks", | ||||||||||||||||
| ): | ||||||||||||||||
| """Initialize the context retriever. | ||||||||||||||||
|
|
@@ -58,7 +60,10 @@ def __init__( | |||||||||||||||
| self.index_path = self.workspace_path / ".rag" | ||||||||||||||||
|
|
||||||||||||||||
| # Initialize embedding model | ||||||||||||||||
| self.embedding_model = SentenceTransformer(embedding_model) | ||||||||||||||||
| if isinstance(embedding_model, str): | ||||||||||||||||
| self.embedding_model = get_sentence_transformer(embedding_model) | ||||||||||||||||
| else: | ||||||||||||||||
| self.embedding_model = embedding_model | ||||||||||||||||
|
Comment on lines
+63
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate injected embedding model interface at initialization. With Suggested patch if isinstance(embedding_model, str):
self.embedding_model = get_sentence_transformer(embedding_model)
else:
+ if not hasattr(embedding_model, "encode") or not callable(embedding_model.encode):
+ raise TypeError("embedding_model must be a model name or an object with encode()")
self.embedding_model = embedding_model🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| # Initialize ChromaDB client | ||||||||||||||||
| self.client = chromadb.PersistentClient( | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix import order/placement to clear pre-commit gates.
Line 35/36 imports appear after executable module code, which triggers flake8 E402 and isort churn in this file. Move
refactron.ragimports to the top import block (before function definitions).Suggested patch
Also applies to: 33-36
🤖 Prompt for AI Agents