mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-22 00:32:49 +00:00
up
This commit is contained in:
parent
8336670c03
commit
df940a8c18
4 changed files with 12 additions and 9 deletions
|
|
@ -166,4 +166,7 @@ class Application(BaseComponent):
|
|||
|
||||
def run_app(self):
|
||||
"""Start the service and serve the application."""
|
||||
if self.context.service is None:
|
||||
raise RuntimeError("Service not configured")
|
||||
|
||||
self.context.service.run_app(app=self)
|
||||
|
|
|
|||
|
|
@ -62,22 +62,22 @@ class BaseEmbeddingModel(BaseComponent):
|
|||
|
||||
# -- Public API --
|
||||
|
||||
async def get_embedding(self, input_text: str, **kwargs) -> list[float] | None:
|
||||
async def get_embedding(self, input_text: str, **kwargs) -> np.ndarray | None:
|
||||
"""Get embedding for a single text."""
|
||||
results = await self.get_embeddings([input_text], **kwargs)
|
||||
return results[0] if results else None
|
||||
|
||||
async def get_embeddings(self, input_text: list[str], **kwargs) -> list[list[float] | None]:
|
||||
async def get_embeddings(self, input_text: list[str], **kwargs) -> list[np.ndarray | None]:
|
||||
"""Get embeddings for a list of texts, with caching and batching."""
|
||||
truncated = [t[: self.max_input_length] for t in input_text]
|
||||
results: list[list[float] | None] = [None] * len(truncated)
|
||||
results: list[np.ndarray | None] = [None] * len(truncated)
|
||||
to_compute: list[tuple[int, str]] = []
|
||||
|
||||
# Split into cache hits and misses
|
||||
for idx, text in enumerate(truncated):
|
||||
cached = self._get_from_cache(text)
|
||||
if cached is not None:
|
||||
results[idx] = cached.tolist()
|
||||
results[idx] = cached
|
||||
else:
|
||||
to_compute.append((idx, text))
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ class BaseEmbeddingModel(BaseComponent):
|
|||
emb_array = np.pad(emb_array, (0, self.dimensions - len(emb_array)))
|
||||
else:
|
||||
emb_array = emb_array[: self.dimensions]
|
||||
results[orig_idx] = emb_array.tolist()
|
||||
results[orig_idx] = emb_array
|
||||
self._put_to_cache(text, emb_array)
|
||||
|
||||
return results
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ class LocalFileStore(BaseFileStore):
|
|||
if old_node and self.embedding_model:
|
||||
for cid in old_node.chunk_ids:
|
||||
old = self.file_chunks.pop(cid, None)
|
||||
if old and old.embedding:
|
||||
if old and old.embedding is not None:
|
||||
cached[cid] = old.embedding
|
||||
|
||||
node.chunk_ids = []
|
||||
for c in chunks:
|
||||
if self.embedding_model and not c.embedding:
|
||||
if self.embedding_model and c.embedding is None:
|
||||
if c.id in cached:
|
||||
c.embedding = cached[c.id]
|
||||
elif c.text:
|
||||
|
|
@ -120,7 +120,7 @@ class LocalFileStore(BaseFileStore):
|
|||
return []
|
||||
|
||||
query_embedding = await self.embedding_model.get_embedding(query)
|
||||
if not query_embedding:
|
||||
if query_embedding is None:
|
||||
return []
|
||||
|
||||
candidates = [c for c in self.file_chunks.values() if c.embedding is not None]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class ReMe(Application):
|
|||
|
||||
def main():
|
||||
"""Parse CLI arguments and launch the appropriate mode."""
|
||||
action, config = parse_args(sys.argv[1:])
|
||||
action, config = parse_args(*sys.argv[1:])
|
||||
if action == "start":
|
||||
reme = ReMe(**config)
|
||||
reme.run_app()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue