Skip to content
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

Stabilize vector store usage #410

Merged
merged 6 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ["3.0.0"]
version: ['latest']
name: integration-tests-against-rc (dart ${{ matrix.version }})
steps:
- name: Checkout
Expand Down
14 changes: 2 additions & 12 deletions lib/src/results/experimental_features.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ part 'experimental_features.g.dart';
createToJson: false,
)
class ExperimentalFeatures {
@JsonKey(name: 'vectorStore')
final bool vectorStore;

const ExperimentalFeatures({
required this.vectorStore,
});
const ExperimentalFeatures();

factory ExperimentalFeatures.fromJson(Map<String, dynamic> src) {
return _$ExperimentalFeaturesFromJson(src);
Expand All @@ -29,12 +24,7 @@ class ExperimentalFeatures {
createFactory: false,
)
class UpdateExperimentalFeatures {
@JsonKey(name: 'vectorStore')
final bool? vectorStore;

const UpdateExperimentalFeatures({
this.vectorStore,
});
const UpdateExperimentalFeatures();

Map<String, dynamic> toJson() => _$UpdateExperimentalFeaturesToJson(this);
}
Expand Down
18 changes: 3 additions & 15 deletions lib/src/results/experimental_features.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 32 additions & 27 deletions test/search_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:meilisearch/meilisearch.dart';
import 'package:meilisearch/src/results/experimental_features.dart';
import 'package:test/test.dart';

import 'utils/books.dart';
Expand All @@ -8,6 +7,8 @@ import 'utils/client.dart';
import 'utils/wait_for.dart';

void main() {
final openAiKeyValue = openAiKey;

group('Search', () {
setUpClient();
late String uid;
Expand Down Expand Up @@ -542,55 +543,62 @@ void main() {
});

// Commented because of https://github.com/meilisearch/meilisearch-dart/issues/369
group('Experimental', () {
group('Vector search', () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is now failing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we still use the old meilisearch version

setUpClient();
late String uid;
late MeiliSearchIndex index;
late ExperimentalFeatures features;
setUp(() async {
features = await client.http.updateExperimentalFeatures(
UpdateExperimentalFeatures(
vectorStore: true,
late IndexSettings settings;

setUpAll(() {
settings = IndexSettings(embedders: {
'default': OpenAiEmbedder(
model: 'text-embedding-3-small',
apiKey: openAiKeyValue,
documentTemplate: "a book titled '{{ doc.title }}'",
),
);
expect(features.vectorStore, true);
});
});

setUp(() async {
uid = randomUid();
index = await createIndexWithData(uid: uid, data: vectorBooks);
// Configure embedder before running vector search
await index.updateSettings(settings).waitFor(client: client);
});

test('vector search', () async {
final vector = [0, 1, 2];
// Create a vector with 1536 dimensions (filled with zeros for test purposes)
final vector = List.filled(1536, 0.0);
final res = await index
.search(
null,
SearchQuery(
vector: vector,
hybrid: HybridSearch(
embedder: 'default',
semanticRatio: 1.0,
),
),
)
.asSearchResult()
.mapToContainer();

expect(res.vector, vector);
expect(
res.hits,
everyElement(
isA<MeiliDocumentContainer<Map<String, dynamic>>>()
.having(
(p0) => p0.vectors,
'vectors',
isNotNull,
)
.having(
(p0) => p0.semanticScore,
'semanticScore',
isNotNull,
),
isA<MeiliDocumentContainer<Map<String, dynamic>>>().having(
(p0) => p0.parsed,
'parsed',
isNotNull,
),
),
);
});
}, skip: "Requires Experimental API");
final openAiKeyValue = openAiKey;
},
skip: openAiKeyValue == null || openAiKeyValue.isEmpty
? "Requires OPEN_AI_API_KEY environment variable"
: null);

group('Embedders', () {
group(
'Unit test',
Expand Down Expand Up @@ -665,9 +673,6 @@ void main() {
});

setUp(() async {
final features = await client.http.updateExperimentalFeatures(
UpdateExperimentalFeatures(vectorStore: true));
expect(features.vectorStore, true);
uid = randomUid();
index = await createBooksIndex(uid: uid);
});
Expand Down
30 changes: 25 additions & 5 deletions test/utils/books_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,43 @@ final vectorBooks = [
{
"id": 0,
"title": "Across The Universe",
"_vectors": [0, 0.8, -0.2],
"_vectors": {
"default": {
"embeddings": [0, 0.8, -0.2],
"regenerate": false,
}
}
},
{
"id": 1,
"title": "All Things Must Pass",
"_vectors": [1, -0.2, 0],
"_vectors": {
"default": {
"embeddings": [1, -0.2, 0],
"regenerate": false,
}
}
},
{
"id": 2,
"title": "And Your Bird Can Sing",
"_vectors": [-0.2, 4, 6],
"_vectors": {
"default": {
"embeddings": [-0.2, 4, 6],
"regenerate": false,
}
}
},
{
"id": 3,
"title": "The Matrix",
"_vectors": [5, -0.5, 0.3],
},
"_vectors": {
"default": {
"embeddings": [5, -0.5, 0.3],
"regenerate": false,
}
},
}
];

enum CSVHeaderTypes {
Expand Down