Skip to content

Commit

Permalink
empty dir and file fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ouonline committed Nov 20, 2024
1 parent c2bb6ff commit 064e8dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
3 changes: 0 additions & 3 deletions examples/rag_milvus_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ def __init__(self):
self.root_dir = os.path.expanduser(os.path.join(config['home'], 'rag_for_ut'))
self.rag_dir = os.path.join(self.root_dir, 'rag_master')
os.makedirs(self.rag_dir, exist_ok=True)
# creates a dummy file for rag
with open(os.path.join(self.rag_dir, '_dummy.txt'), "wb") as fd:
fd.write(b'dsfjfasfkjdsfewifjewofjefiejw')
self.store_file = os.path.join(self.root_dir, "milvus.db")

def __del__(self):
Expand Down
2 changes: 1 addition & 1 deletion lazyllm/tools/rag/doc_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _add_files(self, input_files: List[str], ids: Optional[List[str]] = None,
all_groups = self.store.all_groups()
LOG.info(f"add_files: Trying to merge store with {all_groups}")
for group in all_groups:
if not self.store.is_group_active(group):
if group != LAZY_ROOT_NAME and not self.store.is_group_active(group):
continue
# Duplicate group will be discarded automatically
nodes = self._get_nodes(group, temp_store)
Expand Down
20 changes: 11 additions & 9 deletions lazyllm/tools/rag/rerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ def __init__(self, name: str = "ModuleReranker", target: Optional[str] = None,
self._reranker = lazyllm.TrainableModule(self._kwargs['model'])

def forward(self, nodes: List[DocNode], query: str = "") -> List[DocNode]:
docs = [node.get_text(metadata_mode=MetadataMode.EMBED) for node in nodes]
top_n = self._kwargs['topk'] if 'topk' in self._kwargs else len(docs)
if self._reranker._deploy_type == lazyllm.deploy.Infinity:
sorted_indices = self._reranker(query, documents=docs, top_n=top_n)
else:
inps = {'query': query, 'documents': docs, 'top_n': top_n}
sorted_indices = self._reranker(inps)
results = [nodes[i] for i in sorted_indices]
LOG.debug(f"Rerank use `{self._name}` and get nodes: {results}")
results = []
if nodes:
docs = [node.get_text(metadata_mode=MetadataMode.EMBED) for node in nodes]
top_n = self._kwargs['topk'] if 'topk' in self._kwargs else len(docs)
if self._reranker._deploy_type == lazyllm.deploy.Infinity:
sorted_indices = self._reranker(query, documents=docs, top_n=top_n)
else:
inps = {'query': query, 'documents': docs, 'top_n': top_n}
sorted_indices = self._reranker(inps)
results = [nodes[i] for i in sorted_indices]
LOG.debug(f"Rerank use `{self._name}` and get nodes: {results}")
return self._post_process(results)

# User-defined similarity decorator
Expand Down

0 comments on commit 064e8dd

Please sign in to comment.