diff --git a/app/Services/QdrantService.php b/app/Services/QdrantService.php index e88625d..f680e45 100644 --- a/app/Services/QdrantService.php +++ b/app/Services/QdrantService.php @@ -166,6 +166,14 @@ public function upsert(array $entry, string $project = 'default', bool $checkDup 'superseded_reason' => $entry['superseded_reason'] ?? null, ]; + // Enhancement fields are optional: only present once the Ollama worker + // has processed the entry, and must survive later re-upserts. + foreach (['enhanced', 'enhanced_at', 'summary', 'concepts'] as $enhancementField) { + if (array_key_exists($enhancementField, $entry)) { + $payload[$enhancementField] = $entry[$enhancementField]; + } + } + $point = ['id' => $entry['id'], 'payload' => $payload]; if ($this->hybridEnabled && $this->sparseEmbeddingService instanceof SparseEmbeddingServiceInterface) { @@ -661,6 +669,11 @@ private function mapScoredPointToEntry(ScoredPoint $point): array 'superseded_by' => $p['superseded_by'] ?? null, 'superseded_date' => $p['superseded_date'] ?? null, 'superseded_reason' => $p['superseded_reason'] ?? null, + 'commit' => $p['commit'] ?? null, + 'enhanced' => $p['enhanced'] ?? null, + 'enhanced_at' => $p['enhanced_at'] ?? null, + 'summary' => $p['summary'] ?? null, + 'concepts' => $p['concepts'] ?? null, ]; } diff --git a/tests/Unit/Services/QdrantServiceTest.php b/tests/Unit/Services/QdrantServiceTest.php index 1672128..e6f7419 100644 --- a/tests/Unit/Services/QdrantServiceTest.php +++ b/tests/Unit/Services/QdrantServiceTest.php @@ -1574,3 +1574,45 @@ function mockCollectionExists(Mockery\MockInterface $qdrant, int $times = 1): vo expect($this->service->upsert($entry, 'default', true))->toBeTrue(); }); }); + +describe('enhancement field round-trip', function (): void { + it('persists enhancement fields through updateFields', function (): void { + mockCollectionExists($this->mockQdrant, 2); + + $this->mockQdrant->shouldReceive('getPoints') + ->once() + ->andReturn([ + makeScoredPoint('enh-1', 0.0, [ + 'title' => 'Entry', + 'content' => 'Body', + 'commit' => 'abc123', + ]), + ]); + + $this->mockEmbedding->shouldReceive('embed') + ->once() + ->andReturn([0.1, 0.2, 0.3]); + + $this->mockQdrant->shouldReceive('upsert') + ->once() + ->with(Mockery::any(), Mockery::on(function (array $points): bool { + $payload = $points[0]['payload']; + + return ($payload['enhanced'] ?? null) === true + && ($payload['enhanced_at'] ?? null) === '2026-07-03T00:00:00+00:00' + && ($payload['summary'] ?? null) === 'A summary' + && ($payload['concepts'] ?? null) === ['mesh', 'router'] + && ($payload['commit'] ?? null) === 'abc123'; + })) + ->andReturn(makeUpsertResult()); + + $result = $this->service->updateFields('enh-1', [ + 'enhanced' => true, + 'enhanced_at' => '2026-07-03T00:00:00+00:00', + 'summary' => 'A summary', + 'concepts' => ['mesh', 'router'], + ]); + + expect($result)->toBeTrue(); + }); +});