cwyodmodules 0.3.43__py3-none-any.whl → 0.3.45__py3-none-any.whl

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.
@@ -1,92 +1,107 @@
1
- from graphrag.llm.llm import generate_response
2
- from graphrag.query.graph_search import local_query_graph, global_query_graph
3
- from graphrag.query.vector_search import _similarity_search
4
-
5
- from graphrag.database.base import get_db
6
- from graphrag.database.models import Chunk
7
-
8
- from typing import List, Tuple, Any, Dict, Set
9
-
10
- import asyncio
11
-
12
-
13
- async def _local_query(
14
- query: str, top_k: int, max_nodes: int=3, order_range: int=5
15
- ) -> Tuple[str | None, List[str], Dict[str, Dict[str, Any]], List[str]]:
16
-
17
- db = next(get_db())
18
- nodes, keywords = await local_query_graph(query=query, top_k=top_k, order_range=order_range)
19
- chunk_texts: List[str] = []
20
- for chunk_id in nodes:
21
- if len(chunk_texts) >= max_nodes:
22
- break
23
- chunk_texts.append(
24
- db.get(Chunk, chunk_id).text
25
- )
26
-
27
- context = "\n".join(chunk_texts)
28
- response = await generate_response(context=context, query=query)
29
- db.close()
30
- return response, chunk_texts, nodes, keywords
31
-
32
-
33
- async def _global_query(
34
- query: str, top_k: int, max_nodes: int=3, alpha: float=0.7
35
- ) -> Tuple[str | None, List[str], Dict[str, Dict[str, Any]], List[str]]:
36
-
37
- db = next(get_db())
38
- chunks, keywords = await global_query_graph(query=query, top_k=top_k, alpha=alpha, edge_nodes=max_nodes)
39
- chunk_texts: List[str] = []
40
- for chunk_id in chunks:
41
- chunk_texts.append(
42
- db.get(Chunk, chunk_id).text
43
- )
44
-
45
- context = "\n".join(chunk_texts)
46
- response = await generate_response(context=context, query=query)
47
- db.close()
48
- return response, chunk_texts, chunks, keywords
49
-
50
-
51
- async def _hybrid_query(query: str, top_k: int, max_nodes: int=3, alpha: float=0.7, order_range: int=5
52
- ) -> Tuple[str | None, List[str], Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]], Set[str]]:
53
- db = next(get_db())
54
- local_query_task = asyncio.create_task(local_query_graph(query=query, top_k=top_k, order_range=order_range))
55
- global_query_task = asyncio.create_task(global_query_graph(query=query, top_k=top_k, alpha=alpha, edge_nodes=max_nodes))
56
-
57
- (local_nodes, local_keywords), (global_chunks, global_keywords) = await asyncio.gather(*[local_query_task, global_query_task])
58
- chunk_texts: List[str] = []
59
-
60
- seen_ids = set()
61
- for chunk_id in local_nodes:
62
- if len(chunk_texts) >= max_nodes:
63
- break
64
- seen_ids.add(chunk_id)
65
- chunk_texts.append(
66
- db.get(Chunk, chunk_id).text
67
- )
68
-
69
- for chunk_id in global_chunks:
70
- if chunk_id in seen_ids: continue
71
- chunk_texts.append(
72
- db.get(Chunk, chunk_id).text
73
- )
74
-
75
- context = "\n".join(chunk_texts)
76
- response = await generate_response(context=context, query=query)
77
- db.close()
78
- return response, chunk_texts, (global_chunks, local_nodes), set(local_keywords + global_keywords)
79
-
80
-
81
- async def _naive_rag(query: str, top_k: int) -> Tuple[str, List[str]]:
82
- db = next(get_db())
83
- nodes = await _similarity_search(text=query, table='chunk', top_k=top_k)
84
- chunk_texts: List[str] = []
85
- for (node, _) in nodes:
86
- chunk_texts.append(
87
- node.text
88
- )
89
- context = "\n".join(chunk_texts)
90
- response = await generate_response(context=context, query=query)
91
- db.close()
1
+ from ..llm.llm import generate_response
2
+ from .graph_search import local_query_graph, global_query_graph
3
+ from .vector_search import _similarity_search
4
+ from ..database.base import get_db, for_notebook
5
+ from ..database.models import Chunk
6
+ from .utils import (
7
+ separate_by_rank,
8
+ get_nodes,
9
+ get_text_from_nodes,
10
+ get_all_connected_nodes,
11
+ get_final_text,
12
+ get_context_from_db,
13
+ process_chunks,
14
+ get_node_by_id,
15
+ get_node_from_chunk,
16
+ )
17
+ from ..llm.query_generation import (
18
+ generate_query_from_question_prompt,
19
+ generate_response_from_context_prompt,
20
+ )
21
+ import asyncio
22
+ from typing import List, Dict, Tuple, Any, Set
23
+ from collections import defaultdict
24
+ import networkx as nx
25
+ import pandas as pd
26
+
27
+
28
+ async def _local_query(
29
+ query: str, top_k: int, max_nodes: int=3, order_range: int=5
30
+ ) -> Tuple[str | None, List[str], Dict[str, Dict[str, Any]], List[str]]:
31
+
32
+ db = next(get_db())
33
+ nodes, keywords = await local_query_graph(query=query, top_k=top_k, order_range=order_range)
34
+ chunk_texts: List[str] = []
35
+ for chunk_id in nodes:
36
+ if len(chunk_texts) >= max_nodes:
37
+ break
38
+ chunk_texts.append(
39
+ db.get(Chunk, chunk_id).text
40
+ )
41
+
42
+ context = "\n".join(chunk_texts)
43
+ response = await generate_response(context=context, query=query)
44
+ db.close()
45
+ return response, chunk_texts, nodes, keywords
46
+
47
+
48
+ async def _global_query(
49
+ query: str, top_k: int, max_nodes: int=3, alpha: float=0.7
50
+ ) -> Tuple[str | None, List[str], Dict[str, Dict[str, Any]], List[str]]:
51
+
52
+ db = next(get_db())
53
+ chunks, keywords = await global_query_graph(query=query, top_k=top_k, alpha=alpha, edge_nodes=max_nodes)
54
+ chunk_texts: List[str] = []
55
+ for chunk_id in chunks:
56
+ chunk_texts.append(
57
+ db.get(Chunk, chunk_id).text
58
+ )
59
+
60
+ context = "\n".join(chunk_texts)
61
+ response = await generate_response(context=context, query=query)
62
+ db.close()
63
+ return response, chunk_texts, chunks, keywords
64
+
65
+
66
+ async def _hybrid_query(query: str, top_k: int, max_nodes: int=3, alpha: float=0.7, order_range: int=5
67
+ ) -> Tuple[str | None, List[str], Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]], Set[str]]:
68
+ db = next(get_db())
69
+ local_query_task = asyncio.create_task(local_query_graph(query=query, top_k=top_k, order_range=order_range))
70
+ global_query_task = asyncio.create_task(global_query_graph(query=query, top_k=top_k, alpha=alpha, edge_nodes=max_nodes))
71
+
72
+ (local_nodes, local_keywords), (global_chunks, global_keywords) = await asyncio.gather(*[local_query_task, global_query_task])
73
+ chunk_texts: List[str] = []
74
+
75
+ seen_ids = set()
76
+ for chunk_id in local_nodes:
77
+ if len(chunk_texts) >= max_nodes:
78
+ break
79
+ seen_ids.add(chunk_id)
80
+ chunk_texts.append(
81
+ db.get(Chunk, chunk_id).text
82
+ )
83
+
84
+ for chunk_id in global_chunks:
85
+ if chunk_id in seen_ids: continue
86
+ chunk_texts.append(
87
+ db.get(Chunk, chunk_id).text
88
+ )
89
+
90
+ context = "\n".join(chunk_texts)
91
+ response = await generate_response(context=context, query=query)
92
+ db.close()
93
+ return response, chunk_texts, (global_chunks, local_nodes), set(local_keywords + global_keywords)
94
+
95
+
96
+ async def _naive_rag(query: str, top_k: int) -> Tuple[str, List[str]]:
97
+ db = next(get_db())
98
+ nodes = await _similarity_search(text=query, table='chunk', top_k=top_k)
99
+ chunk_texts: List[str] = []
100
+ for (node, _) in nodes:
101
+ chunk_texts.append(
102
+ node.text
103
+ )
104
+ context = "\n".join(chunk_texts)
105
+ response = await generate_response(context=context, query=query)
106
+ db.close()
92
107
  return response, chunk_texts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cwyodmodules
