Skip to content

Commit

Permalink
Refactor model name methods for consistency and add vector size method.
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhhui committed Dec 15, 2024
1 parent 3697cd0 commit 9ba220c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Knowledge/Knowledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function similaritySearch(string $query, string $collection, int $limit =

public function upsert(string $collection, Document $document): ?UpdateResult
{
$this->qdrant->getOrCreateCollection($collection, $this->vectorSizeMap[$this->embeddingModel->getSpecifiedModelName()]);
$this->qdrant->getOrCreateCollection($collection, $this->vectorSizeMap[$this->embeddingModel->getModelName()]);
return $this->qdrant->upsertPointsByDocument($collection, $document, $this->embeddingModel);
}

Expand Down
8 changes: 7 additions & 1 deletion src/Model/AzureOpenAIModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public function getAzureOpenAIClient(): AzureOpenAIClient
return $openAI->getClient($config, $this->model);
}

public function getSpecifiedModelName(): string
public function getModelName(): string
{
return $this->model;
}

public function getVectorSize(): int
{
return 1536;
}

}
8 changes: 7 additions & 1 deletion src/Model/ChatglmModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public function embedding(string $input): Embedding
return new Embedding($embeddings);
}

public function getSpecifiedModelName(): string
public function getModelName(): string
{
return $this->model;
}

public function getVectorSize(): int
{
return 1536;
}

}
4 changes: 3 additions & 1 deletion src/Model/EmbeddingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ interface EmbeddingInterface
{
public function embedding(string $input): Embedding;

public function getSpecifiedModelName(): string;
public function getModelName(): string;

public function getVectorSize(): int;
}
7 changes: 6 additions & 1 deletion src/Model/OllamaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ public function embedding(string $input): Embedding
return new Embedding($response->getEmbeddings());
}

public function getVectorSize(): int
{
return 1536;
}

public function getOllamaClient(): Client
{
$ollama = new Ollama();
$config = new OllamaConfig($this->config['base_url'] ?? 'http://0.0.0.0:11434');
return $ollama->getClient($config);
}

public function getSpecifiedModelName(): string
public function getModelName(): string
{
return $this->model;
}
Expand Down
2 changes: 1 addition & 1 deletion src/VectorStore/Qdrant/Qdrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function upsertPointsByDocument(
$embedding = $embeddingModel->embedding($block)->getEmbeddings();
$payload = array_merge([
'__content__' => $block,
'__model__' => $embeddingModel->getSpecifiedModelName()
'__model__' => $embeddingModel->getModelName()
], $document->getMetadata());
return new PointStruct($pointId, new VectorStruct($embedding), $payload);
}
Expand Down

0 comments on commit 9ba220c

Please sign in to comment.