Skip to content

Commit

Permalink
updated deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasilije1990 committed Jul 17, 2024
1 parent a6dd542 commit d0ad763
Show file tree
Hide file tree
Showing 8 changed files with 817 additions and 786 deletions.
21 changes: 21 additions & 0 deletions cognee/api/v1/cognify/cognify_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ async def run_cognify_pipeline(dataset_name: str, files: list[dict]):
]),
Task(remove_obsolete_chunks), # Remove the obsolete document chunks.
]
gg =[ PdfDocument(title = file["name"], file_path = file["file_path"]) for file in files]



pipeline = run_tasks(tasks, [PdfDocument(title = file["name"], file_path = file["file_path"]) for file in files])

Expand All @@ -85,3 +88,21 @@ async def run_cognify_pipeline(dataset_name: str, files: list[dict]):
awaitables.append(run_cognify_pipeline(dataset, db_engine.get_files_metadata(dataset)))

return await asyncio.gather(*awaitables)


#
# if __name__ == "__main__":
# from cognee.api.v1.add import add
# from cognee.api.v1.datasets.datasets import datasets
#
#
# async def aa():
# await add("TEXT ABOUT NLP AND MONKEYS")
#
# print(datasets.discover_datasets())
#
# return



# asyncio.run(cognify())
18 changes: 10 additions & 8 deletions cognee/infrastructure/llm/openai/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from cognee.infrastructure.llm.llm_interface import LLMInterface
from cognee.infrastructure.llm.prompts import read_query_prompt
from cognee.shared.data_models import MonitoringTool
import logging
logging.basicConfig(level=logging.DEBUG)

class OpenAIAdapter(LLMInterface):
name = "OpenAI"
Expand All @@ -19,14 +21,14 @@ class OpenAIAdapter(LLMInterface):
def __init__(self, api_key: str, model: str, streaming: bool = False):
base_config = get_base_config()

if base_config.monitoring_tool == MonitoringTool.LANGFUSE:
from langfuse.openai import AsyncOpenAI, OpenAI
elif base_config.monitoring_tool == MonitoringTool.LANGSMITH:
from langsmith import wrappers
from openai import AsyncOpenAI
AsyncOpenAI = wrappers.wrap_openai(AsyncOpenAI())
else:
from openai import AsyncOpenAI, OpenAI
# if base_config.monitoring_tool == MonitoringTool.LANGFUSE:
# from langfuse.openai import AsyncOpenAI, OpenAI
# elif base_config.monitoring_tool == MonitoringTool.LANGSMITH:
# from langsmith import wrappers
# from openai import AsyncOpenAI
# AsyncOpenAI = wrappers.wrap_openai(AsyncOpenAI())
# else:
from openai import AsyncOpenAI, OpenAI

self.aclient = instructor.from_openai(AsyncOpenAI(api_key = api_key))
self.client = instructor.from_openai(OpenAI(api_key = api_key))
Expand Down
4 changes: 3 additions & 1 deletion cognee/modules/data/processing/document_types/PdfDocument.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# import pdfplumber
import logging
from uuid import uuid5, NAMESPACE_OID
from typing import Optional
from pypdf import PdfReader as pypdf_PdfReader
Expand Down Expand Up @@ -89,11 +90,12 @@ def __init__(self, title: str, file_path: str):
self.id = uuid5(NAMESPACE_OID, title)
self.title = title
self.file_path = file_path

logging.debug("file_path: %s", self.file_path)
reader = PdfReader(self.id, self.file_path)
self.num_pages = reader.get_number_of_pages()

def get_reader(self) -> PdfReader:
logging.debug("file_path: %s", self.file_path)
reader = PdfReader(self.id, self.file_path)
return reader

Expand Down
55 changes: 28 additions & 27 deletions cognee/tests/test_library.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

import logging
import os
import dotenv

dotenv.load_dotenv()

logging.basicConfig(level=logging.DEBUG)
async def main():
Expand All @@ -22,49 +25,47 @@ async def main():
logging.debug("CURRENCT CWD: %s", os.getcwd())


dataset_name = "cs_explanations"

explanation_file_path = os.path.join(pathlib.Path(__file__).parent, "test_data/Natural_language_processing.txt")
await cognee.add([explanation_file_path], dataset_name)
# explanation_file_path = os.path.join(pathlib.Path(__file__).parent, "test_data/Natural_language_processing.txt")
await cognee.add("file:///Users/vasa/Projects/cognee/.data/dss/artificial.pdf", "dss")