3
- Version: 0.3.43
3
+ Version: 0.3.45
4
4
  Summary: Add your description here
5
5
  Author-email: Patrik <patrikhartl@gmail.com>
6
6
  Classifier: Operating System :: OS Independent
@@ -1,3 +1,4 @@
1
+ cwyodmodules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1
2
  cwyodmodules/mgmt_config.py,sha256=xRp9absSmQifcKKCn6fyqcMSJ9hDvMTqPPAViezJHZw,5308
2
3
  cwyodmodules/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
4
  cwyodmodules/api/chat_history.py,sha256=bVXFmhTHIfEiHv_nBrfizO-cQRHhKgrdcZ07OD1b0Tw,20683
@@ -40,12 +41,13 @@ cwyodmodules/batch/utilities/helpers/env_helper.py,sha256=S0EG0XzILrJ_iPCAwKN-kz
40
41
  cwyodmodules/batch/utilities/helpers/lightrag_helper.py,sha256=7lb9JMm5IohsO73LWo5bWmlzWCGYNsx_fYl-aFdwATQ,3845
41
42
  cwyodmodules/batch/utilities/helpers/llm_helper.py,sha256=lHLYrUidtaemmKrVbWoo7oIvwluUoPUk16U5lV-YIX8,8282
42
43
  cwyodmodules/batch/utilities/helpers/orchestrator_helper.py,sha256=mCcZyMFG0otnw9gzWd-PYocHmDdFDVg-RT9oDPiDZPk,897
