Skip to content

Commit 89d67ef

Browse files
fix: add keyword index for type field to fix Qdrant codebase_search error (#8964)
Co-authored-by: Roo Code <[email protected]>
1 parent eb68c65 commit 89d67ef

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/services/code-index/vector-store/__tests__/qdrant-client.spec.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,18 @@ describe("QdrantVectorStore", () => {
542542
})
543543
expect(mockQdrantClientInstance.deleteCollection).not.toHaveBeenCalled()
544544

545-
// Verify payload index creation
545+
// Verify payload index creation - 'type' field first, then pathSegments
546+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
547+
field_name: "type",
548+
field_schema: "keyword",
549+
})
546550
for (let i = 0; i <= 4; i++) {
547551
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
548552
field_name: `pathSegments.${i}`,
549553
field_schema: "keyword",
550554
})
551555
}
552-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
556+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
553557
})
554558
it("should not create a new collection if one exists with matching vectorSize and return false", async () => {
555559
// Mock getCollection to return existing collection info with matching vector size
@@ -572,14 +576,18 @@ describe("QdrantVectorStore", () => {
572576
expect(mockQdrantClientInstance.createCollection).not.toHaveBeenCalled()
573577
expect(mockQdrantClientInstance.deleteCollection).not.toHaveBeenCalled()
574578

575-
// Verify payload index creation still happens
579+
// Verify payload index creation still happens - 'type' field first, then pathSegments
580+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
581+
field_name: "type",
582+
field_schema: "keyword",
583+
})
576584
for (let i = 0; i <= 4; i++) {
577585
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
578586
field_name: `pathSegments.${i}`,
579587
field_schema: "keyword",
580588
})
581589
}
582-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
590+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
583591
})
584592
it("should recreate collection if it exists but vectorSize mismatches and return true", async () => {
585593
const differentVectorSize = 768
@@ -625,14 +633,18 @@ describe("QdrantVectorStore", () => {
625633
},
626634
})
627635

628-
// Verify payload index creation
636+
// Verify payload index creation - 'type' field first, then pathSegments
637+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
638+
field_name: "type",
639+
field_schema: "keyword",
640+
})
629641
for (let i = 0; i <= 4; i++) {
630642
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledWith(expectedCollectionName, {
631643
field_name: `pathSegments.${i}`,
632644
field_schema: "keyword",
633645
})
634646
}
635-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
647+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
636648
;(console.warn as any).mockRestore() // Restore console.warn
637649
})
638650
it("should log warning for non-404 errors but still create collection", async () => {
@@ -646,7 +658,7 @@ describe("QdrantVectorStore", () => {
646658
expect(mockQdrantClientInstance.getCollection).toHaveBeenCalledTimes(1)
647659
expect(mockQdrantClientInstance.createCollection).toHaveBeenCalledTimes(1)
648660
expect(mockQdrantClientInstance.deleteCollection).not.toHaveBeenCalled()
649-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
661+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
650662
expect(console.warn).toHaveBeenCalledWith(
651663
expect.stringContaining(`Warning during getCollectionInfo for "${expectedCollectionName}"`),
652664
genericError.message,
@@ -693,11 +705,16 @@ describe("QdrantVectorStore", () => {
693705
expect(result).toBe(true)
694706
expect(mockQdrantClientInstance.createCollection).toHaveBeenCalledTimes(1)
695707

696-
// Verify all payload index creations were attempted
697-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
708+
// Verify all payload index creations were attempted (6: type + 5 pathSegments)
709+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
698710

699-
// Verify warnings were logged for each failed index
700-
expect(console.warn).toHaveBeenCalledTimes(5)
711+
// Verify warnings were logged for each failed index (now 6)
712+
expect(console.warn).toHaveBeenCalledTimes(6)
713+
// Verify warning for 'type' index
714+
expect(console.warn).toHaveBeenCalledWith(
715+
expect.stringContaining(`Could not create payload index for type`),
716+
indexError.message,
717+
)
701718
for (let i = 0; i <= 4; i++) {
702719
expect(console.warn).toHaveBeenCalledWith(
703720
expect.stringContaining(`Could not create payload index for pathSegments.${i}`),
@@ -826,7 +843,7 @@ describe("QdrantVectorStore", () => {
826843
expect(mockQdrantClientInstance.getCollection).toHaveBeenCalledTimes(2)
827844
expect(mockQdrantClientInstance.deleteCollection).toHaveBeenCalledTimes(1)
828845
expect(mockQdrantClientInstance.createCollection).toHaveBeenCalledTimes(1)
829-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
846+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
830847
;(console.warn as any).mockRestore()
831848
})
832849

@@ -923,7 +940,7 @@ describe("QdrantVectorStore", () => {
923940
on_disk: true,
924941
},
925942
})
926-
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(5)
943+
expect(mockQdrantClientInstance.createPayloadIndex).toHaveBeenCalledTimes(6)
927944
;(console.warn as any).mockRestore()
928945
})
929946

src/services/code-index/vector-store/qdrant-client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ export class QdrantVectorStore implements IVectorStore {
296296
* Creates payload indexes for the collection, handling errors gracefully.
297297
*/
298298
private async _createPayloadIndexes(): Promise<void> {
299+
// Create index for the 'type' field to enable metadata filtering
300+
try {
301+
await this.client.createPayloadIndex(this.collectionName, {
302+
field_name: "type",
303+
field_schema: "keyword",
304+
})
305+
} catch (indexError: any) {
306+
const errorMessage = (indexError?.message || "").toLowerCase()
307+
if (!errorMessage.includes("already exists")) {
308+
console.warn(
309+
`[QdrantVectorStore] Could not create payload index for type on ${this.collectionName}. Details:`,
310+
indexError?.message || indexError,
311+
)
312+
}
313+
}
314+
315+
// Create indexes for pathSegments fields
299316
for (let i = 0; i <= 4; i++) {
300317
try {
301318
await this.client.createPayloadIndex(this.collectionName, {

0 commit comments

Comments
 (0)