Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c572e27
Draft ollama test
Vasilije1990 Feb 19, 2025
2de364b
Ollama test end to end
Vasilije1990 Feb 20, 2025
8ebd9a7
Ollama test end to end
Vasilije1990 Feb 20, 2025
9d0d96e
Fix ollama
Vasilije1990 Feb 21, 2025
b4088be
Fix ollama
Vasilije1990 Feb 21, 2025
b670697
Fix ollama
Vasilije1990 Feb 21, 2025
bfe039d
Fix ollama
Vasilije1990 Feb 21, 2025
6bc4f6a
Fix ollama
Vasilije1990 Feb 21, 2025
96adcfb
Fix ollama
Vasilije1990 Feb 21, 2025
c06c28d
Fix ollama
Vasilije1990 Feb 21, 2025
edd681f
Fix ollama
Vasilije1990 Feb 21, 2025
02b0109
Fix ollama
Vasilije1990 Feb 21, 2025
a91e83e
Fix ollama
Vasilije1990 Feb 21, 2025
326c418
Fix ollama
Vasilije1990 Feb 21, 2025
92602aa
Fix ollama
Vasilije1990 Feb 22, 2025
f2d0909
Fix ollama
Vasilije1990 Feb 22, 2025
97465f1
Fix ollama
Vasilije1990 Feb 22, 2025
73662b8
Fix ollama
Vasilije1990 Feb 22, 2025
90d96aa
Fix ollama
Vasilije1990 Feb 22, 2025
3a88b94
Fix ollama
Vasilije1990 Feb 22, 2025
11442df
Fix ollama
Vasilije1990 Feb 22, 2025
1dfb0dd
Fix ollama
Vasilije1990 Feb 22, 2025
4c4723b
Fix ollama
Vasilije1990 Feb 22, 2025
846c45e
Fix ollama
Vasilije1990 Feb 22, 2025
2c0bfc8
Fix ollama
Vasilije1990 Feb 22, 2025
62d2d76
Add helm chart for deployment
Vasilije1990 Feb 24, 2025
57630ee
Merge branch 'dev' into add_helm_to_core
Vasilije1990 Feb 24, 2025
0516d6e
Update cognee/infrastructure/llm/ollama/adapter.py
borisarzentar Feb 26, 2025
bacfb01
Merge branch 'dev' into add_helm_to_core
Vasilije1990 Mar 4, 2025
6e17fdf
check
Vasilije1990 Mar 4, 2025
a9f8ab4
Merge remote-tracking branch 'origin/add_helm_to_core' into add_helm_…
Vasilije1990 Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test_ollama.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:

run_simple_example_test:


# needs 16 Gb RAM for phi4
runs-on: buildjet-4vcpu-ubuntu-2204
# services:
Expand All @@ -17,6 +18,7 @@ jobs:
# ports:
# - 11434:11434


steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -36,6 +38,7 @@ jobs:
- name: Install dependencies
run: |
poetry install --no-interaction --all-extras

poetry add torch

# - name: Install ollama
Expand All @@ -55,10 +58,13 @@ jobs:
- name: Check Ollama logs
run: docker logs ollama


- name: Wait for Ollama to be ready
run: |
for i in {1..30}; do

if curl -s http://localhost:11434/v1/models > /dev/null; then

echo "Ollama is ready"
exit 0
fi
Expand Down Expand Up @@ -92,6 +98,7 @@ jobs:
"input": "This is a test sentence to generate an embedding."
}'


- name: Dump Docker logs
run: |
docker ps
Expand All @@ -104,6 +111,7 @@ jobs:
GRAPHISTRY_USERNAME: ${{ secrets.GRAPHISTRY_USERNAME }}
GRAPHISTRY_PASSWORD: ${{ secrets.GRAPHISTRY_PASSWORD }}
PYTHONFAULTHANDLER: 1

LLM_PROVIDER: "ollama"
LLM_API_KEY: "ollama"
LLM_ENDPOINT: "http://localhost:11434/v1/"
Expand All @@ -114,3 +122,4 @@ jobs:
EMBEDDING_DIMENSIONS: "4096"
HUGGINGFACE_TOKENIZER: "Salesforce/SFR-Embedding-Mistral"
run: poetry run python ./examples/python/simple_example.py

15 changes: 12 additions & 3 deletions cognee/infrastructure/llm/ollama/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
from cognee.infrastructure.llm.config import get_llm_config
from openai import OpenAI
import base64
import os