43
- cwyodmodules/batch/utilities/helpers/secret_helper.py,sha256=RYDPR-1c7uChfmAJfzvN_GiI4u6czyWZ67XQah0hla4,2756
44
+ cwyodmodules/batch/utilities/helpers/secret_helper.py,sha256=KacIc2hHpWtgButUnR3sFC9StLS36HjYvNpTmf2f4gc,2834
45
+ cwyodmodules/batch/utilities/helpers/config/agent_mode.py,sha256=8XMbu8dwMXva_xxeZNDlwOjDaZwIcwc-xJK1-QsaJ3w,82
44
46
  cwyodmodules/batch/utilities/helpers/config/assistant_strategy.py,sha256=uT8h646zEURU9x8oDOH7pWoZKb0Mw6dA2nJtA2M-ufg,171
45
- cwyodmodules/batch/utilities/helpers/config/config_helper.py,sha256=26na6YrLqRLhdSZxTSlOnJOkIcPbTcbFVuPEQTPT3WY,14908
47
+ cwyodmodules/batch/utilities/helpers/config/config_helper.py,sha256=rHP9YgkwG9UodAlRALesQ54M_dDsl801s_gP710vqHk,15685
46
48
  cwyodmodules/batch/utilities/helpers/config/conversation_flow.py,sha256=4nP8a-I-sME5-2unzWWBNpTzWdfpfc5_EAYU6Pn6LAQ,94
47
49
  cwyodmodules/batch/utilities/helpers/config/database_type.py,sha256=Zmmlh1NAKDdd-2ei478boncRKcx8v3lDkPf4kO2j4ss,132
48
- cwyodmodules/batch/utilities/helpers/config/default.json,sha256=FnW-cSQJr4xkFwe3B44HtpDeJr8iPDIYfKxBUVdPXQs,15259
50
+ cwyodmodules/batch/utilities/helpers/config/default.json,sha256=kwZg04XoLlKnva22o_YIuC31jWeSTpuewJTG9oyJP9o,15430
49
51
  cwyodmodules/batch/utilities/helpers/config/default_contract_assistant_prompt.txt,sha256=X39WGcxzQPIvqG7NpAMPsgmSwSyMEoK1DVWiuEHEHRg,3210
50
52
  cwyodmodules/batch/utilities/helpers/config/default_employee_assistant_prompt.txt,sha256=toQFo0wXYrEK7zAItAS9rbtyhT6DJZKBhiL6C9VPUQk,3942
51
53
  cwyodmodules/batch/utilities/helpers/config/embedding_config.py,sha256=9pCJxpsouln9dngjVHaKGFYP14PrwmSts_UFDytSiVk,950
@@ -90,13 +92,13 @@ cwyodmodules/batch/utilities/tools/question_answer_tool.py,sha256=8GWurj50bUND_4
90
92
  cwyodmodules/batch/utilities/tools/text_processing_tool.py,sha256=zCF83SQaC8k6z6-Gevxj6AdDKzhU3P_6FG0hAnrG5Zk,1824
91
93
  cwyodmodules/graphrag/__init__.py,sha256=O5fi4Q3RC9Gt8ItNZGV1HjyIJvEz7grYXTFMmUWstxw,111
92
94
  cwyodmodules/graphrag/config.py,sha256=TvG45dezHkqgZzWnPxhpyWciIiKOrD_3JQ3APkoD6Hw,1525
