cognee 0.3.4.dev3__py3-none-any.whl → 0.3.5__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.
Files changed (186) hide show
  1. cognee/api/client.py +16 -7
  2. cognee/api/health.py +5 -9
  3. cognee/api/v1/add/add.py +3 -1
  4. cognee/api/v1/cognify/cognify.py +44 -7
  5. cognee/api/v1/permissions/routers/get_permissions_router.py +8 -4
  6. cognee/api/v1/search/search.py +3 -0
  7. cognee/api/v1/ui/__init__.py +1 -1
  8. cognee/api/v1/ui/ui.py +215 -150
  9. cognee/api/v1/update/__init__.py +1 -0
  10. cognee/api/v1/update/routers/__init__.py +1 -0
  11. cognee/api/v1/update/routers/get_update_router.py +90 -0
  12. cognee/api/v1/update/update.py +100 -0
  13. cognee/base_config.py +5 -2
  14. cognee/cli/_cognee.py +28 -10
  15. cognee/cli/commands/delete_command.py +34 -2
  16. cognee/eval_framework/corpus_builder/task_getters/get_default_tasks_by_indices.py +2 -2
  17. cognee/eval_framework/evaluation/direct_llm_eval_adapter.py +3 -2
  18. cognee/eval_framework/modal_eval_dashboard.py +9 -1
  19. cognee/infrastructure/databases/graph/config.py +9 -9
  20. cognee/infrastructure/databases/graph/get_graph_engine.py +4 -21
  21. cognee/infrastructure/databases/graph/kuzu/adapter.py +60 -9
  22. cognee/infrastructure/databases/hybrid/neptune_analytics/NeptuneAnalyticsAdapter.py +3 -3
  23. cognee/infrastructure/databases/relational/config.py +4 -4
  24. cognee/infrastructure/databases/relational/create_relational_engine.py +11 -3
  25. cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +7 -3
  26. cognee/infrastructure/databases/vector/config.py +7 -7
  27. cognee/infrastructure/databases/vector/create_vector_engine.py +7 -15
  28. cognee/infrastructure/databases/vector/embeddings/EmbeddingEngine.py +9 -0
  29. cognee/infrastructure/databases/vector/embeddings/FastembedEmbeddingEngine.py +11 -0
  30. cognee/infrastructure/databases/vector/embeddings/LiteLLMEmbeddingEngine.py +19 -2
  31. cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +11 -0
  32. cognee/infrastructure/databases/vector/embeddings/config.py +8 -0
  33. cognee/infrastructure/databases/vector/embeddings/get_embedding_engine.py +5 -0
  34. cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py +11 -10
  35. cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py +48 -38
  36. cognee/infrastructure/databases/vector/vector_db_interface.py +8 -4
  37. cognee/infrastructure/files/storage/S3FileStorage.py +15 -5
  38. cognee/infrastructure/files/storage/s3_config.py +1 -0
  39. cognee/infrastructure/files/utils/open_data_file.py +7 -14
  40. cognee/infrastructure/llm/LLMGateway.py +19 -117
  41. cognee/infrastructure/llm/config.py +28 -13
  42. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_categories.py +2 -1
  43. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_event_entities.py +3 -2
  44. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/extract_summary.py +3 -2
  45. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/extract_content_graph.py +2 -1
  46. cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/extract_event_graph.py +3 -2
  47. cognee/infrastructure/llm/prompts/read_query_prompt.py +3 -2
  48. cognee/infrastructure/llm/prompts/show_prompt.py +35 -0
  49. cognee/infrastructure/llm/prompts/test.txt +1 -0
  50. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/__init__.py +2 -2
  51. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/async_client.py +50 -397
  52. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/inlinedbaml.py +2 -3
  53. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/parser.py +8 -88
  54. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/runtime.py +78 -0
  55. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/stream_types.py +2 -99
  56. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/sync_client.py +49 -401
  57. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_builder.py +19 -882
  58. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/type_map.py +2 -34
  59. cognee/infrastructure/llm/structured_output_framework/baml/baml_client/types.py +2 -107
  60. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/acreate_structured_output.baml +26 -0
  61. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/__init__.py +1 -2
  62. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/acreate_structured_output.py +76 -0
  63. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/create_dynamic_baml_type.py +122 -0
  64. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/generators.baml +3 -3
  65. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +0 -32
  66. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/gemini/adapter.py +107 -98
  67. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/generic_llm_api/adapter.py +5 -6
  68. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/get_llm_client.py +5 -6
  69. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/llm_interface.py +0 -26
  70. cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/openai/adapter.py +17 -67
  71. cognee/infrastructure/llm/tokenizer/Gemini/adapter.py +8 -7
  72. cognee/infrastructure/llm/utils.py +4 -4
  73. cognee/infrastructure/loaders/LoaderEngine.py +5 -2
  74. cognee/infrastructure/loaders/external/__init__.py +7 -0
  75. cognee/infrastructure/loaders/external/advanced_pdf_loader.py +244 -0
  76. cognee/infrastructure/loaders/supported_loaders.py +7 -0
  77. cognee/modules/data/methods/create_authorized_dataset.py +9 -0
  78. cognee/modules/data/methods/get_authorized_dataset.py +1 -1
  79. cognee/modules/data/methods/get_authorized_dataset_by_name.py +11 -0
  80. cognee/modules/data/methods/get_deletion_counts.py +92 -0
  81. cognee/modules/graph/cognee_graph/CogneeGraph.py +1 -1
  82. cognee/modules/graph/utils/expand_with_nodes_and_edges.py +22 -8
  83. cognee/modules/graph/utils/retrieve_existing_edges.py +0 -2
  84. cognee/modules/ingestion/data_types/TextData.py +0 -1
  85. cognee/modules/notebooks/methods/create_notebook.py +3 -1
  86. cognee/modules/notebooks/methods/get_notebooks.py +27 -1
  87. cognee/modules/observability/get_observe.py +14 -0
  88. cognee/modules/observability/observers.py +1 -0
  89. cognee/modules/ontology/base_ontology_resolver.py +42 -0
  90. cognee/modules/ontology/get_default_ontology_resolver.py +41 -0
  91. cognee/modules/ontology/matching_strategies.py +53 -0
  92. cognee/modules/ontology/models.py +20 -0
  93. cognee/modules/ontology/ontology_config.py +24 -0
  94. cognee/modules/ontology/ontology_env_config.py +45 -0
  95. cognee/modules/ontology/rdf_xml/{OntologyResolver.py → RDFLibOntologyResolver.py} +20 -28
  96. cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +21 -24
  97. cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +3 -3
  98. cognee/modules/retrieval/code_retriever.py +2 -1
  99. cognee/modules/retrieval/context_providers/TripletSearchContextProvider.py +1 -4
  100. cognee/modules/retrieval/graph_completion_cot_retriever.py +6 -5
  101. cognee/modules/retrieval/graph_completion_retriever.py +0 -3
  102. cognee/modules/retrieval/insights_retriever.py +1 -1
  103. cognee/modules/retrieval/jaccard_retrival.py +60 -0
  104. cognee/modules/retrieval/lexical_retriever.py +123 -0
  105. cognee/modules/retrieval/natural_language_retriever.py +2 -1
  106. cognee/modules/retrieval/temporal_retriever.py +3 -2
  107. cognee/modules/retrieval/utils/brute_force_triplet_search.py +2 -12
  108. cognee/modules/retrieval/utils/completion.py +4 -7
  109. cognee/modules/search/methods/get_search_type_tools.py +7 -0
  110. cognee/modules/search/methods/no_access_control_search.py +1 -1
  111. cognee/modules/search/methods/search.py +32 -13
  112. cognee/modules/search/types/SearchType.py +1 -0
  113. cognee/modules/users/methods/create_user.py +0 -2
  114. cognee/modules/users/permissions/methods/authorized_give_permission_on_datasets.py +12 -0
  115. cognee/modules/users/permissions/methods/check_permission_on_dataset.py +11 -0
  116. cognee/modules/users/permissions/methods/get_all_user_permission_datasets.py +10 -0
  117. cognee/modules/users/permissions/methods/get_document_ids_for_user.py +10 -0
  118. cognee/modules/users/permissions/methods/get_principal.py +9 -0
  119. cognee/modules/users/permissions/methods/get_principal_datasets.py +11 -0
  120. cognee/modules/users/permissions/methods/get_role.py +10 -0
  121. cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +3 -3
  122. cognee/modules/users/permissions/methods/get_tenant.py +9 -0
  123. cognee/modules/users/permissions/methods/give_default_permission_to_role.py +9 -0
  124. cognee/modules/users/permissions/methods/give_default_permission_to_tenant.py +9 -0
  125. cognee/modules/users/permissions/methods/give_default_permission_to_user.py +9 -0
  126. cognee/modules/users/permissions/methods/give_permission_on_dataset.py +10 -0
  127. cognee/modules/users/roles/methods/add_user_to_role.py +11 -0
  128. cognee/modules/users/roles/methods/create_role.py +12 -1
  129. cognee/modules/users/tenants/methods/add_user_to_tenant.py +12 -0
  130. cognee/modules/users/tenants/methods/create_tenant.py +12 -1
  131. cognee/modules/visualization/cognee_network_visualization.py +13 -9
  132. cognee/shared/data_models.py +0 -1
  133. cognee/shared/utils.py +0 -32
  134. cognee/tasks/chunk_naive_llm_classifier/chunk_naive_llm_classifier.py +2 -2
  135. cognee/tasks/codingagents/coding_rule_associations.py +3 -2
  136. cognee/tasks/entity_completion/entity_extractors/llm_entity_extractor.py +3 -2
  137. cognee/tasks/graph/cascade_extract/utils/extract_content_nodes_and_relationship_names.py +3 -2
  138. cognee/tasks/graph/cascade_extract/utils/extract_edge_triplets.py +3 -2
  139. cognee/tasks/graph/cascade_extract/utils/extract_nodes.py +3 -2
  140. cognee/tasks/graph/extract_graph_from_code.py +2 -2
  141. cognee/tasks/graph/extract_graph_from_data.py +55 -12
  142. cognee/tasks/graph/extract_graph_from_data_v2.py +16 -4
  143. cognee/tasks/ingestion/migrate_relational_database.py +132 -41
  144. cognee/tasks/ingestion/resolve_data_directories.py +4 -1
  145. cognee/tasks/schema/ingest_database_schema.py +134 -0
  146. cognee/tasks/schema/models.py +40 -0
  147. cognee/tasks/storage/index_data_points.py +1 -1
  148. cognee/tasks/storage/index_graph_edges.py +3 -1
  149. cognee/tasks/summarization/summarize_code.py +2 -2
  150. cognee/tasks/summarization/summarize_text.py +2 -2
  151. cognee/tasks/temporal_graph/enrich_events.py +2 -2
  152. cognee/tasks/temporal_graph/extract_events_and_entities.py +2 -2
  153. cognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py +13 -4
  154. cognee/tests/cli_tests/cli_unit_tests/test_cli_edge_cases.py +13 -3
  155. cognee/tests/test_advanced_pdf_loader.py +141 -0
  156. cognee/tests/test_chromadb.py +40 -0
  157. cognee/tests/test_cognee_server_start.py +6 -1
  158. cognee/tests/test_data/Quantum_computers.txt +9 -0
  159. cognee/tests/test_lancedb.py +211 -0
  160. cognee/tests/test_pgvector.py +40 -0
  161. cognee/tests/test_relational_db_migration.py +76 -0
  162. cognee/tests/unit/infrastructure/databases/test_index_graph_edges.py +2 -1
  163. cognee/tests/unit/modules/ontology/test_ontology_adapter.py +330 -13
  164. cognee/tests/unit/modules/retrieval/graph_completion_retriever_context_extension_test.py +0 -4
  165. cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +0 -4
  166. cognee/tests/unit/modules/retrieval/graph_completion_retriever_test.py +0 -4
  167. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/METADATA +92 -96
  168. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/RECORD +176 -162
  169. distributed/pyproject.toml +0 -1
  170. cognee/infrastructure/data/utils/extract_keywords.py +0 -48
  171. cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py +0 -1227
  172. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_categories.baml +0 -109
  173. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extract_content_graph.baml +0 -343
  174. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/extract_categories.py +0 -0
  175. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/extract_summary.py +0 -89
  176. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/__init__.py +0 -0
  177. cognee/infrastructure/llm/structured_output_framework/baml/baml_src/extraction/knowledge_graph/extract_content_graph.py +0 -44
  178. cognee/tasks/graph/infer_data_ontology.py +0 -309
  179. cognee/tests/test_falkordb.py +0 -174
  180. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/__init__.py +0 -0
  181. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/knowledge_graph/__init__.py +0 -0
  182. /cognee/infrastructure/llm/{structured_output_framework/litellm_instructor/extraction → extraction}/texts.json +0 -0
  183. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/WHEEL +0 -0
  184. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/entry_points.txt +0 -0
  185. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/licenses/LICENSE +0 -0
  186. {cognee-0.3.4.dev3.dist-info → cognee-0.3.5.dist-info}/licenses/NOTICE.md +0 -0