# dataset_name = "short_stories"
# # data_directory_path is defined above
# await cognee.add("data://" + "/Users/runner/work/cognee/cognee/./cognee/tests", dataset_name)

text_1 = """A quantum computer is a computer that takes advantage of quantum mechanical phenomena.
At small scales, physical matter exhibits properties of both particles and waves, and quantum computing leverages this behavior, specifically quantum superposition and entanglement, using specialized hardware that supports the preparation and manipulation of quantum states.
Classical physics cannot explain the operation of these quantum devices, and a scalable quantum computer could perform some calculations exponentially faster (with respect to input size scaling) than any modern "classical" computer. In particular, a large-scale quantum computer could break widely used encryption schemes and aid physicists in performing physical simulations; however, the current state of the technology is largely experimental and impractical, with several obstacles to useful applications. Moreover, scalable quantum computers do not hold promise for many practical tasks, and for many important tasks quantum speedups are proven impossible.
The basic unit of information in quantum computing is the qubit, similar to the bit in traditional digital electronics. Unlike a classical bit, a qubit can exist in a superposition of its two "basis" states. When measuring a qubit, the result is a probabilistic output of a classical bit, therefore making quantum computers nondeterministic in general. If a quantum computer manipulates the qubit in a particular way, wave interference effects can amplify the desired measurement results. The design of quantum algorithms involves creating procedures that allow a quantum computer to perform calculations efficiently and quickly.
Physically engineering high-quality qubits has proven challenging. If a physical qubit is not sufficiently isolated from its environment, it suffers from quantum decoherence, introducing noise into calculations. Paradoxically, perfectly isolating qubits is also undesirable because quantum computations typically need to initialize qubits, perform controlled qubit interactions, and measure the resulting quantum states. Each of those operations introduces errors and suffers from noise, and such inaccuracies accumulate.
In principle, a non-quantum (classical) computer can solve the same computational problems as a quantum computer, given enough time. Quantum advantage comes in the form of time complexity rather than computability, and quantum complexity theory shows that some quantum algorithms for carefully selected tasks require exponentially fewer computational steps than the best known non-quantum algorithms. Such tasks can in theory be solved on a large-scale quantum computer whereas classical computers would not finish computations in any reasonable amount of time. However, quantum speedup is not universal or even typical across computational tasks, since basic tasks such as sorting are proven to not allow any asymptotic quantum speedup. Claims of quantum supremacy have drawn significant attention to the discipline, but are demonstrated on contrived tasks, while near-term practical use cases remain limited.
"""

