Skip to content

Commit 2cec76c

Browse files
committed
wip
1 parent 6721a80 commit 2cec76c

File tree

6 files changed

+26
-110
lines changed

6 files changed

+26
-110
lines changed

app/Console/Commands/IngestDocumentation.php

-10
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ private function ingestFile(SplFileInfo $fileInfo)
7272
$usedMemory = (memory_get_usage() - $memory) / 1024;
7373

7474
$upserts = collect($documents)
75-
->filter(function (Document $document) {
76-
return ! $this->contentIsJustHeadings($document);
77-
})
7875
->map(fn (Document $document) => new DataUpsert(
7976
id: Str::uuid(),
8077
data: $document->getContent(),
@@ -91,11 +88,4 @@ private function ingestFile(SplFileInfo $fileInfo)
9188

9289
$this->info("File $fileName has $documentCount documents, used $usedMemory kb.");
9390
}
94-
95-
private function contentIsJustHeadings(Document $document): bool
96-
{
97-
98-
return collect(explode("\n", $document->getContent()))
99-
->every(fn ($line) => Str::startsWith($line, '#') || Str::startsWith($line, ''));
100-
}
10191
}

app/Console/Commands/SearchVector.php

-98
This file was deleted.

app/Livewire/ChatPage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function processQuestion(string $question)
7474
])
7575
->toArray();
7676

77-
$this->js(sprintf('$wire.generateAnswer("%s")', $question));
77+
// $this->js(sprintf('$wire.generateAnswer("%s")', $question));
7878
}
7979

8080
public function generateAnswer(string $question)

app/Splitters/Document.php

+7
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ public function getLinks(): array
5757
{
5858
return $this->links;
5959
}
60+
61+
public function hasOnlyTitles(): bool
62+
{
63+
$lines = explode("\n", trim($this->content));
64+
65+
return count($lines) === count(array_filter($lines, fn ($line) => preg_match('/^#{1,6}/', $line)));
66+
}
6067
}

app/Splitters/LaravelMarkdownSplitter.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public function split(string $contents): array
5353

5454
$documents[] = $currentDocument;
5555

56-
return array_values(array_filter($documents));
56+
return collect($documents)
57+
->filter()
58+
->filter(fn (Document $document) => ! $document->hasOnlyTitles())
59+
->values()
60+
->toArray();
5761
}
5862

5963
private function getTitleIndex(string $line): int

tests/Unit/DocumentTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use App\Splitters\Document;
4+
5+
test('document can identify if it has only titles', function () {
6+
$document = new Document;
7+
$document->pushContent('# Title');
8+
$document->pushContent('## Title');
9+
expect($document->hasOnlyTitles())->toBeTrue();
10+
11+
$document->pushContent('Content');
12+
expect($document->hasOnlyTitles())->toBeFalse();
13+
});

0 commit comments

Comments
 (0)