@@ -9,24 +9,30 @@ class LLMGateway:
9
9
  Class used as a namespace for LLM related functions, should not be instantiated, all methods are static.
10
10
  """
11
11
 
12
- @staticmethod
13
- def render_prompt(filename: str, context: dict, base_directory: str = None):
14
- from cognee.infrastructure.llm.prompts import render_prompt
15
-
16
- return render_prompt(filename=filename, context=context, base_directory=base_directory)
17
-
18
12
  @staticmethod
19
13
  def acreate_structured_output(
20
14
  text_input: str, system_prompt: str, response_model: Type[BaseModel]
21
15
  ) -> Coroutine:
22
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.get_llm_client import (
23
- get_llm_client,
24
- )
16
+ llm_config = get_llm_config()
17
+ if llm_config.structured_output_framework.upper() == "BAML":
18
+ from cognee.infrastructure.llm.structured_output_framework.baml.baml_src.extraction import (
19
+ acreate_structured_output,
20
+ )
25
21
 
26
- llm_client = get_llm_client()
27
- return llm_client.acreate_structured_output(
28
- text_input=text_input, system_prompt=system_prompt, response_model=response_model
29
- )
22
+ return acreate_structured_output(
23
+ text_input=text_input,
24
+ system_prompt=system_prompt,
25
+ response_model=response_model,
26
+ )
27
+ else:
28
+ from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.get_llm_client import (
29
+ get_llm_client,
30
+ )
31
+
32
+ llm_client = get_llm_client()
33
+ return llm_client.acreate_structured_output(
34
+ text_input=text_input, system_prompt=system_prompt, response_model=response_model
35
+ )
30
36
 
31
37
  @staticmethod
32
38
  def create_structured_output(
@@ -58,107 +64,3 @@ class LLMGateway:
58
64
 
59
65
  llm_client = get_llm_client()
60
66
  return llm_client.transcribe_image(input=input)
61
-
62
- @staticmethod
63
- def show_prompt(text_input: str, system_prompt: str) -> str:
64
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.llm.get_llm_client import (
65
- get_llm_client,
66
- )
67
-
68
- llm_client = get_llm_client()
69
- return llm_client.show_prompt(text_input=text_input, system_prompt=system_prompt)
70
-
71
- @staticmethod
72
- def read_query_prompt(prompt_file_name: str, base_directory: str = None):
73
- from cognee.infrastructure.llm.prompts import (
74
- read_query_prompt,
75
- )
76
-
77
- return read_query_prompt(prompt_file_name=prompt_file_name, base_directory=base_directory)
78
-
79
- @staticmethod
80
- def extract_content_graph(
81
- content: str,
82
- response_model: Type[BaseModel],
83
- mode: str = "simple",
84
- custom_prompt: Optional[str] = None,
85
- ) -> Coroutine:
86
- llm_config = get_llm_config()
87
- if llm_config.structured_output_framework.upper() == "BAML":
88
- from cognee.infrastructure.llm.structured_output_framework.baml.baml_src.extraction import (
89
- extract_content_graph,
90
- )
91
-
92
- return extract_content_graph(
93
- content=content,
94
- response_model=response_model,
95
- mode=mode,
96
- custom_prompt=custom_prompt,
97
- )
98
- else:
99
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
100
- extract_content_graph,
101
- )
102
-
103
- return extract_content_graph(
104
- content=content, response_model=response_model, custom_prompt=custom_prompt
105
- )
106
-
107
- @staticmethod
108
- def extract_categories(content: str, response_model: Type[BaseModel]) -> Coroutine:
109
- # TODO: Add BAML version of category and extraction and update function
110
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
111
- extract_categories,
112
- )
113
-
114
- return extract_categories(content=content, response_model=response_model)
115
-
116
- @staticmethod
117
- def extract_code_summary(content: str) -> Coroutine:
118
- llm_config = get_llm_config()
119
- if llm_config.structured_output_framework.upper() == "BAML":
120
- from cognee.infrastructure.llm.structured_output_framework.baml.baml_src.extraction import (
121
- extract_code_summary,
122
- )
123
-
124
- return extract_code_summary(content=content)
125
- else:
126
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
127
- extract_code_summary,
128
- )
129
-
130
- return extract_code_summary(content=content)
131
-
132
- @staticmethod
133
- def extract_summary(content: str, response_model: Type[BaseModel]) -> Coroutine:
134
- llm_config = get_llm_config()
135
- if llm_config.structured_output_framework.upper() == "BAML":
136
- from cognee.infrastructure.llm.structured_output_framework.baml.baml_src.extraction import (
137
- extract_summary,
138
- )
139
-
140
- return extract_summary(content=content, response_model=response_model)
141
- else:
142
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
143
- extract_summary,
144
- )
145
-
146
- return extract_summary(content=content, response_model=response_model)
147
-
148
- @staticmethod
149
- def extract_event_graph(content: str, response_model: Type[BaseModel]) -> Coroutine:
150
- # TODO: Add BAML version of category and extraction and update function (consulted with Igor)
151
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
152
- extract_event_graph,
153
- )
154
-
155
- return extract_event_graph(content=content, response_model=response_model)
156
-
157
- @staticmethod
158
- def extract_event_entities(content: str, response_model: Type[BaseModel]) -> Coroutine:
159
- # TODO: Add BAML version of category and extraction and update function (consulted with Igor)
160
- from cognee.infrastructure.llm.structured_output_framework.litellm_instructor.extraction import (
161
- extract_event_entities,
162
- )
163
-
164
- return extract_event_entities(content=content, response_model=response_model)
@@ -1,9 +1,13 @@
1
1
  import os
2
- from typing import Optional, ClassVar
2
+ from typing import Optional, ClassVar, Any
3
3
  from functools import lru_cache
4
4
  from pydantic_settings import BaseSettings, SettingsConfigDict
5
5
  from pydantic import model_validator
6
- from baml_py import ClientRegistry
6
+
7
+ try:
8
+ from baml_py import ClientRegistry
9
+ except ImportError:
10
+ ClientRegistry = None
7
11
 
8
12
 
9
13
  class LLMConfig(BaseSettings):
@@ -35,7 +39,7 @@ class LLMConfig(BaseSettings):
35
39
 
36
40
  structured_output_framework: str = "instructor"
37
41
  llm_provider: str = "openai"
38
- llm_model: str = "openai/gpt-4o-mini"
42
+ llm_model: str = "openai/gpt-5-mini"
39
43
  llm_endpoint: str = ""
40
44
  llm_api_key: Optional[str] = None
41
45
  llm_api_version: Optional[str] = None
@@ -44,7 +48,7 @@ class LLMConfig(BaseSettings):
44
48
  llm_max_completion_tokens: int = 16384
45
49
 
46
50
  baml_llm_provider: str = "openai"
47
- baml_llm_model: str = "gpt-4o-mini"
51
+ baml_llm_model: str = "gpt-5-mini"
48
52
  baml_llm_endpoint: str = ""
49
53
  baml_llm_api_key: Optional[str] = None
50
54
  baml_llm_temperature: float = 0.0
@@ -65,25 +69,36 @@ class LLMConfig(BaseSettings):
65
69
  fallback_endpoint: str = ""
66
70
  fallback_model: str = ""
67
71
 
68
- baml_registry: ClassVar[ClientRegistry] = ClientRegistry()
72
+ baml_registry: Optional[Any] = None
69
73
 
70
74
  model_config = SettingsConfigDict(env_file=".env", extra="allow")
71
75
 
72
76
  def model_post_init(self, __context) -> None:
73
77
  """Initialize the BAML registry after the model is created."""
74
- self.baml_registry.add_llm_client(
75
- name=self.baml_llm_provider,
76
- provider=self.baml_llm_provider,
77
- options={
78
+ # Check if BAML is selected as structured output framework but not available
79
+ if self.structured_output_framework.lower() == "baml" and ClientRegistry is None:
80
+ raise ImportError(
81
+ "BAML is selected as structured output framework but not available. "
82
+ "Please install with 'pip install cognee\"[baml]\"' to use BAML extraction features."
83
+ )
84
+ elif self.structured_output_framework.lower() == "baml" and ClientRegistry is not None:
85
+ self.baml_registry = ClientRegistry()
86
+
87
+ raw_options = {
78
88
  "model": self.baml_llm_model,
79
89
  "temperature": self.baml_llm_temperature,
80
90
  "api_key": self.baml_llm_api_key,
81
91
  "base_url": self.baml_llm_endpoint,
82
92
  "api_version": self.baml_llm_api_version,
83
- },
84
- )
85
- # Sets the primary client
86
- self.baml_registry.set_primary(self.baml_llm_provider)
93
+ }
94
+
95
+ # Note: keep the item only when the value is not None or an empty string (they would override baml default values)
96
+ options = {k: v for k, v in raw_options.items() if v not in (None, "")}
97
+ self.baml_registry.add_llm_client(
98
+ name=self.baml_llm_provider, provider=self.baml_llm_provider, options=options
99
+ )
100
+ # Sets the primary client
101
+ self.baml_registry.set_primary(self.baml_llm_provider)
87
102
 
88
103
  @model_validator(mode="after")
89
104
  def ensure_env_vars_for_ollama(self) -> "LLMConfig":
@@ -1,11 +1,12 @@
1
1
  from typing import Type
2
2
  from pydantic import BaseModel
3
3
 
4
+ from cognee.infrastructure.llm.prompts import read_query_prompt
4
5
  from cognee.infrastructure.llm.LLMGateway import LLMGateway
5
6
 
6
7
 
7
8
  async def extract_categories(content: str, response_model: Type[BaseModel]):
8
- system_prompt = LLMGateway.read_query_prompt("classify_content.txt")
9
+ system_prompt = read_query_prompt("classify_content.txt")
9
10
 
10
11
  llm_output = await LLMGateway.acreate_structured_output(content, system_prompt, response_model)
11
12
 
@@ -1,6 +1,7 @@
1
1
  import os
2
- from typing import List, Type
2
+ from typing import Type
3
3
  from pydantic import BaseModel
4
+ from cognee.infrastructure.llm.prompts.render_prompt import render_prompt
4
5
  from cognee.infrastructure.llm.LLMGateway import LLMGateway
5
6
  from cognee.infrastructure.llm.config import (
6
7
  get_llm_config,
@@ -35,7 +36,7 @@ async def extract_event_entities(content: str, response_model: Type[BaseModel]):
35
36
  else:
36
37
  base_directory = None
37
38
 
38
- system_prompt = LLMGateway.render_prompt(prompt_path, {}, base_directory=base_directory)
39
+ system_prompt = render_prompt(prompt_path, {}, base_directory=base_directory)
39
40
 
40
41
  content_graph = await LLMGateway.acreate_structured_output(
41
42
  content, system_prompt, response_model
@@ -2,7 +2,8 @@ from cognee.shared.logging_utils import get_logger
2
2
  import os
3
3
  from typing import Type
4
4
 
5
- from instructor.exceptions import InstructorRetryException
5
+ from instructor.core import InstructorRetryException
6
+ from cognee.infrastructure.llm.prompts import read_query_prompt
6
7
  from pydantic import BaseModel
7
8
 
8
9
  from cognee.infrastructure.llm.LLMGateway import LLMGateway
@@ -25,7 +26,7 @@ def get_mock_summarized_code():
25
26
 
26
27
 
27
28
  async def extract_summary(content: str, response_model: Type[BaseModel]):
28
- system_prompt = LLMGateway.read_query_prompt("summarize_content.txt")
29
+ system_prompt = read_query_prompt("summarize_content.txt")
29
30
 
30
31
  llm_output = await LLMGateway.acreate_structured_output(content, system_prompt, response_model)
31
32
 
@@ -2,6 +2,7 @@ import os
2
2
  from typing import Type, Optional
3
3
  from pydantic import BaseModel
4
4
 
5
+ from cognee.infrastructure.llm.prompts import render_prompt
5
6
  from cognee.infrastructure.llm.LLMGateway import LLMGateway
6
7
  from cognee.infrastructure.llm.config import (
7
8
  get_llm_config,
@@ -26,7 +27,7 @@ async def extract_content_graph(
26
27
  else:
27
28
  base_directory = None
28
29
 
29
- system_prompt = LLMGateway.render_prompt(prompt_path, {}, base_directory=base_directory)
30
+ system_prompt = render_prompt(prompt_path, {}, base_directory=base_directory)
30
31
 
31
32
  content_graph = await LLMGateway.acreate_structured_output(
32
33
  content, system_prompt, response_model
@@ -1,8 +1,9 @@
1
1
  import os
2
2
  from pydantic import BaseModel
3
3
  from typing import Type
4
- from cognee.infrastructure.llm.LLMGateway import LLMGateway
5
4
 
5
+ from cognee.infrastructure.llm.prompts import render_prompt
6
+ from cognee.infrastructure.llm.LLMGateway import LLMGateway
6
7
  from cognee.infrastructure.llm.config import (
7
8
  get_llm_config,
8
9
  )
@@ -37,7 +38,7 @@ async def extract_event_graph(content: str, response_model: Type[BaseModel]):
37
38
  else:
38
39
  base_directory = None
39
40
 
40
- system_prompt = LLMGateway.render_prompt(prompt_path, {}, base_directory=base_directory)
41
+ system_prompt = render_prompt(prompt_path, {}, base_directory=base_directory)
41
42
 
42
43
  content_graph = await LLMGateway.acreate_structured_output(
43
44
  content, system_prompt, response_model
@@ -26,6 +26,7 @@ def read_query_prompt(prompt_file_name: str, base_directory: str = None):
26
26
  read due to an error.
27
27
  """
