Update code for Ollama API compatibility with newer version (#1578)

<!-- .github/pull_request_template.md -->
## Description

While testing Cognee with the latest version of Ollama, I discovered two
breaking changes that prevented proper functionality:

1. **Ollama API key change**: The embeddings API response key has been
updated from `embedding` to `embeddings` in newer Ollama versions
2. **Vector dimension handling**: The `create_lance_data_point` method
was receiving vectors as nested lists `[[...]]` instead of a flat list.
Added validation to flatten the vector when this occurs.

These changes ensure compatibility with the latest Ollama release while
maintaining the expected behavior.


## Type of Change
<!-- Please check the relevant option -->
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Other (please specify):

## Screenshots/Videos (if applicable)
<!-- Add screenshots or videos to help explain your changes -->

## Pre-submission Checklist
<!-- Please check all boxes that apply before submitting your PR -->
- [x] **I have tested my changes thoroughly before submitting this PR**
- [x] **This PR contains minimal changes necessary to address the
issue/feature**
- [x] My code follows the project's coding standards and style
guidelines
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added necessary documentation (if applicable)
- [ ] All new and existing tests pass
- [x] I have searched existing PRs to ensure this change hasn't been
submitted already
- [ ] I have linked any relevant issues in the description
- [x] My commits have clear and descriptive messages

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin.
This commit is contained in:
Vasilije 2025-10-22 18:02:56 +02:00 committed by GitHub
commit dfba2f80db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 3 deletions

View file

@ -124,7 +124,7 @@ class OllamaEmbeddingEngine(EmbeddingEngine):
self.endpoint, json=payload, headers=headers, timeout=60.0
) as response:
data = await response.json()
return data["embedding"]
return data["embeddings"][0]
def get_vector_size(self) -> int:
"""

View file

@ -181,7 +181,7 @@ class LanceDBAdapter(VectorDBInterface):
def create_lance_data_point(data_point: DataPoint, vector: list[float]) -> LanceDataPoint:
properties = get_own_properties(data_point)
properties["id"] = str(properties["id"])
return LanceDataPoint[str, self.get_data_point_schema(type(data_point))](
id=str(data_point.id),
vector=vector,
@ -324,7 +324,6 @@ class LanceDBAdapter(VectorDBInterface):
def get_data_point_schema(self, model_type: BaseModel):
related_models_fields = []
for field_name, field_config in model_type.model_fields.items():
if hasattr(field_config, "model_fields"):
related_models_fields.append(field_name)