Skip to content

Commit f37ef35

Browse files
committed
refactor: upgrade to latest AI Search SDK
1 parent b184e99 commit f37ef35

File tree

5 files changed

+93
-97
lines changed

5 files changed

+93
-97
lines changed

package-lock.json

Lines changed: 26 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/indexer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@azure/core-http": "^3.0.5",
2727
"@azure/identity": "^4.0.1",
2828
"@azure/monitor-opentelemetry": "^1.0.0-beta.2",
29-
"@azure/search-documents": "12.0.0-beta.3",
29+
"@azure/search-documents": "^12.1.0",
3030
"@azure/storage-blob": "^12.15.0",
3131
"@dqbd/tiktoken": "^1.0.7",
3232
"@fastify/autoload": "^6.1.0",

packages/indexer/src/lib/indexer.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,41 @@ export class Indexer {
5252
} else {
5353
const index: SearchIndex = {
5454
name: indexName,
55+
vectorSearch: {
56+
algorithms: [
57+
{
58+
name: 'vector-search-algorithm',
59+
kind: 'hnsw',
60+
parameters: {
61+
m: 4,
62+
efSearch: 500,
63+
metric: 'cosine',
64+
efConstruction: 400,
65+
},
66+
},
67+
],
68+
profiles: [
69+
{
70+
name: 'vector-search-profile',
71+
algorithmConfigurationName: 'vector-search-algorithm',
72+
},
73+
],
74+
},
75+
semanticSearch: {
76+
defaultConfigurationName: 'semantic-search-config',
77+
configurations: [
78+
{
79+
name: 'semantic-search-config',
80+
prioritizedFields: {
81+
contentFields: [
82+
{
83+
name: 'content',
84+
},
85+
],
86+
},
87+
},
88+
],
89+
},
5590
fields: [
5691
{
5792
name: 'id',
@@ -73,7 +108,7 @@ export class Indexer {
73108
sortable: false,
74109
facetable: false,
75110
vectorSearchDimensions: 1536,
76-
vectorSearchConfiguration: 'default',
111+
vectorSearchProfileName: 'vector-search-profile',
77112
},
78113
{
79114
name: 'category',
@@ -94,27 +129,6 @@ export class Indexer {
94129
facetable: true,
95130
},
96131
],
97-
semanticSettings: {
98-
configurations: [
99-
{
100-
name: 'default',
101-
prioritizedFields: {
102-
prioritizedContentFields: [{ name: 'content' }],
103-
},
104-
},
105-
],
106-
},
107-
vectorSearch: {
108-
algorithmConfigurations: [
109-
{
110-
name: 'default',
111-
kind: 'hnsw',
112-
parameters: {
113-
metric: 'cosine',
114-
},
115-
},
116-
],
117-
},
118132
};
119133
this.logger.debug(`Creating "${indexName}" search index...`);
120134
await searchIndexClient.createIndex(index);

packages/search/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@azure/core-http": "^3.0.5",
2424
"@azure/identity": "^4.0.1",
2525
"@azure/monitor-opentelemetry": "^1.0.0-beta.2",
26-
"@azure/search-documents": "12.0.0-beta.3",
26+
"@azure/search-documents": "^12.1.0",
2727
"@azure/storage-blob": "^12.15.0",
2828
"@dqbd/tiktoken": "^1.0.7",
2929
"@fastify/autoload": "^6.1.0",

packages/search/src/lib/approaches/approach-base.ts

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,40 @@ export class ApproachBase {
4343
? this.search.search(queryText, {
4444
filter,
4545
queryType: 'semantic',
46-
queryLanguage: 'en-us',
47-
speller: 'lexicon',
48-
semanticConfiguration: 'default',
46+
semanticSearchOptions: {
47+
configurationName: 'semantic-search-config',
48+
captions: useSemanticCaption
49+
? {
50+
captionType: 'extractive',
51+
highlight: false,
52+
}
53+
: undefined,
54+
},
4955
top,
50-
captions: useSemanticCaption ? 'extractive|highlight-false' : undefined,
51-
vectors: [
52-
{
53-
value: queryVector,
54-
kNearestNeighborsCount: queryVector ? 50 : undefined,
55-
fields: queryVector ? ['embedding'] : undefined,
56-
},
57-
],
56+
vectorSearchOptions: {
57+
queries: [
58+
{
59+
kind: 'vector',
60+
vector: queryVector!,
61+
kNearestNeighborsCount: queryVector ? 50 : undefined,
62+
fields: queryVector ? ['embedding'] : undefined,
63+
},
64+
],
65+
},
5866
})
5967
: this.search.search(queryText, {
6068
filter,
6169
top,
62-
vectors: [
63-
{
64-
value: queryVector,
65-
kNearestNeighborsCount: queryVector ? 50 : undefined,
66-
fields: queryVector ? ['embedding'] : undefined,
67-
},
68-
],
70+
vectorSearchOptions: {
71+
queries: [
72+
{
73+
kind: 'vector',
74+
vector: queryVector!,
75+
kNearestNeighborsCount: queryVector ? 50 : undefined,
76+
fields: queryVector ? ['embedding'] : undefined,
77+
},
78+
],
79+
},
6980
}));
7081

7182
const results: string[] = [];
@@ -87,32 +98,4 @@ export class ApproachBase {
8798
const content = results.join('\n');
8899
return { query: queryText ?? '', results, content };
89100
}
90-
91-
protected async lookupDocument(query: string): Promise<any> {
92-
const searchResults = await this.search.search(query, {
93-
top: 1,
94-
includeTotalCount: true,
95-
queryType: 'semantic',
96-
queryLanguage: 'en-us',
97-
speller: 'lexicon',
98-
semanticConfiguration: 'default',
99-
answers: 'extractive|count-1',
100-
captions: 'extractive|highlight-false',
101-
});
102-
103-
const answers = await searchResults.answers;
104-
if (answers && answers.length > 0) {
105-
return answers[0].text;
106-
}
107-
if (searchResults.count ?? 0 > 0) {
108-
const results: string[] = [];
109-
for await (const result of searchResults.results) {
110-
// TODO: ensure typings
111-
const document = result.document as any;
112-
results.push(document[this.contentField]);
113-
}
114-
return results.join('\n');
115-
}
116-
return undefined;
117-
}
118101
}

0 commit comments

Comments
 (0)