28
28
  logger = get_logger(level=ERROR)
29
+
29
30
  try:
30
31
  if base_directory is None:
31
32
  base_directory = get_absolute_path("./infrastructure/llm/prompts")
@@ -35,8 +36,8 @@ def read_query_prompt(prompt_file_name: str, base_directory: str = None):
35
36
  with open(file_path, "r", encoding="utf-8") as file:
36
37
  return file.read()
37
38
  except FileNotFoundError:
38
- logger.error(f"Error: Prompt file not found. Attempted to read: %s {file_path}")
39
+ logger.error(f"Error: Prompt file not found. Attempted to read: {file_path}")
39
40
  return None
40
41
  except Exception as e:
41
- logger.error(f"An error occurred: %s {e}")
42
+ logger.error(f"An error occurred: {e}")
42
43
  return None
@@ -0,0 +1,35 @@
1
+ from cognee.infrastructure.llm.exceptions import MissingSystemPromptPathError
2
+ from cognee.infrastructure.llm.prompts import read_query_prompt
3
+
4
+
5
+ def show_prompt(text_input: str, system_prompt: str) -> str:
6
+ """
7
+ Format and display the prompt for a user query.
8
+
9
+ This method formats the prompt using the provided user input and system prompt,
10
+ returning a string representation. Raises MissingSystemPromptPathError if the system prompt is not
11
+ provided.
12
+
13
+ Parameters:
14
+ -----------
15
+
16
+ - text_input (str): The input text provided by the user.
17
+ - system_prompt (str): The system's prompt to guide the model's response.
18
+
19
+ Returns:
20
+ --------
21
+
22
+ - str: A formatted string representing the user input and system prompt.
23
+ """
24
+ if not text_input:
25
+ text_input = "No user input provided."
26
+ if not system_prompt:
27
+ raise MissingSystemPromptPathError()
28
+ system_prompt = read_query_prompt(system_prompt)
29
+
30
+ formatted_prompt = (
31
+ f"""System Prompt:\n{system_prompt}\n\nUser Input:\n{text_input}\n"""
32
+ if system_prompt
33
+ else None
34
+ )
35
+ return formatted_prompt
@@ -0,0 +1 @@
1
+ Respond with: test
@@ -10,7 +10,7 @@
10
10
  # BAML files and re-generate this code using: baml-cli generate
11
11
  # baml-cli is available with the baml package.
12
12
 
13
- __version__ = "0.201.0"
13
+ __version__ = "0.206.0"
14
14
 
15
15
  try:
16
16
  from baml_py.safe_import import EnsureBamlPyImport
@@ -39,7 +39,7 @@ with EnsureBamlPyImport(__version__) as e:
39
39
  from . import config
40
40
  from .config import reset_baml_env_vars
41
41
 
42
- from .sync_client import b
42
+ from .async_client import b
43
43
 
44
44
 
45
45
  # FOR LEGACY COMPATIBILITY, expose "partial_types" as an alias for "stream_types"