import os

class OllamaAPIAdapter(LLMInterface):
"""Adapter for a Generic API LLM provider using instructor with an OpenAI backend."""
"""Adapter for a Ollama API LLM provider using instructor with an OpenAI backend."""

api_version: str

MAX_RETRIES = 5

def __init__(self, endpoint: str, api_key: str, model: str, name: str, max_tokens: int):
def __init__(self, endpoint: str, api_key: str, model: str, name: str, max_tokens: int, api_version: str = None) -> None:
self.name = name
self.model = model
self.api_key = api_key
self.endpoint = endpoint
self.max_tokens = max_tokens
self.api_version= api_version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix formatting issue.

Add a space after the equals sign.

-        self.api_version= api_version
+        self.api_version = api_version
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.api_version= api_version
self.api_version = api_version


self.aclient = instructor.from_openai(
OpenAI(base_url=self.endpoint, api_key=self.api_key), mode=instructor.Mode.JSON
Expand Down Expand Up @@ -45,6 +50,7 @@ async def acreate_structured_output(

return response


def create_transcript(self, input_file: str) -> str:
"""Generate an audio transcript from a user query."""

Expand Down Expand Up @@ -74,11 +80,13 @@ def transcribe_image(self, input_file: str) -> str:
encoded_image = base64.b64encode(image_file.read()).decode("utf-8")

response = self.aclient.chat.completions.create(

model=self.model,
messages=[
{
"role": "user",
"content": [

{"type": "text", "text": "What’s in this image?"},
{
"type": "image_url",
Expand All @@ -95,3 +103,4 @@ def transcribe_image(self, input_file: str) -> str:
raise ValueError("Image transcription failed. No response received.")

return response.choices[0].message.content

162 changes: 162 additions & 0 deletions infra/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
24 changes: 24 additions & 0 deletions infra/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: cognee-chart
description: A helm chart of the cognee backend deployment on Kubernetes environment

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
45 changes: 45 additions & 0 deletions infra/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM python:3.11-slim

# Set build argument
ARG DEBUG

# Set environment variable based on the build argument
ENV DEBUG=${DEBUG}
ENV PIP_NO_CACHE_DIR=true
ENV PATH="${PATH}:/root/.poetry/bin"

RUN apt-get update && apt-get install

RUN apt-get install -y \
gcc \
libpq-dev
Comment on lines +11 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Critical: Merge Update and Install Commands
The Dockerfile contains an incomplete package installation command on line 11 (RUN apt-get update && apt-get install) followed by a full installation on line 13. This may lead to build failures. It is advisable to combine these steps to ensure a robust build process. For example:

- RUN apt-get update && apt-get install
- 
- RUN apt-get install -y \
-   gcc \
-   libpq-dev
+ RUN apt-get update && apt-get install -y gcc libpq-dev
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RUN apt-get update && apt-get install
RUN apt-get install -y \
gcc \
libpq-dev
RUN apt-get update && apt-get install -y gcc libpq-dev



WORKDIR /app
COPY pyproject.toml poetry.lock /app/


RUN pip install poetry

# Don't create virtualenv since docker is already isolated
RUN poetry config virtualenvs.create false

# Install the dependencies
RUN poetry install --all-extras --no-root --no-dev


# Set the PYTHONPATH environment variable to include the /app directory
ENV PYTHONPATH=/app

COPY cognee/ /app/cognee

# Copy Alembic configuration
COPY alembic.ini /app/alembic.ini
COPY alembic/ /app/alembic

COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

RUN sed -i 's/\r$//' /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]
25 changes: 25 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# cognee-infra-helm
General infrastructure setup for Cognee on Kubernetes using a Helm chart.

## Prerequisites
Before deploying the Helm chart, ensure the following prerequisites are met: 

**Kubernetes Cluster**: A running Kubernetes cluster (e.g., Minikube, GKE, EKS).

**Helm**: Installed and configured for your Kubernetes cluster. You can install Helm by following the [official guide](https://helm.sh/docs/intro/install/). 

**kubectl**: Installed and configured to interact with your cluster. Follow the instructions [here](https://kubernetes.io/docs/tasks/tools/install-kubectl/).

Clone the Repository Clone this repository to your local machine and navigate to the directory.

## Deploy Helm Chart:

```bash
helm install cognee ./cognee-chart
```

**Uninstall Helm Release**:
```bash
helm uninstall cognee
```
Loading
Loading