-
-
Notifications
You must be signed in to change notification settings - Fork 124
[Store] Add a way to bypass document loading in Indexer #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lyrixx
wants to merge
1
commit into
symfony:main
Choose a base branch
from
lyrixx:store-indexer-with-document
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+32
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,12 +26,18 @@ | |||||
| class Indexer implements IndexerInterface | ||||||
| { | ||||||
| /** | ||||||
| * @var array<string|null> | ||||||
| * @var array<string> | ||||||
| */ | ||||||
| private array $sources = []; | ||||||
|
|
||||||
| /** | ||||||
| * @var array<EmbeddableDocumentInterface> | ||||||
| */ | ||||||
| private array $documents = []; | ||||||
|
|
||||||
| /** | ||||||
| * @param string|array<string>|null $source Source identifier(s) for data loading (file paths, URLs, etc.) | ||||||
| * @param EmbeddableDocumentInterface|array<EmbeddableDocumentInterface>|null $document Document or array of documents to process directly, bypassing the loading step | ||||||
| * @param FilterInterface[] $filters Filters to apply after loading documents to remove unwanted content | ||||||
| * @param TransformerInterface[] $transformers Transformers to mutate documents after filtering (chunking, cleaning, etc.) | ||||||
| */ | ||||||
|
|
@@ -40,32 +46,47 @@ public function __construct( | |||||
| private VectorizerInterface $vectorizer, | ||||||
| private StoreInterface $store, | ||||||
| string|array|null $source = null, | ||||||
| EmbeddableDocumentInterface|array|null $document = [], | ||||||
| private array $filters = [], | ||||||
| private array $transformers = [], | ||||||
| private LoggerInterface $logger = new NullLogger(), | ||||||
| ) { | ||||||
| $this->sources = null === $source ? [] : (array) $source; | ||||||
| if (null === $document) { | ||||||
| $this->documents = []; | ||||||
| } elseif ($document instanceof EmbeddableDocumentInterface) { | ||||||
| $this->documents = [$document]; | ||||||
| } else { | ||||||
| $this->documents = $document; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public function withSource(string|array $source): self | ||||||
| public function withSource(EmbeddableDocumentInterface|string|array $source): self | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should we accept the EmbeddableDocumentInterface here too? |
||||||
| { | ||||||
| return new self($this->loader, $this->vectorizer, $this->store, $source, $this->filters, $this->transformers, $this->logger); | ||||||
| return new self($this->loader, $this->vectorizer, $this->store, $source, [], $this->filters, $this->transformers, $this->logger); | ||||||
| } | ||||||
|
|
||||||
| public function withDocument(EmbeddableDocumentInterface|array $document): self | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||
| { | ||||||
| return new self($this->loader, $this->vectorizer, $this->store, null, $document, $this->filters, $this->transformers, $this->logger); | ||||||
| } | ||||||
|
|
||||||
| public function index(array $options = []): void | ||||||
| { | ||||||
| $this->logger->debug('Starting document processing', ['sources' => $this->sources, 'options' => $options]); | ||||||
|
|
||||||
| $documents = []; | ||||||
| if ([] === $this->sources) { | ||||||
| $documents = $this->loadSource(null); | ||||||
| } else { | ||||||
| foreach ($this->sources as $singleSource) { | ||||||
| $documents = array_merge($documents, $this->loadSource($singleSource)); | ||||||
| $documents = $this->documents; | ||||||
| if (!$documents) { | ||||||
| if (!$this->sources) { | ||||||
| $documents = $this->loadSource(null); | ||||||
| } else { | ||||||
| foreach ($this->sources as $singleSource) { | ||||||
| $documents = array_merge($documents, $this->loadSource($singleSource)); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ([] === $documents) { | ||||||
| if (!$documents) { | ||||||
| $this->logger->debug('No documents to process', ['sources' => $this->sources]); | ||||||
|
|
||||||
| return; | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?