text_2 = """A large language model (LLM) is a language model notable for its ability to achieve general-purpose language generation and other natural language processing tasks such as classification. LLMs acquire these abilities by learning statistical relationships from text documents during a computationally intensive self-supervised and semi-supervised training process. LLMs can be used for text generation, a form of generative AI, by taking an input text and repeatedly predicting the next token or word.
LLMs are artificial neural networks. The largest and most capable, as of March 2024, are built with a decoder-only transformer-based architecture while some recent implementations are based on other architectures, such as recurrent neural network variants and Mamba (a state space model).
Up to 2020, fine tuning was the only way a model could be adapted to be able to accomplish specific tasks. Larger sized models, such as GPT-3, however, can be prompt-engineered to achieve similar results.[6] They are thought to acquire knowledge about syntax, semantics and "ontology" inherent in human language corpora, but also inaccuracies and biases present in the corpora.
Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5 and GPT-4, used in ChatGPT and Microsoft Copilot), Google's PaLM and Gemini (the latter of which is currently used in the chatbot of the same name), xAI's Grok, Meta's LLaMA family of open-source models, Anthropic's Claude models, Mistral AI's open source models, and Databricks' open source DBRX.
"""
# text_1 = """A quantum computer is a computer that takes advantage of quantum mechanical phenomena.
# At small scales, physical matter exhibits properties of both particles and waves, and quantum computing leverages this behavior, specifically quantum superposition and entanglement, using specialized hardware that supports the preparation and manipulation of quantum states.
# Classical physics cannot explain the operation of these quantum devices, and a scalable quantum computer could perform some calculations exponentially faster (with respect to input size scaling) than any modern "classical" computer. In particular, a large-scale quantum computer could break widely used encryption schemes and aid physicists in performing physical simulations; however, the current state of the technology is largely experimental and impractical, with several obstacles to useful applications. Moreover, scalable quantum computers do not hold promise for many practical tasks, and for many important tasks quantum speedups are proven impossible.
# The basic unit of information in quantum computing is the qubit, similar to the bit in traditional digital electronics. Unlike a classical bit, a qubit can exist in a superposition of its two "basis" states. When measuring a qubit, the result is a probabilistic output of a classical bit, therefore making quantum computers nondeterministic in general. If a quantum computer manipulates the qubit in a particular way, wave interference effects can amplify the desired measurement results. The design of quantum algorithms involves creating procedures that allow a quantum computer to perform calculations efficiently and quickly.
# Physically engineering high-quality qubits has proven challenging. If a physical qubit is not sufficiently isolated from its environment, it suffers from quantum decoherence, introducing noise into calculations. Paradoxically, perfectly isolating qubits is also undesirable because quantum computations typically need to initialize qubits, perform controlled qubit interactions, and measure the resulting quantum states. Each of those operations introduces errors and suffers from noise, and such inaccuracies accumulate.
# In principle, a non-quantum (classical) computer can solve the same computational problems as a quantum computer, given enough time. Quantum advantage comes in the form of time complexity rather than computability, and quantum complexity theory shows that some quantum algorithms for carefully selected tasks require exponentially fewer computational steps than the best known non-quantum algorithms. Such tasks can in theory be solved on a large-scale quantum computer whereas classical computers would not finish computations in any reasonable amount of time. However, quantum speedup is not universal or even typical across computational tasks, since basic tasks such as sorting are proven to not allow any asymptotic quantum speedup. Claims of quantum supremacy have drawn significant attention to the discipline, but are demonstrated on contrived tasks, while near-term practical use cases remain limited.
# """
#
# text_2 = """A large language model (LLM) is a language model notable for its ability to achieve general-purpose language generation and other natural language processing tasks such as classification. LLMs acquire these abilities by learning statistical relationships from text documents during a computationally intensive self-supervised and semi-supervised training process. LLMs can be used for text generation, a form of generative AI, by taking an input text and repeatedly predicting the next token or word.
# LLMs are artificial neural networks. The largest and most capable, as of March 2024, are built with a decoder-only transformer-based architecture while some recent implementations are based on other architectures, such as recurrent neural network variants and Mamba (a state space model).
# Up to 2020, fine tuning was the only way a model could be adapted to be able to accomplish specific tasks. Larger sized models, such as GPT-3, however, can be prompt-engineered to achieve similar results.[6] They are thought to acquire knowledge about syntax, semantics and "ontology" inherent in human language corpora, but also inaccuracies and biases present in the corpora.
# Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5 and GPT-4, used in ChatGPT and Microsoft Copilot), Google's PaLM and Gemini (the latter of which is currently used in the chatbot of the same name), xAI's Grok, Meta's LLaMA family of open-source models, Anthropic's Claude models, Mistral AI's open source models, and Databricks' open source DBRX.
# """


await cognee.cognify([ "cs_explanations"])
await cognee.cognify()

search_results = await cognee.search("SIMILARITY", { "query": "computer science" })
assert len(search_results) != 0, "The search results list is empty."
print("The search results list is not empty.")

search_results = await cognee.search("CATEGORIES", { "query": "DefaultGraphModel__default_user" })
assert len(search_results) != 0, "The search results list is empty."
print("The search results list is not empty.")
# search_results = await cognee.search("CATEGORIES", { "query": "DefaultGraphModel__default_user" })
# assert len(search_results) != 0, "The search results list is empty."
# print("The search results list is not empty.")


search_results = await cognee.search("NEIGHBOR", { "query": "DefaultGraphModel__default_user" })
assert len(search_results) != 0, "The search results list is empty."
print("The search results list is not empty.")
# search_results = await cognee.search("NEIGHBOR", { "query": "DefaultGraphModel__default_user" })
# assert len(search_results) != 0, "The search results list is empty."
# print("The search results list is not empty.")


search_results = await cognee.search("SUMMARY", { "query": "Work and computers" })
assert len(search_results) != 0, "The search results list is empty."
print("The search results list is not empty.")
# search_results = await cognee.search("SUMMARY", { "query": "Work and computers" })
# assert len(search_results) != 0, "The search results list is empty."
# print("The search results list is not empty.")

search_results = await cognee.search("ADJACENT", { "query": "DefaultGraphModel__default_user" })
assert len(search_results) != 0, "The search results list is empty."
Expand Down
41 changes: 0 additions & 41 deletions docker-compose-vanilla.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
deploy:
resources:
limits:
cpus: 4.0
cpus: '4.0'
memory: 8GB

frontend:
Expand Down
Loading

0 comments on commit d0ad763

Please sign in to comment.