langroid 0.42.3__tar.gz → 0.42.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langroid-0.42.3 → langroid-0.42.5}/PKG-INFO +1 -1
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/task.py +4 -3
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/base.py +0 -3
- {langroid-0.42.3 → langroid-0.42.5}/pyproject.toml +1 -1
- langroid-0.42.3/langroid/vector_store/momento.py +0 -276
- {langroid-0.42.3 → langroid-0.42.5}/.gitignore +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/LICENSE +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/README.md +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/base.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/batch.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/callbacks/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/callbacks/chainlit.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/chat_document.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/openai_assistant.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/arangodb/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/arangodb/arangodb_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/arangodb/system_messages.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/arangodb/tools.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/arangodb/utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/doc_chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_doc_chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_rag/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_rag/critic_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_rag/lance_rag_task.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_rag/query_planner_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/lance_tools.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/neo4j/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/neo4j/csv_kg_chat.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/neo4j/neo4j_chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/neo4j/system_messages.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/neo4j/tools.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/relevance_extractor_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/retriever_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/sql_chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/description_extractors.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/populate_metadata.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/system_message.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/tools.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/table_chat_agent.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tool_message.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/duckduckgo_search_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/exa_search_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/file_tools.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/google_search_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/metaphor_search_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/orchestration.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/recipient_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/retrieval_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/rewind_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/segment_extract_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/tools/tavily_search_tool.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/agent/xml_tool_message.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/cachedb/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/cachedb/base.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/cachedb/momento_cachedb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/cachedb/redis_cachedb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/base.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/models.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/protoc/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/protoc/embeddings.proto +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/protoc/embeddings_pb2.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/protoc/embeddings_pb2.pyi +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/protoc/embeddings_pb2_grpc.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/embedding_models/remote_embeds.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/exceptions.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/azure_openai.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/base.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/config.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/mock_lm.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/model_info.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/openai_gpt.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/base.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/hf_formatter.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/llama2_formatter.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/mytypes.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/agent_chats.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/code_parser.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/document_parser.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/para_sentence_split.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/parse_json.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/parser.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/pdf_utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/repo_loader.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/routing.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/search.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/spider.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/table_loader.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/url_loader.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/urls.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/parsing/web_search.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/prompts/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/prompts/dialog.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/prompts/prompts_config.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/prompts/templates.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/py.typed +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/pydantic_v1/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/pydantic_v1/main.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/algorithms/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/algorithms/graph.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/configuration.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/constants.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/git_utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/globals.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/logging.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/object_registry.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/output/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/output/citations.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/output/printing.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/output/status.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/pandas_utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/pydantic_utils.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/system.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/utils/types.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/__init__.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/chromadb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/lancedb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/meilisearch.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/pineconedb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/postgres.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/qdrantdb.py +0 -0
- {langroid-0.42.3 → langroid-0.42.5}/langroid/vector_store/weaviatedb.py +0 -0
@@ -572,7 +572,11 @@ class Task:
|
|
572
572
|
self.pending_message.metadata.agent_id = self.agent.id
|
573
573
|
|
574
574
|
self._show_pending_message_if_debug()
|
575
|
+
self.init_loggers()
|
576
|
+
self.log_message(Entity.USER, self.pending_message)
|
577
|
+
return self.pending_message
|
575
578
|
|
579
|
+
def init_loggers(self) -> None:
|
576
580
|
if self.caller is not None and self.caller.logger is not None:
|
577
581
|
self.logger = self.caller.logger
|
578
582
|
elif self.logger is None:
|
@@ -591,9 +595,6 @@ class Task:
|
|
591
595
|
header = ChatDocLoggerFields().tsv_header()
|
592
596
|
self.tsv_logger.info(f" \tTask\tResponder\t{header}")
|
593
597
|
|
594
|
-
self.log_message(Entity.USER, self.pending_message)
|
595
|
-
return self.pending_message
|
596
|
-
|
597
598
|
def reset_all_sub_tasks(self) -> None:
|
598
599
|
"""
|
599
600
|
Recursively reset message history & state of own agent and
|
@@ -58,7 +58,6 @@ class VectorStore(ABC):
|
|
58
58
|
from langroid.vector_store.chromadb import ChromaDB, ChromaDBConfig
|
59
59
|
from langroid.vector_store.lancedb import LanceDB, LanceDBConfig
|
60
60
|
from langroid.vector_store.meilisearch import MeiliSearch, MeiliSearchConfig
|
61
|
-
from langroid.vector_store.momento import MomentoVI, MomentoVIConfig
|
62
61
|
from langroid.vector_store.pineconedb import PineconeDB, PineconeDBConfig
|
63
62
|
from langroid.vector_store.postgres import PostgresDB, PostgresDBConfig
|
64
63
|
from langroid.vector_store.qdrantdb import QdrantDB, QdrantDBConfig
|
@@ -68,8 +67,6 @@ class VectorStore(ABC):
|
|
68
67
|
return QdrantDB(config)
|
69
68
|
elif isinstance(config, ChromaDBConfig):
|
70
69
|
return ChromaDB(config)
|
71
|
-
elif isinstance(config, MomentoVIConfig):
|
72
|
-
return MomentoVI(config)
|
73
70
|
elif isinstance(config, LanceDBConfig):
|
74
71
|
return LanceDB(config)
|
75
72
|
elif isinstance(config, MeiliSearchConfig):
|
@@ -1,276 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Momento Vector Index.
|
3
|
-
https://docs.momentohq.com/vector-index/develop/api-reference
|
4
|
-
DEPRECATED: API is unstable.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from __future__ import annotations
|
8
|
-
|
9
|
-
import logging
|
10
|
-
import os
|
11
|
-
from typing import List, Optional, Sequence, Tuple, no_type_check
|
12
|
-
|
13
|
-
from dotenv import load_dotenv
|
14
|
-
|
15
|
-
from langroid.exceptions import LangroidImportError
|
16
|
-
|
17
|
-
try:
|
18
|
-
import momento.responses.vector_index as mvi_response
|
19
|
-
from momento import (
|
20
|
-
# PreviewVectorIndexClientAsync,
|
21
|
-
CredentialProvider,
|
22
|
-
PreviewVectorIndexClient,
|
23
|
-
VectorIndexConfigurations,
|
24
|
-
)
|
25
|
-
from momento.requests.vector_index import (
|
26
|
-
ALL_METADATA,
|
27
|
-
Item,
|
28
|
-
SimilarityMetric,
|
29
|
-
)
|
30
|
-
|
31
|
-
has_momento = True
|
32
|
-
except ImportError:
|
33
|
-
has_momento = False
|
34
|
-
|
35
|
-
|
36
|
-
from langroid.embedding_models.base import (
|
37
|
-
EmbeddingModelsConfig,
|
38
|
-
)
|
39
|
-
from langroid.embedding_models.models import OpenAIEmbeddingsConfig
|
40
|
-
from langroid.mytypes import Document
|
41
|
-
from langroid.utils.configuration import settings
|
42
|
-
from langroid.utils.pydantic_utils import (
|
43
|
-
flatten_pydantic_instance,
|
44
|
-
nested_dict_from_flat,
|
45
|
-
)
|
46
|
-
from langroid.vector_store.base import VectorStore, VectorStoreConfig
|
47
|
-
|
48
|
-
logger = logging.getLogger(__name__)
|
49
|
-
|
50
|
-
|
51
|
-
class MomentoVIConfig(VectorStoreConfig):
|
52
|
-
cloud: bool = True
|
53
|
-
collection_name: str | None = "temp"
|
54
|
-
embedding: EmbeddingModelsConfig = OpenAIEmbeddingsConfig()
|
55
|
-
|
56
|
-
|
57
|
-
class MomentoVI(VectorStore):
|
58
|
-
def __init__(self, config: MomentoVIConfig = MomentoVIConfig()):
|
59
|
-
super().__init__(config)
|
60
|
-
if not has_momento:
|
61
|
-
raise LangroidImportError("momento", "momento")
|
62
|
-
self.distance = SimilarityMetric.COSINE_SIMILARITY
|
63
|
-
self.config: MomentoVIConfig = config
|
64
|
-
self.host = config.host
|
65
|
-
self.port = config.port
|
66
|
-
load_dotenv()
|
67
|
-
api_key = os.getenv("MOMENTO_API_KEY")
|
68
|
-
if config.cloud:
|
69
|
-
if api_key is None:
|
70
|
-
raise ValueError(
|
71
|
-
"""MOMENTO_API_KEY env variable must be set to
|
72
|
-
MomentoVI hosted service. Please set this in your .env file.
|
73
|
-
"""
|
74
|
-
)
|
75
|
-
self.client = PreviewVectorIndexClient(
|
76
|
-
configuration=VectorIndexConfigurations.Default.latest(),
|
77
|
-
credential_provider=CredentialProvider.from_string(api_key),
|
78
|
-
)
|
79
|
-
else:
|
80
|
-
raise NotImplementedError("MomentoVI local not available yet")
|
81
|
-
|
82
|
-
# Note: Only create collection if a non-null collection name is provided.
|
83
|
-
# This is useful to delay creation of vecdb until we have a suitable
|
84
|
-
# collection name (e.g. we could get it from the url or folder path).
|
85
|
-
if config.collection_name is not None:
|
86
|
-
self.create_collection(
|
87
|
-
config.collection_name, replace=config.replace_collection
|
88
|
-
)
|
89
|
-
|
90
|
-
def clear_empty_collections(self) -> int:
|
91
|
-
logger.warning(
|
92
|
-
"""
|
93
|
-
Momento VI does not yet have a way to easily get size of indices,
|
94
|
-
so clear_empty_collections is not deleting any indices.
|
95
|
-
"""
|
96
|
-
)
|
97
|
-
return 0
|
98
|
-
|
99
|
-
def clear_all_collections(self, really: bool = False, prefix: str = "") -> int:
|
100
|
-
"""Clear all collections with the given prefix."""
|
101
|
-
|
102
|
-
if not really:
|
103
|
-
logger.warning("Not deleting all collections, set really=True to confirm")
|
104
|
-
return 0
|
105
|
-
coll_names = self.list_collections(empty=False)
|
106
|
-
coll_names = [name for name in coll_names if name.startswith(prefix)]
|
107
|
-
if len(coll_names) == 0:
|
108
|
-
logger.warning(f"No collections found with prefix {prefix}")
|
109
|
-
return 0
|
110
|
-
for name in coll_names:
|
111
|
-
self.delete_collection(name)
|
112
|
-
logger.warning(
|
113
|
-
f"""
|
114
|
-
Deleted {len(coll_names)} indices from Momento VI
|
115
|
-
"""
|
116
|
-
)
|
117
|
-
return len(coll_names)
|
118
|
-
|
119
|
-
def list_collections(self, empty: bool = False) -> List[str]:
|
120
|
-
"""
|
121
|
-
Returns:
|
122
|
-
List of collection names that have at least one vector.
|
123
|
-
|
124
|
-
Args:
|
125
|
-
empty (bool, optional): Whether to include empty collections.
|
126
|
-
"""
|
127
|
-
if not has_momento:
|
128
|
-
raise LangroidImportError("momento", "momento")
|
129
|
-
response = self.client.list_indexes()
|
130
|
-
if isinstance(response, mvi_response.ListIndexes.Success):
|
131
|
-
return [ind.name for ind in response.indexes]
|
132
|
-
elif isinstance(response, mvi_response.ListIndexes.Error):
|
133
|
-
raise ValueError(f"Error listing collections: {response.message}")
|
134
|
-
else:
|
135
|
-
raise ValueError(f"Unexpected response: {response}")
|
136
|
-
|
137
|
-
def create_collection(self, collection_name: str, replace: bool = False) -> None:
|
138
|
-
"""
|
139
|
-
Create a collection with the given name, optionally replacing an existing
|
140
|
-
collection if `replace` is True.
|
141
|
-
Args:
|
142
|
-
collection_name (str): Name of the collection to create.
|
143
|
-
replace (bool): Whether to replace an existing collection
|
144
|
-
with the same name. Defaults to False.
|
145
|
-
"""
|
146
|
-
if not has_momento:
|
147
|
-
raise LangroidImportError("momento", "momento")
|
148
|
-
self.config.collection_name = collection_name
|
149
|
-
response = self.client.create_index(
|
150
|
-
index_name=collection_name,
|
151
|
-
num_dimensions=self.embedding_dim,
|
152
|
-
similarity_metric=self.distance,
|
153
|
-
)
|
154
|
-
if isinstance(response, mvi_response.CreateIndex.Success):
|
155
|
-
logger.info(f"Created collection {collection_name}")
|
156
|
-
elif isinstance(response, mvi_response.CreateIndex.IndexAlreadyExists):
|
157
|
-
logger.warning(f"Collection {collection_name} already exists")
|
158
|
-
elif isinstance(response, mvi_response.CreateIndex.Error):
|
159
|
-
raise ValueError(
|
160
|
-
f"Error creating collection {collection_name}: {response.message}"
|
161
|
-
)
|
162
|
-
if settings.debug:
|
163
|
-
level = logger.getEffectiveLevel()
|
164
|
-
logger.setLevel(logging.INFO)
|
165
|
-
logger.info(f"Collection {collection_name} created")
|
166
|
-
logger.setLevel(level)
|
167
|
-
|
168
|
-
def add_documents(self, documents: Sequence[Document]) -> None:
|
169
|
-
super().maybe_add_ids(documents)
|
170
|
-
if len(documents) == 0:
|
171
|
-
return
|
172
|
-
embedding_vecs = self.embedding_fn([doc.content for doc in documents])
|
173
|
-
if self.config.collection_name is None:
|
174
|
-
raise ValueError("No collection name set, cannot ingest docs")
|
175
|
-
|
176
|
-
self.create_collection(self.config.collection_name, replace=True)
|
177
|
-
|
178
|
-
items = [
|
179
|
-
Item(
|
180
|
-
id=str(d.id()),
|
181
|
-
vector=embedding_vecs[i],
|
182
|
-
metadata=flatten_pydantic_instance(d, force_str=True),
|
183
|
-
# force all values to str since Momento requires it
|
184
|
-
)
|
185
|
-
for i, d in enumerate(documents)
|
186
|
-
]
|
187
|
-
|
188
|
-
# don't insert all at once, batch in chunks of b,
|
189
|
-
# else we get an API error
|
190
|
-
b = self.config.batch_size
|
191
|
-
for i in range(0, len(documents), b):
|
192
|
-
response = self.client.upsert_item_batch(
|
193
|
-
index_name=self.config.collection_name,
|
194
|
-
items=items[i : i + b],
|
195
|
-
)
|
196
|
-
if isinstance(response, mvi_response.UpsertItemBatch.Success):
|
197
|
-
continue
|
198
|
-
elif isinstance(response, mvi_response.UpsertItemBatch.Error):
|
199
|
-
raise ValueError(f"Error adding documents: {response.message}")
|
200
|
-
else:
|
201
|
-
raise ValueError(f"Unexpected response: {response}")
|
202
|
-
|
203
|
-
def delete_collection(self, collection_name: str) -> None:
|
204
|
-
delete_response = self.client.delete_index(collection_name)
|
205
|
-
if isinstance(delete_response, mvi_response.DeleteIndex.Success):
|
206
|
-
logger.warning(f"Deleted index {collection_name}")
|
207
|
-
elif isinstance(delete_response, mvi_response.DeleteIndex.Error):
|
208
|
-
logger.error(
|
209
|
-
f"Error while deleting index {collection_name}: "
|
210
|
-
f" {delete_response.message}"
|
211
|
-
)
|
212
|
-
|
213
|
-
def _to_int_or_uuid(self, id: str) -> int | str:
|
214
|
-
try:
|
215
|
-
return int(id)
|
216
|
-
except ValueError:
|
217
|
-
return id
|
218
|
-
|
219
|
-
def get_all_documents(self, where: str = "") -> List[Document]:
|
220
|
-
raise NotImplementedError(
|
221
|
-
"""
|
222
|
-
MomentoVI does not support get_all_documents().
|
223
|
-
Please use a different vector database, e.g. qdrant or chromadb.
|
224
|
-
"""
|
225
|
-
)
|
226
|
-
|
227
|
-
def get_documents_by_ids(self, ids: List[str]) -> List[Document]:
|
228
|
-
raise NotImplementedError(
|
229
|
-
"""
|
230
|
-
MomentoVI does not support get_documents_by_ids.
|
231
|
-
Please use a different vector database, e.g. qdrant or chromadb.
|
232
|
-
"""
|
233
|
-
)
|
234
|
-
|
235
|
-
@no_type_check
|
236
|
-
def similar_texts_with_scores(
|
237
|
-
self,
|
238
|
-
text: str,
|
239
|
-
k: int = 1,
|
240
|
-
where: Optional[str] = None,
|
241
|
-
neighbors: int = 0, # ignored
|
242
|
-
) -> List[Tuple[Document, float]]:
|
243
|
-
if self.config.collection_name is None:
|
244
|
-
raise ValueError("No collection name set, cannot search")
|
245
|
-
embedding = self.embedding_fn([text])[0]
|
246
|
-
response = self.client.search(
|
247
|
-
index_name=self.config.collection_name,
|
248
|
-
query_vector=embedding,
|
249
|
-
top_k=k,
|
250
|
-
metadata_fields=ALL_METADATA,
|
251
|
-
)
|
252
|
-
|
253
|
-
if isinstance(response, mvi_response.Search.Error):
|
254
|
-
logger.warning(
|
255
|
-
f"Error while searching on index {self.config.collection_name}:"
|
256
|
-
f" {response.message}"
|
257
|
-
)
|
258
|
-
return []
|
259
|
-
elif not isinstance(response, mvi_response.Search.Success):
|
260
|
-
logger.warning(f"Unexpected response: {response}")
|
261
|
-
return []
|
262
|
-
|
263
|
-
scores = [match.metadata["distance"] for match in response.hits]
|
264
|
-
docs = [
|
265
|
-
Document.parse_obj(nested_dict_from_flat(match.metadata))
|
266
|
-
for match in response.hits
|
267
|
-
if match is not None
|
268
|
-
]
|
269
|
-
if len(docs) == 0:
|
270
|
-
logger.warning(f"No matches found for {text}")
|
271
|
-
return []
|
272
|
-
if settings.debug:
|
273
|
-
logger.info(f"Found {len(docs)} matches, max score: {max(scores)}")
|
274
|
-
doc_score_pairs = list(zip(docs, scores))
|
275
|
-
self.show_if_debug(doc_score_pairs)
|
276
|
-
return doc_score_pairs
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.42.3 → langroid-0.42.5}/langroid/agent/special/sql/utils/description_extractors.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/hf_formatter.py
RENAMED
File without changes
|
{langroid-0.42.3 → langroid-0.42.5}/langroid/language_models/prompt_formatter/llama2_formatter.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|