93
- cwyodmodules/graphrag/main.py,sha256=8_z5X3b00J1FYnq43LrbJpOC3bKGkuyZQglgtBtVO2I,2201
95
+ cwyodmodules/graphrag/main.py,sha256=Ot4hu0muElQGge9L9-8lZSTswgG8YPRoQjXE6wnZ2Gw,2211
94
96
  cwyodmodules/graphrag/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
95
97
  cwyodmodules/graphrag/database/base.py,sha256=d8CCJYAyEqu3F9m4qfvszMKJGOP0tD0FpTEUbjDDHqU,751
96
98
  cwyodmodules/graphrag/database/models.py,sha256=4NZt2ZSeyaR1bkrUZQHYWPxWHK49-XNV6Wt3n3zVTcg,2803
97
99
  cwyodmodules/graphrag/indexing/__init__.py,sha256=TdI1oChZYljm_ao4GPQ3Oe8ESeeDKGsyheqoHFf5sJQ,125
98
100
  cwyodmodules/graphrag/indexing/chunking.py,sha256=hSEH6KoHemQg1tB4-_BN4r7ZMLBQ94ctV9EUwgKiQcc,7216
99
- cwyodmodules/graphrag/indexing/extraction.py,sha256=Pe1gukVxpq7lmV62oiIMVc8TTn4IGNQtI5MFRifbhe4,10377
101
+ cwyodmodules/graphrag/indexing/extraction.py,sha256=LwV29UVyhdAIkcd30GSQrfx-ilxsg4tHHCsPmNqrA9M,10822
100
102
  cwyodmodules/graphrag/indexing/types.py,sha256=wIn-q-eGVdmcNvDt0gGXIdqJcvwK5exRqtuWtLu2z0Y,2457
101
103
  cwyodmodules/graphrag/indexing/upsert.py,sha256=BhinBPaq2z0ApHWSG0XzmqXFsrXuiCJcQyL1hhnM1C0,4814
102
104
  cwyodmodules/graphrag/indexing/utils.py,sha256=kvjpBSyRsJcdCybz1Eqd2itFEe4cm76AxqJ_F7n3JEs,169
@@ -104,12 +106,12 @@ cwyodmodules/graphrag/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
104
106
  cwyodmodules/graphrag/llm/llm.py,sha256=sxWqiiMG-iuVvNPYnlqC9mDdld2JP8iPGhzaBq-zk6M,4850
105
107
  cwyodmodules/graphrag/llm/prompt.py,sha256=h4F4j-i6MxpeSz1Kiyhr_hMdiIQOcNosR_HR-zmSoMU,6674
106
108
  cwyodmodules/graphrag/query/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
107
- cwyodmodules/graphrag/query/generate.py,sha256=xBnZs2U9xFWtPk4AfAZgYKbHdcxNcIO6Q_D5dWJ_8qg,3323
109
+ cwyodmodules/graphrag/query/generate.py,sha256=BZiB6iw7PkIovw-CyYFogMHnDxK0Qu_4uCe494nYEFY,3816
108
110
  cwyodmodules/graphrag/query/graph_search.py,sha256=95h3ecSWx4864XgKABtG0fh3Nk8HkqJVzoCrO8daJ-Y,7724
109
111
  cwyodmodules/graphrag/query/types.py,sha256=1Iq1dp4I4a56_cuFjOZ0NTgd0A2_MpVFznp_czgt6cI,617
110
112
  cwyodmodules/graphrag/query/vector_search.py,sha256=9Gwu9LPjtoAYUU8WKqCvbCHAIg3dpk71reoYd1scLnQ,1807
111
- cwyodmodules-0.3.43.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
112
- cwyodmodules-0.3.43.dist-info/METADATA,sha256=CJHnTq4Q2E-Dcn8GiIYWPqI4jyvxQ1S44KIVClTitQY,2002
113
- cwyodmodules-0.3.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
- cwyodmodules-0.3.43.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
115
- cwyodmodules-0.3.43.dist-info/RECORD,,
113
+ cwyodmodules-0.3.45.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
114
+ cwyodmodules-0.3.45.dist-info/METADATA,sha256=dhCo5n3jzElUG7B7kF2FimtLv8dXN5kYYF15zVZaaNU,2002
115
+ cwyodmodules-0.3.45.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
116
+ cwyodmodules-0.3.45.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
117
+ cwyodmodules-0.3.45.dist-info/RECORD,,